Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Fragment Error
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.appex.android.inquisitor.EndActivity">
</RelativeLayout>
package com.appex.android.inquisitor;
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.app.ActionBarActivity;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
public class EndActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_end);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment())
.commit();
}
}
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_end, container, false);
TextView eview=(TextView)rootView.findViewById(R.id.endview);
eview.setGravity(Gravity.CENTER);
Typeface typeface=Typeface.createFromAsset(getActivity().getAssets(),"fonts/brotherDeluxe.ttf");
eview.setTypeface(typeface);
return rootView;
}
}
}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
android:background="@drawable/endimg"
tools:context="com.appex.android.inquisitor.EndActivity$PlaceholderFragment">
<TextView
android:id="@+id/endview"
android:text="@string/end"
android:textColor="@color/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14pt"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
Process: com.appex.android.inquisitor, PID: 22286
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.appex.android.inquisitor/com.appex.android.inquisitor.EndActivity}: java.lang.IllegalArgumentException: No view found for id 0x7f08003f (com.appex.android.inquisitor:id/container) for fragment PlaceholderFragment{447bcac0 #0 id=0x7f08003f}
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2237)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2286)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1246)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:212)
at android.app.ActivityThread.main(ActivityThread.java:5135)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalArgumentException: No view found for id 0x7f08003f (com.appex.android.inquisitor:id/container) for fragment PlaceholderFragment{447bcac0 #0 id=0x7f08003f}
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:939)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1126)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:739)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1489)
at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:548)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1171)
at android.app.Activity.performStart(Activity.java:5241)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2210)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2286)
            at android.app.ActivityThread.access$800(ActivityThread.java:144)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1246)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:212)
            at android.app.ActivityThread.main(ActivityThread.java:5135)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
            at dalvik.system.NativeStart.main(Native Method)
//this activity calls EndActivity with an intent
package com.appex.android.inquisitor;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.app.ActionBarActivity;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class QuestionActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_question);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment())
.commit();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
if(id== R.id.action_about){
startActivity(new Intent(this, AboutActivity.class));
}
return super.onOptionsItemSelected(item);
}
public static class PlaceholderFragment extends Fragment {
public String ques[]={
"FD,RT,LT,BK,Turtle.",
"Sixth Sense on Paper.",
"White House, Jenny Craig Inc.",
"11, Oranje.",
"Perkins Engineering, Brown-Forman.",
"Whenever windows opened, it was there. But it will soon disappear.",
"Grand Theft Auto, Ranbir Kapoor.",
"Hoomerpalooza, Lollapalooza.",
"Was used in war, now a TV star."
};
public String ans[]={
"logo",
"pranav mistry",
"monica samille lewinsky",
"the flying dutchman",
"jack daniel's",
"internet explorer",
"rockstar",
"cypress hill",
"arrow"
};
public String hint[]={
"Programming",
"Cameras and Projectors",
"Scandal",
"Davy Jones",
"Old No.7",
"Thomas Reardon",
"It's a one word connection",
"Ghetto Therapy",
"Emanuel Chiroco"
};
int i=0;
int j=0;
public PlaceholderFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
final View rootView = inflater.inflate(R.layout.activity_question, container, false);
final EditText t = (EditText) rootView.findViewById(R.id.edittext1);
final TextView qView=(TextView)rootView.findViewById(R.id.textviewname);
final TextView hView=(TextView)rootView.findViewById(R.id.hintview);
Typeface typeface=Typeface.createFromAsset(getActivity().getAssets(),"fonts/1942.ttf");
qView.setTypeface(typeface);
hView.setTypeface(typeface);
qView.append(ques[0]);
t.setTypeface(typeface);
t.setGravity(Gravity.CENTER);
Button DoneButton=(Button)rootView.findViewById(R.id.done_button);
DoneButton.setTypeface(typeface);
DoneButton.setOnClickListener(new View.OnClickListener(){
String ans1;
public void onClick(View dview) {
for (i = 0; i < ques.length; i++) {
j=i+1;
ans1 = t.getText().toString();
if (ans1.equals(ans[i])) {
Toast.makeText(getActivity(),R.string.correcttoast,Toast.LENGTH_SHORT).show();
hView.setText("");
t.setText("");
if(j!=ques.length)
qView.setText(ques[j]);
else {
Intent intent = new Intent(getActivity(), EndActivity.class);
startActivity(intent);
}
break;
}
}
}
});
Button HintButton=(Button)rootView.findViewById(R.id.hintbutton);
HintButton.setTypeface(typeface);
HintButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
hView.setText(hint[j]);
}
});
return rootView;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment