I have several objects defined in XML that are returning null when I try to get a handle on them. I saw several post saying to clean the project but that did not help. When I explore the ListView object all the children are null?? So I am at a bit of a loss as to what I am doing wrong. Here is the code that I think is relevant but if you need to see something else let me know and I'll post it.
TIA
JB
<Button
android:id="#+id/btn_NextLift"
android:layout_width="100dp"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginRight="30dp"
android:layout_marginBottom="40dp"
android:text="#string/str_BtnNxtTxt"
android:onClick="btn_NextLiftClick"
android:longClickable="true" />
In the activity:
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.liftinterface);
...//More code....
...//Still in the OnCreate....
lstvw_LiftData = (ListView)findViewById(R.id.lstvw_LiftData);
...//Image below of this object.....
//Get a handle on our button
Button btn_Nxt = (Button)this.findViewById(R.id.btn_NextLift);
btn_Nxt.setOnLongClickListener(new OnLongClickListener()
{
public boolean onLongClick(View v)
{
SaveAdvance();
return true;
}
});
Here is my logcat errors only:
11-13 22:04:57.798: E/AndroidRuntime(787): FATAL EXCEPTION: main
11-13 22:04:57.798: E/AndroidRuntime(787): java.lang.RuntimeException: Unable to start activity ComponentInfo{org.gpgvm.ironmike/org.gpgvm.ironmike.IcyArmActivity}: java.lang.NullPointerException
11-13 22:04:57.798: E/AndroidRuntime(787): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
11-13 22:04:57.798: E/AndroidRuntime(787): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
11-13 22:04:57.798: E/AndroidRuntime(787): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
11-13 22:04:57.798: E/AndroidRuntime(787): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
11-13 22:04:57.798: E/AndroidRuntime(787): at android.os.Handler.dispatchMessage(Handler.java:99)
11-13 22:04:57.798: E/AndroidRuntime(787): at android.os.Looper.loop(Looper.java:123)
11-13 22:04:57.798: E/AndroidRuntime(787): at android.app.ActivityThread.main(ActivityThread.java:3683)
11-13 22:04:57.798: E/AndroidRuntime(787): at java.lang.reflect.Method.invokeNative(Native Method)
11-13 22:04:57.798: E/AndroidRuntime(787): at java.lang.reflect.Method.invoke(Method.java:507)
11-13 22:04:57.798: E/AndroidRuntime(787): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
11-13 22:04:57.798: E/AndroidRuntime(787): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
11-13 22:04:57.798: E/AndroidRuntime(787): at dalvik.system.NativeStart.main(Native Method)
11-13 22:04:57.798: E/AndroidRuntime(787): Caused by: java.lang.NullPointerException
11-13 22:04:57.798: E/AndroidRuntime(787): at org.gpgvm.ironmike.IcyArmActivity.onCreate(IcyArmActivity.java:83)
11-13 22:04:57.798: E/AndroidRuntime(787): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
11-13 22:04:57.798: E/AndroidRuntime(787): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
11-13 22:04:57.798: E/AndroidRuntime(787): ... 11 more
When I explore the ListView object all the children are null??
Views are not draw until after onResume() has completed. So the ListView will not have any children in onCreate().
Where is this Button? If it is in the ListView, you need to write a custom adapter to override it's listeners.
Addition
It is in the ListView layout.
You need to extend you current adapter and override getView() to give each row unique listeners like this. Please watch Android's Romain Guy discussion this exact topic in fabulous detail at multiple Google Talk events.
Related
I don't know why the app crashes whenever it's supposed to go to the next Activity. I made a practice app that works as it should when using the same format. I uploaded the files to gist.github.
The error is
1216-1216/com.example.chiozokamalu.newfreshstart E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.ArrayIndexOutOfBoundsException
at com.example.chiozokamalu.newfreshstart.MainActivity.onClick(MainActivity.java:164)
at android.view.View.performClick(View.java:2485)
at android.view.View$PerformClick.run(View.java:9080)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
On line 164 of MainActivity.java:
questionView.setText(questions[questionIndex]); // set the text to the next question
EDIT: After Varun helped me, I get a new error which is
1307-1307/com.example.chiozokamalu.newfreshstart E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.chiozokamalu.newfreshstart/com.example.chiozokamalu.newfreshstart.Results1}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
at android.app.ActivityThread.access$1500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.example.chiozokamalu.newfreshstart.Results1.onCreate(Results1.java:58)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
at android.app.ActivityThread.access$1500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
The questions array at line no. 164 is going out of bound that means questionIndex is greater than the total length of the questions array. So you should add a check on the length before extracting value from the array.
You have added the check but after that you incremented the value so either you modify the if condition to if (questionIndex < questions.length -1)
or modify the questionIndex variable before the if condition
You are getting problem because you haven't initiated resultView9 that is why it is null and giving nullpointer, just initiatlise it as you done with other and everything is fine. You have initialised the resultView8 twice just add resultview9 over there
My App crash rarely
i want to get off this bug for ever.
this is the log that users Report
i tried so long on this but nothing helps
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xxx.xxx/com.xxx.xxx.Master_}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2072)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2097)
at android.app.ActivityThread.access$600(ActivityThread.java:136)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1207)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4787)
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:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.xxx.xxx.HomeFragment.onActivityCreated(HomeFragment.java:140)
at android.support.v4.app.Fragment.performActivityCreated(Fragment.java:1508)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:958)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1115)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1097)
at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:1895)
at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:566)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1163)
at android.app.Activity.performStart(Activity.java:5018)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2045)
... 11 more
I've made my Android app tablet optimized and I followed the tutorial here:
Everything is great, but I am trying to select an item (say, the 1st item) with a button in the ActionBar.
I tried this answer to use performItemClick but on I've got error reports of java.lang.IllegalStateException
in android.support.v4.app.ListFragment.ensureList, java.lang.IllegalStateException: Content view not yet created, and java.lang.NullPointerException
in android.content.ComponentName.<init>
I've tried checking if the ListView is null and still get the error reports on the Play Store. How do I properly select an item in my list programmatically?
Update to add logcat and the code is virtually identical to the tutorials in the links:
Logcat A:
java.lang.IllegalStateException: Content view not yet created
at android.support.v4.app.ListFragment.ensureList(ListFragment.java:328)
at android.support.v4.app.ListFragment.getListView(ListFragment.java:222)
at com.ccwilcox.meteorshower.MeteorList.showMeteorDetails(MeteorList.java:69)
at com.ccwilcox.meteorshower.MeteorList.onListItemClick(MeteorList.java:62)
at android.support.v4.app.ListFragment$2.onItemClick(ListFragment.java:58)
at android.widget.AdapterView.performItemClick(AdapterView.java:298)
at android.widget.AbsListView.performItemClick(AbsListView.java:1280)
at com.ccwilcox.meteorshower.MainActivity.viewUpcomingEvent(MainActivity.java:648)
at com.ccwilcox.meteorshower.MainActivity.onOptionsItemSelected(MainActivity.java:534)
at android.app.Activity.onMenuItemSelected(Activity.java:2606)
at android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:361)
at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:1045)
at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:735)
at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:149)
at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:874)
at com.android.internal.view.menu.ActionMenuView.invokeItem(ActionMenuView.java:592)
at com.android.internal.view.menu.ActionMenuItemView.onClick(ActionMenuItemView.java:149)
at android.view.View.performClick(View.java:4222)
at android.view.View$PerformClick.run(View.java:17273)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4895)
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:994)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:761)
at dalvik.system.NativeStart.main(Native Method)
Logcat B:
java.lang.NullPointerException
at android.content.ComponentName.<init>(ComponentName.java:75)
at android.content.Intent.<init>(Intent.java:2874)
at com.ccwilcox.meteorshower.MeteorList.showMeteorDetails(MeteorList.java:86)
at com.ccwilcox.meteorshower.MeteorList.onListItemClick(MeteorList.java:62)
at android.support.v4.app.ListFragment$2.onItemClick(ListFragment.java:58)
at android.widget.AdapterView.performItemClick(AdapterView.java:284)
at android.widget.ListView.performItemClick(ListView.java:3701)
at com.ccwilcox.meteorshower.MainActivity.viewUpcomingEvent(MainActivity.java:648)
at com.ccwilcox.meteorshower.MainActivity.onOptionsItemSelected(MainActivity.java:534)
at android.app.Activity.onMenuItemSelected(Activity.java:2205)
at android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:361)
at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:779)
at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:143)
at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:861)
at com.android.internal.view.menu.IconMenuView.invokeItem(IconMenuView.java:532)
at com.android.internal.view.menu.IconMenuItemView.performClick(IconMenuItemView.java:122)
at android.view.View$PerformClick.run(View.java:9152)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3687)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)
Update 2
And here is the code that is causing the problem:
if (mListFragment.listView != null) {
mListFragment.listView.performItemClick(mListFragment.listView.getAdapter().getView(position, null, null), position, mListFragment.listView.getAdapter().getItemId(position));
}
I have been trying to add adMob on my application, but I have naver been able to make it work on my app. Finally I have downloaded a sample adMob app from adMob's web site. However, that doesn't work either. And I get that log below:
11-13 18:24:21.477: D/AndroidRuntime(2225): Shutting down VM
11-13 18:24:21.477: W/dalvikvm(2225): threadid=1: thread exiting with uncaught exception (group=0xb40cb180)
11-13 18:24:21.507: E/AndroidRuntime(2225): FATAL EXCEPTION: main
11-13 18:24:21.507: E/AndroidRuntime(2225): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.google.example.ads.xml/com.google.example.ads.xml.BannerSample}: android.view.InflateException: Binary XML file line #10: Error inflating class com.google.ads.AdView
11-13 18:24:21.507: E/AndroidRuntime(2225): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
11-13 18:24:21.507: E/AndroidRuntime(2225): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
11-13 18:24:21.507: E/AndroidRuntime(2225): at android.app.ActivityThread.access$600(ActivityThread.java:123)
11-13 18:24:21.507: E/AndroidRuntime(2225): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
11-13 18:24:21.507: E/AndroidRuntime(2225): at android.os.Handler.dispatchMessage(Handler.java:99)
11-13 18:24:21.507: E/AndroidRuntime(2225): at android.os.Looper.loop(Looper.java:137)
11-13 18:24:21.507: E/AndroidRuntime(2225): at android.app.ActivityThread.main(ActivityThread.java:4424)
11-13 18:24:21.507: E/AndroidRuntime(2225): at java.lang.reflect.Method.invokeNative(Native Method)
11-13 18:24:21.507: E/AndroidRuntime(2225): at java.lang.reflect.Method.invoke(Method.java:511)
11-13 18:24:21.507: E/AndroidRuntime(2225): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
11-13 18:24:21.507: E/AndroidRuntime(2225): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
11-13 18:24:21.507: E/AndroidRuntime(2225): at dalvik.system.NativeStart.main(Native Method)
11-13 18:24:21.507: E/AndroidRuntime(2225): Caused by: android.view.InflateException: Binary XML file line #10: Error inflating class com.google.ads.AdView
11-13 18:24:21.507: E/AndroidRuntime(2225): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:691)
11-13 18:24:21.507: E/AndroidRuntime(2225): at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
11-13 18:24:21.507: E/AndroidRuntime(2225): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
11-13 18:24:21.507: E/AndroidRuntime(2225): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
11-13 18:24:21.507: E/AndroidRuntime(2225): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
11-13 18:24:21.507: E/AndroidRuntime(2225): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251)
11-13 18:24:21.507: E/AndroidRuntime(2225): at android.app.Activity.setContentView(Activity.java:1835)
11-13 18:24:21.507: E/AndroidRuntime(2225): at com.google.example.ads.xml.BannerSample.onCreate(BannerSample.java:14)
11-13 18:24:21.507: E/AndroidRuntime(2225): at android.app.Activity.performCreate(Activity.java:4465)
11-13 18:24:21.507: E/AndroidRuntime(2225): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
11-13 18:24:21.507: E/AndroidRuntime(2225): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
11-13 18:24:21.507: E/AndroidRuntime(2225): ... 11 more
11-13 18:24:21.507: E/AndroidRuntime(2225): Caused by: java.lang.ClassNotFoundException: com.google.ads.AdView
11-13 18:24:21.507: E/AndroidRuntime(2225): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
11-13 18:24:21.507: E/AndroidRuntime(2225): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
11-13 18:24:21.507: E/AndroidRuntime(2225): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
11-13 18:24:21.507: E/AndroidRuntime(2225): at android.view.LayoutInflater.createView(LayoutInflater.java:552)
11-13 18:24:21.507: E/AndroidRuntime(2225): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
11-13 18:24:21.507: E/AndroidRuntime(2225): ... 21 more
11-13 18:24:21.798: I/dalvikvm(2225): threadid=3: reacting to signal 3
11-13 18:24:21.808: I/dalvikvm(2225): Wrote stack traces to '/data/anr/traces.txt'
11-13 18:24:22.148: I/dalvikvm(2225): threadid=3: reacting to signal 3
11-13 18:24:22.158: I/dalvikvm(2225): Wrote stack traces to '/data/anr/traces.txt'
I have gotten this error before, when I got it it was because I had accidentally removed the admobSDK.jar from my application. However, it seems more likely that the below solution will work better for you.
If you are using ADT r17 or higher, then you need to create a libs/ folder in your project, and then copy the adMob SDK into that folder.
Here is another similar post
Error inflating class com.google.ads.AdView
I have no Idea why I get this error :/
Exception class java.lang.NullPointerException
Source method Jax$7.onClick()
java.lang.NullPointerException
at com.reg.lolsoundboard.Jax$7.onClick(Jax.java:83)
at android.view.View.performClick(View.java:2485)
at android.view.View$PerformClick.run(View.java:9089)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3806)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
Obviously you are dereferencing a variable in line 83 of the file Jax.java where the variable is null.
java.lang.NullPointerException
at com.reg.lolsoundboard.Jax$7.onClick(Jax.java:83)
If show the relevant code, people may be able to help you.