Note that there are some explanatory texts on larger screens.

plurals
  1. POProblem using ListFragment on Android
    primarykey
    data
    text
    <p>I'm very new at programming in Android (I have programmed extensively PC applications and used Java) and I'm at a loss. I want to create a application that uses fragments. I want to create the Fragment Programaticaly (as the introduction says on Android Developer page) buy my application keeps crashing and I have no Idea as to why.</p> <p>Here is the code for my main activity:</p> <pre><code>public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); FragmentManager fmanager = getFragmentManager(); FragmentTransaction ftransaction = fmanager.beginTransaction(); FileBrowser fbrowser = new FileBrowser(); ftransaction.add(R.layout.main,fbrowser, "FileBrowser"); ftransaction.commit(); fbrowser.test(); } </code></pre> <p>And here is the code for FileBrowser:</p> <p>public class FileBrowser extends ListFragment {</p> <pre><code>public void test(){ System.err.println("Entre a test!!!"); String[] MyList = {"HOla","Mundo","De","Las","Listas"}; if (getActivity() == null){ System.err.println("I get a NULL Activity"); } else{ System.err.println("No NULL Activity Attempting to Create an Adapter"); ArrayAdapter&lt;String&gt; aa = new ArrayAdapter&lt;String&gt;(getActivity(), R.layout.file_row, MyList); } //setListAdapter(new ArrayAdapter&lt;String&gt;(this.getActivity(), R.layout.file_row, MyList)); } </code></pre> <p>}</p> <p>All I wan to do to start is to print the string list MyList in the fragment. However I the program crashes and I get this error:</p> <p>06-09 19:25:42.920: ERROR/AndroidRuntime(26064): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ccr/com.ccr.Main}: java.lang.IllegalArgumentException: No view found for id 0x7f030001 for fragment FileBrowser{4077d558 #0 id=0x7f030001 FileBrowser}</p> <p>Thanks for any help!</p> <p>PD: I get the I get a NULL Activity Message also.</p> <hr> <p>I've tried that and it did not work either.</p> <p>This is my new xml file</p> <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"&gt; &lt;FrameLayout android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/flFileBrowser"&gt; &lt;/FrameLayout&gt; &lt;/LinearLayout&gt; </code></pre> <p>And this is what my code reads:</p> <pre><code> public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); FragmentManager fmanager = getFragmentManager(); FragmentTransaction ftransaction = fmanager.beginTransaction(); FileBrowser fbrowser = new FileBrowser(); System.err.println("I'm about to add the fragment"); ftransaction.add(R.id.flFileBrowser,fbrowser, "FileBrowser"); System.err.println("fragment added"); ftransaction.commit(); System.err.println("Done"); } </code></pre> <p>This was my output:</p> <pre><code>06-10 12:23:21.520: WARN/System.err(30826): I'm about to add the fragment 06-10 12:23:21.520: WARN/System.err(30826): fragment added 06-10 12:23:21.520: WARN/System.err(30826): Done 06-10 12:23:21.520: WARN/dalvikvm(30826): threadid=1: thread exiting with uncaught exception (group=0x40131760) 06-10 12:23:21.520: ERROR/AndroidRuntime(30826): FATAL EXCEPTION: main 06-10 12:23:21.520: ERROR/AndroidRuntime(30826): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ccr/com.ccr.Main}: java.lang.IllegalArgumentException: No view found for id 0x7f050000 for fragment FileBrowser{4077d3f0 #0 id=0x7f050000 FileBrowser} 06-10 12:23:21.520: ERROR/AndroidRuntime(30826): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1748) 06-10 12:23:21.520: ERROR/AndroidRuntime(30826): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1764) 06-10 12:23:21.520: ERROR/AndroidRuntime(30826): at android.app.ActivityThread.access$1500(ActivityThread.java:122) 06-10 12:23:21.520: ERROR/AndroidRuntime(30826): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1002) 06-10 12:23:21.520: ERROR/AndroidRuntime(30826): at android.os.Handler.dispatchMessage(Handler.java:99) 06-10 12:23:21.520: ERROR/AndroidRuntime(30826): at android.os.Looper.loop(Looper.java:132) 06-10 12:23:21.520: ERROR/AndroidRuntime(30826): at android.app.ActivityThread.main(ActivityThread.java:4025) 06-10 12:23:21.520: ERROR/AndroidRuntime(30826): at java.lang.reflect.Method.invokeNative(Native Method) 06-10 12:23:21.520: ERROR/AndroidRuntime(30826): at java.lang.reflect.Method.invoke(Method.java:491) 06-10 12:23:21.520: ERROR/AndroidRuntime(30826): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841) 06-10 12:23:21.520: ERROR/AndroidRuntime(30826): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599) 06-10 12:23:21.520: ERROR/AndroidRuntime(30826): at dalvik.system.NativeStart.main(Native Method) 06-10 12:23:21.520: ERROR/AndroidRuntime(30826): Caused by: java.lang.IllegalArgumentException: No view found for id 0x7f050000 for fragment FileBrowser{4077d3f0 #0 id=0x7f050000 FileBrowser} </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload