• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Adapter for ListView causes app to crash! help!!

Ristar

Lurker
i've been trying to get this to work... but it isnt working. please help!

there was no Exception to catch, the app just crash.

Code:
public class MainActivity extends Activity{
    ...

    private void loadFromFile_populateListView(final String data){
        try{

            ... //code for data reading and processing

            ListView list = (ListView) activity.findViewById(R.id.load_list);

            if(list != null){
                ArrayList <String> listItems = new ArrayList<String>();
                ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.id.load_list, listItems);
                list.setAdapter(adapter); // [B]this line causes the app to crash[/B]

                ... //code for adding items into the ArrayList

                adapter.notifyDataSetChanged();
            }
        }catch(Exception e){
            ...
        }
    }

    ...
}
 
XML: activity_load.xml
Code:
<RelativeLayout>
    ...

    <ListView
        android:id="@+id/load_list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/load_backToMainButton"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/load_rawDataEditText" >

    </ListView>
</RelativeLayout>

before "loadFromFile_populateListView();" (the method posted in the original post) was called, "setContentView(R.layout.activity_load);" was called.


the following is the log:

08-30 15:11:31.465: D/dalvikvm(330): GC_EXTERNAL_ALLOC freed 471K, 53% free 2831K/5959K, external 2122K/2137K, paused 55ms
08-30 15:11:54.926: D/dalvikvm(330): GC_EXTERNAL_ALLOC freed 106K, 53% free 2806K/5959K, external 2069K/2279K, paused 38ms
08-30 15:11:55.036: D/AndroidRuntime(330): Shutting down VM
08-30 15:11:55.036: W/dalvikvm(330): threadid=1: thread exiting with uncaught exception (group=0x40015560)
08-30 15:11:55.045: E/AndroidRuntime(330): FATAL EXCEPTION: main
08-30 15:11:55.045: E/AndroidRuntime(330): android.content.res.Resources$NotFoundException: Resource ID #0x7f080006 type #0x12 is not valid
08-30 15:11:55.045: E/AndroidRuntime(330): at android.content.res.Resources.loadXmlResourceParser(Resources.java:1874)
08-30 15:11:55.045: E/AndroidRuntime(330): at android.content.res.Resources.getLayout(Resources.java:731)
08-30 15:11:55.045: E/AndroidRuntime(330): at android.view.LayoutInflater.inflate(LayoutInflater.java:318)
08-30 15:11:55.045: E/AndroidRuntime(330): at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:332)
08-30 15:11:55.045: E/AndroidRuntime(330): at android.widget.ArrayAdapter.getView(ArrayAdapter.java:323)
08-30 15:11:55.045: E/AndroidRuntime(330): at android.widget.AbsListView.obtainView(AbsListView.java:1430)
08-30 15:11:55.045: E/AndroidRuntime(330): at android.widget.ListView.makeAndAddView(ListView.java:1745)
08-30 15:11:55.045: E/AndroidRuntime(330): at android.widget.ListView.fillDown(ListView.java:670)
08-30 15:11:55.045: E/AndroidRuntime(330): at android.widget.ListView.fillFromTop(ListView.java:727)
08-30 15:11:55.045: E/AndroidRuntime(330): at android.widget.ListView.layoutChildren(ListView.java:1584)
08-30 15:11:55.045: E/AndroidRuntime(330): at android.widget.AbsListView.onLayout(AbsListView.java:1260)
08-30 15:11:55.045: E/AndroidRuntime(330): at android.view.View.layout(View.java:7175)
08-30 15:11:55.045: E/AndroidRuntime(330): at android.widget.RelativeLayout.onLayout(RelativeLayout.java:912)
08-30 15:11:55.045: E/AndroidRuntime(330): at android.view.View.layout(View.java:7175)
08-30 15:11:55.045: E/AndroidRuntime(330): at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
08-30 15:11:55.045: E/AndroidRuntime(330): at android.view.View.layout(View.java:7175)
08-30 15:11:55.045: E/AndroidRuntime(330): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
08-30 15:11:55.045: E/AndroidRuntime(330): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130)
08-30 15:11:55.045: E/AndroidRuntime(330): at android.widget.LinearLayout.onLayout(LinearLayout.java:1047)
08-30 15:11:55.045: E/AndroidRuntime(330): at android.view.View.layout(View.java:7175)
08-30 15:11:55.045: E/AndroidRuntime(330): at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
08-30 15:11:55.045: E/AndroidRuntime(330): at android.view.View.layout(View.java:7175)
08-30 15:11:55.045: E/AndroidRuntime(330): at android.view.ViewRoot.performTraversals(ViewRoot.java:1140)
08-30 15:11:55.045: E/AndroidRuntime(330): at android.view.ViewRoot.handleMessage(ViewRoot.java:1859)
08-30 15:11:55.045: E/AndroidRuntime(330): at android.os.Handler.dispatchMessage(Handler.java:99)
08-30 15:11:55.045: E/AndroidRuntime(330): at android.os.Looper.loop(Looper.java:123)
08-30 15:11:55.045: E/AndroidRuntime(330): at android.app.ActivityThread.main(ActivityThread.java:3683)
08-30 15:11:55.045: E/AndroidRuntime(330): at java.lang.reflect.Method.invokeNative(Native Method)
08-30 15:11:55.045: E/AndroidRuntime(330): at java.lang.reflect.Method.invoke(Method.java:507)
08-30 15:11:55.045: E/AndroidRuntime(330): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-30 15:11:55.045: E/AndroidRuntime(330): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-30 15:11:55.045: E/AndroidRuntime(330): at dalvik.system.NativeStart.main(Native Method)
08-30 15:12:13.295: I/Process(330): Sending signal. PID: 330 SIG: 9


thanks.
 
It seems that the generated R class is out of sync. Delete the gen folder and let Eclipse re-build your project. Do you notice any difference?
 
Alternatively, go to Project > Clean in the menu bar and it will recompile your resources and subsequently regenerate all of the gen folder.

I suppose it is also possible that you have errors in your resources somewhere, although it would normally fail to compile in this case.
 
hello,

i've cleaned and rebuilt the project, and it still shows the same thing.

"08-31 01:59:34.644: E/AndroidRuntime(332): android.content.res.Resources$NotFoundException: Resource ID #0x7f080006 type #0x12 is not valid"

odd! the Resource ID #0x7F080006 is "ListView list"... which HAS to be not null if it reaches the "setAdapter()" method.
 
I'm half a month late. Hopefully you have already solved your problem.
This line is causing the error:-

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.id.load_list, listItems);

The second argument should be of a layout resource (R.layout) NOT R.id..
and it should be the layout for an item of the listview NOT the listview itself.

Change it to something like
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.load_list_item, listItems);
 
Back
Top Bottom