Zalek Bloom
Zalek Bloom

Reputation: 551

My app is failing in Custom Adapter for ListView

My app is failing in custom Adapter for ListView.

I am writing an app in Android where I want to show ListView in 3 columns. I created an adapter for a ListViewand my app is failing on the command:

listView.setAdapter(adapter);

where listView is a ListView and adapter is a subclass of Adapter I created. I know the problem is with my definition of the adapter and I want to look for a problem, but where to look for?

Here is a log:

FATAL EXCEPTION: main  java.lang.NullPointerException   
at com.hayored.memory_helper.SearchActivity.search(SearchActivity.java:156) 
at com.hayored.memory_helper.SearchActivity.onClick(SearchActivity.java:120)
at android.view.View.performClick(View.java:4204)
at android.view.View$PerformClick.run(View.java:17355)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5041)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)

Upvotes: 0

Views: 46

Answers (1)

Zalek Bloom
Zalek Bloom

Reputation: 551

I just found the problem - in my Java program in the command listView.setAdapter(adapter); listView was not defined as ListView type on my xml file. My app has few screens and on each screen few buttons and text views, so my conclusion is: each item on the screen will have the name:xxx_yy_abcd where xxx is the name of the screen, yy - type of the item (tv - TextView, bt - button etc) and abcd the name of the item. I hope this way will prevent me from similar mistakes.

Upvotes: 1

Related Questions