added extends ListActivity and the emulator booted me error

3

does not show me the layout when compiling it. and I get the typical error when you do not add the activity in the manifest. I already made the tests, the error is generated when I add the ListActivity since I am using a listview.

FATAL EXCEPTION: main
      Process: com.vistony.newapp, PID: 32006
      java.lang.RuntimeException: Unable to start activity ComponentInfo{com.vistony.newapp/com.vistony.newapp.View.ConsDespachocActivity}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
        at android.app.ActivityThread.access$800(ActivityThread.java:135)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:136)
        at android.app.ActivityThread.main(ActivityThread.java:5017)
        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:779)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
        at dalvik.system.NativeStart.main(Native Method)

    Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
        at android.app.ListActivity.onContentChanged(ListActivity.java:243)
        at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:293)
        at android.app.Activity.setContentView(Activity.java:1929)
        at com.vistony.newapp.View.ConsDespachocActivity.onCreate(ConsDespachocActivity.java:43)
        at android.app.Activity.performCreate(Activity.java:5231)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245) 
        at android.app.ActivityThread.access$800(ActivityThread.java:135) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:136) 
        at android.app.ActivityThread.main(ActivityThread.java:5017) 
        at java.lang.reflect.Method.invokeNative(Native Method) 

    
asked by ICRUZ 17.06.2016 в 19:37
source

1 answer

1

The problem is described here:

  

Caused by: java.lang.RuntimeException: Your content must have a   ListView whose id attribute is 'android.R.id.list'

In fact I just saw that you extend your Activity of ListActivity , in this case you should not use setContentView()

If you want to use extends ListActivity , then get the ListView reference like this:

ListView listview = (ListView)findViewById(android.R.id.list);

and you should not use setContentView()

I found an example here of what you want extends ListActivity , check HelloListView.java.

public class HelloListView extends ListActivity {
    //define el data source
    private ArrayList<String> data;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // configura data source
        this.data = new ArrayList<String>();

        // Agrega algunos objetos.
        this.data.add("List Item 1");
        this.data.add("List Item 2");
        this.data.add("List Item 3");

        // use el layout archivo .xml 
        setContentView(R.layout.main);

        // Configura el adapter
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.list_item, R.id.text, this.data);

        // specify the list adaptor
        setListAdapter(adapter);
    }
}
    
answered by 17.06.2016 в 20:05