hi all m having a strange problem.
i have a button and when i set onClick Listener of it.
it gives me null Pointer Exception and application forcefully closes.
my code is
more = (Button) findViewById(R.id.moreButton);
System.out.println("BEFORE more listener CALL");
more.setOnClickListener(this);
Its so strange for me please can any one help?
stackTrace is Below:
05-17 13:28:54.141: ERROR/AndroidRuntime(1509): FATAL EXCEPTION: main
05-17 13:28:54.141: ERROR/AndroidRuntime(1509): java.lang.RuntimeException: Unable to start activity ComponentInfo{org.sigmatec.finditnear/org.sigmatec.finditnear.customListView}: java.lang.NullPointerException
05-17 13:28:54.141: ERROR/AndroidRuntime(1509): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
05-17 13:28:54.141: ERROR/AndroidRuntime(1509): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
05-17 13:28:54.141: ERROR/AndroidRuntime(1509): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
05-17 13:28:54.141: ERROR/AndroidRuntime(1509): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
05-17 13:28:54.141: ERROR/AndroidRuntime(1509): at android.os.Handler.dispatchMessage(Handler.java:99)
05-17 13:28:54.141: ERROR/AndroidRuntime(1509): at android.os.Looper.loop(Looper.java:123)
05-17 13:28:54.141: ERROR/AndroidRuntime(1509): at android.app.ActivityThread.main(ActivityThread.java:4627)
05-17 13:28:54.141: ERROR/AndroidRuntime(1509): at java.lang.reflect.Method.invokeNative(Native Method)
05-17 13:28:54.141: ERROR/AndroidRuntime(1509): at java.lang.reflect.Method.invoke(Method.java:521)
05-17 13:28:54.141: ERROR/AndroidRuntime(1509): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-17 13:28:54.141: ERROR/AndroidRuntime(1509): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-17 13:28:54.141: ERROR/AndroidRuntime(1509): at dalvik.system.NativeStart.main(Native Method)
05-17 13:28:54.141: ERROR/AndroidRuntime(1509): Caused by: java.lang.NullPointerException
05-17 13:28:54.141: ERROR/AndroidRuntime(1509): at org.sigmatec.finditnear.customListView.onCreate(customListView.java:114)
05-17 13:28:54.141: ERROR/AndroidRuntime(1509): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-17 13:28:54.141: ERROR/AndroidRuntime(1509): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
05-17 13:28:54.141: ERROR/AndroidRuntime(1509): ... 11 more
UPDATED:
one more thing the Button that i am using has been taken from the answer from the link
How to add a footer in ListView?
i have used button instead of TextView Take a look at answer#2 at the end.
m using the Button from some other layout not from the one which has been set on setContentView. because i am using List and i want a button at the end of the list so i made a seperate .xml and used the following code to join it with the List Footer.
COde:
super.onCreate(savedInstanceState);
setContentView(R.layout.listview);
ListView l1 = (ListView) findViewById(R.id.ListView01);
View footerView =
((LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.layout_footer, null, false);
l1.addFooterView(footerView);
l1.setAdapter(adapter);