ListView yielding nullpointerexception on setOnItemClickListener

后端 未结 4 1364
南笙
南笙 2021-01-25 16:01

I\'m attempting to work with through some tutorial code and add in an OnItemClick Listener, but keep throwing an exception when it hits the listener and crashing my app. This is

4条回答
  •  死守一世寂寞
    2021-01-25 16:56

    I cannot see where you have initialized your layout...so:

    Activity class takes care of creating a window for you in which you can place your UI with setContentView(View).

    The onCreate(Bundle) method initializes your Activity. It is where you usually call setContentView(int) with your xml layout(main.xml or your xml which defines your UI). Place it after super.onCreate(..)


    With regards with this exception:

    java.lang.RuntimeException: Unable to start activity ComponentInfo{}:
    

    check your AndroidManifest.xml if your Activity is already in there:

    
    
    

    If your problem has not been resolved, make use of your Logcat and put Log.d in your methods to see where it's crashing.

提交回复
热议问题