ivanrm
Apple Fan
Profile
Posts: 14
Reg: May 11, 2012
Chandler, AZ
2,790
05/24/12 04:08 PM (13 years ago)

Null Pointer Exception

I'm having the following error when I try to launch my Android application in the emulator. Any help would be greatly appreciated. This is from LogCat: 05-24 16:02:12.329: D/AndroidRuntime(356): Shutting down VM 05-24 16:02:12.339: W/dalvikvm(356): threadid=1: thread exiting with uncaught exception (group=0x4001d800) 05-24 16:02:12.349: E/AndroidRuntime(356): FATAL EXCEPTION: main 05-24 16:02:12.349: E/AndroidRuntime(356): java.lang.NullPointerException 05-24 16:02:12.349: E/AndroidRuntime(356): at com.qwaltec.BT_activity_root.transitionToAppHomeScreen(BT_activity_root.java:222) 05-24 16:02:12.349: E/AndroidRuntime(356): at com.qwaltec.BT_activity_root$1.run(BT_activity_root.java:352) 05-24 16:02:12.349: E/AndroidRuntime(356): at android.os.Handler.handleCallback(Handler.java:587) 05-24 16:02:12.349: E/AndroidRuntime(356): at android.os.Handler.dispatchMessage(Handler.java:92) 05-24 16:02:12.349: E/AndroidRuntime(356): at android.os.Looper.loop(Looper.java:123) 05-24 16:02:12.349: E/AndroidRuntime(356): at android.app.ActivityThread.main(ActivityThread.java:4627) 05-24 16:02:12.349: E/AndroidRuntime(356): at java.lang.reflect.Method.invokeNative(Native Method) 05-24 16:02:12.349: E/AndroidRuntime(356): at java.lang.reflect.Method.invoke(Method.java:521) 05-24 16:02:12.349: E/AndroidRuntime(356): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 05-24 16:02:12.349: E/AndroidRuntime(356): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 05-24 16:02:12.349: E/AndroidRuntime(356): at dalvik.system.NativeStart.main(Native Method)
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
05/24/12 09:50 PM (13 years ago)
Hi. java.lang.NullPointerException's are exceptionally difficult (no pun intended) to track down. It's especially tough to diagnose these types of issues without much other info or context around the crash. In other words, lots of things could be causing this. It does look like the crash is happening when the app tries to transition to the app's home screen. This means the Activity (the screen) that's being initialized for the home screen is probably the culprit. Is this screen initializing, etc. You could do some testing and debugging be experimenting with setting different screens as the "home screen" and see if it still crashes. This may help you determine which screen type in your project is causing the trouble. Ultimately it will be a matter of isolating where the nullPointerException is occurring before you'll be able to adjust / fix anything.
 
GoNorthWest
buzztouch Evangelist
Profile
Posts: 8197
Reg: Jun 24, 2011
Oro Valley, AZ
1,000,000
like
05/24/12 09:52 PM (13 years ago)
Learning here.... Does the following line suggest that the problem begins to surface at line 222 of the indicated file? 05-24 16:02:12.349: E/AndroidRuntime(356): at com.qwaltec.BT_activity_root.transitionToAppHomeScreen(BT_activity_root.java:222) Mark
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
05/24/12 10:16 PM (13 years ago)
It suggests that the issue begins in the METHOD named transitionToAppHomeScreen that exists in the CLASS named BT_activity_root. So, finding this method, in this class file (the BT_activity_root.java file) and adding some console output statements (use the BT_Debugger class like all the other console outputs in the project) to find / fix it. I'll be that method is "asking" to initialize an Android Activity and the Activity is causing the crash, not the method itself. So, the console shows this as the beginning of the errors. Baby steps debugging needed.
 
ivanrm
Apple Fan
Profile
Posts: 14
Reg: May 11, 2012
Chandler, AZ
2,790
like
05/24/12 10:38 PM (13 years ago)
Thank you all for your help. The strange thing here is that I have no custom code. I have merely used 3 or 4 of the offered Buzztouch plugins and that's it? I wasn't expecting to have to debug using the plugins if I used them "out of the box". Is that normal? Thanks again for all of your help!
 
GoNorthWest
buzztouch Evangelist
Profile
Posts: 8197
Reg: Jun 24, 2011
Oro Valley, AZ
1,000,000
like
05/24/12 10:38 PM (13 years ago)
OK, good stuff. If I ever get around to learning to debug Java, that'll be helpful! Mark
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
05/24/12 10:42 PM (13 years ago)
@ivanrm: You are correct, you should not have to debug. However, things dont' always go as planned. The fact is, tens of thousands of these work wonderfully without any issues at all. But, some do crash and it's an ongoing battle to find and fix each and every occurances of such things. Android offers so many different computer / work station / emulator / environment options that it's very very difficult to have perfect source code in 100% of configurations. Again, a very high success rate with the default plugins but not 100%. These ideas are why we jump in to help, learn along with you, and hope to get our heads, and your head, around the process. Believe it or not, when bugs arise, we all win! LOL Stick with this, it will all become much clearer as you spend more time understanding how your project is setup.
 
GoNorthWest
buzztouch Evangelist
Profile
Posts: 8197
Reg: Jun 24, 2011
Oro Valley, AZ
1,000,000
like
05/24/12 10:44 PM (13 years ago)
@Ivan, What screen type were you on when you experienced the crash? Mark
 
ivanrm
Apple Fan
Profile
Posts: 14
Reg: May 11, 2012
Chandler, AZ
2,790
like
05/24/12 10:50 PM (13 years ago)
The application crashes as soon as it starts. My "home" screen is a Menu Button screen.
 
ivanrm
Apple Fan
Profile
Posts: 14
Reg: May 11, 2012
Chandler, AZ
2,790
like
05/24/12 10:55 PM (13 years ago)
The application crashes as soon as it starts. My "home" screen is a Menu Button screen.
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
05/24/12 10:59 PM (13 years ago)
OK, good info. a) Create new screen, like a simple button screen. b) Set it as the home screen in the Layout section of the control panel. c) Visit the apps config data screen and COPY this data to your mouse. All of it. d) Paste the in your already downloaded source code. Overwrite the existing JSON data in BT_config.txt. e) Compile / run. Does the app crash just like before or not? The idea is to modify the app a bit to try to isolate the issue. The Menu's are reliable so something weird is happening. Get a button menu as the home screen, see if it works. Report.
 
ivanrm
Apple Fan
Profile
Posts: 14
Reg: May 11, 2012
Chandler, AZ
2,790
like
05/25/12 10:04 AM (13 years ago)
I tried the above and the app is still crashing when launching (I added a Simple Menu and made it the home screen in the layout). It looks like it trying to call the home screen but can't seem to find it? 05-25 09:59:29.246: W/ZZ(381): BT_activity_root:transitionToAppHomeScreen 05-25 09:59:29.246: W/ZZ(381): BT_activity_root:transitionToAppHomeScreen splash screen with itemId: 55BB7D63034504686CFCF9B 05-25 09:59:29.246: W/ZZ(381): BT_application:getScreenDataByItemId 55BB7D63034504686CFCF9B 05-25 09:59:29.256: W/ZZ(381): BT_application:getScreenDataByItemId could not find screen with itemId: 55BB7D63034504686CFCF9B 05-25 09:59:29.256: D/AndroidRuntime(381): Shutting down VM 05-25 09:59:29.256: W/dalvikvm(381): threadid=1: thread exiting with uncaught exception (group=0x4001d800) 05-25 09:59:29.276: E/AndroidRuntime(381): FATAL EXCEPTION: main 05-25 09:59:29.276: E/AndroidRuntime(381): java.lang.NullPointerException 05-25 09:59:29.276: E/AndroidRuntime(381): at com.qwaltec.BT_activity_root.transitionToAppHomeScreen(BT_activity_root.java:222) 05-25 09:59:29.276: E/AndroidRuntime(381): at com.qwaltec.BT_activity_root$1.run(BT_activity_root.java:352) 05-25 09:59:29.276: E/AndroidRuntime(381): at android.os.Handler.handleCallback(Handler.java:587) 05-25 09:59:29.276: E/AndroidRuntime(381): at android.os.Handler.dispatchMessage(Handler.java:92) 05-25 09:59:29.276: E/AndroidRuntime(381): at android.os.Looper.loop(Looper.java:123) 05-25 09:59:29.276: E/AndroidRuntime(381): at android.app.ActivityThread.main(ActivityThread.java:4627) 05-25 09:59:29.276: E/AndroidRuntime(381): at java.lang.reflect.Method.invokeNative(Native Method) 05-25 09:59:29.276: E/AndroidRuntime(381): at java.lang.reflect.Method.invoke(Method.java:521) 05-25 09:59:29.276: E/AndroidRuntime(381): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 05-25 09:59:29.276: E/AndroidRuntime(381): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 05-25 09:59:29.276: E/AndroidRuntime(381): at dalvik.system.NativeStart.main(Native Method) 05-25 10:01:06.136: I/Process(381): Sending signal. PID: 381 SIG: 9
 
ivanrm
Apple Fan
Profile
Posts: 14
Reg: May 11, 2012
Chandler, AZ
2,790
like
05/29/12 11:27 AM (13 years ago)
I decide to start fresh with and created a new app. I'm no longer having the problem. It seems I got myself into some sort of bad unrecoverable state? Thank you all for your help!
 
ElleEyeEssay
Code is Art
Profile
Posts: 36
Reg: Jul 08, 2012
Santa Barbara, ...
4,510
like
07/11/12 01:33 AM (13 years ago)
I seem to be having the same issue or a similar one but I had a splash screen and then I deleted it and removed it from the Theme but when I view my BT_config.txt file, an itemID still exists for a splash screen so when I debug the program, it checks to see if the itemID length is greater than 1. If it is, it tries to load a splash screen which is no longer there.
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
07/11/12 01:40 AM (13 years ago)
OK...I think I understand what you mean. If you create a splash screen in your control panel, in the list of screens, it will appear in the config.txt file. BUT, this doesn't necessarily mean it's going to be "used" or "applied." Have a look at the BT_theme in the config.txt file. If it has as splashScreenItemId that isn't empty, it will look for that screen to use. If there is no splashScreenItemId in the theme, it won't do anything. I hope this makes sense. Another way to say it. Just because you see a splash screen in the config.txt file, in the long list of screens with all the others, it doesn't necessarily mean the theme will use it. To use it, the theme must have a splash screen itemId set. This gets set when you visit the theme in the control panel and set a splash screen. Another way to say it. You could have lots of splash screens in your list of screens in your control panel and have NO splash screen set in the theme.
 
ElleEyeEssay
Code is Art
Profile
Posts: 36
Reg: Jul 08, 2012
Santa Barbara, ...
4,510
like
07/11/12 01:52 AM (13 years ago)
@David - I understand and I think I explained my issue incorrectly so I'll post what I'm seeing below. In BT_activity_root.java: if(splashScreenItemId.length() > 1){ <-- This splashScreenItemId is greater than one BT_debugger.showIt(activityName + ":transitionToAppHomeScreen splash screen with itemId: " + splashScreenItemId); //get the splash screen object and remember it... BT_item tmpScreenData = trivia_appDelegate.rootApp.getScreenDataByItemId(splashScreenItemId); <-- This pointer is NULL //remember the current screen trivia_appDelegate.rootApp.setCurrentScreenData(tmpScreenData); String theActivityClass = "com.trivia." + tmpScreenData.getItemType(); <-- This line is causing the issue
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
07/11/12 02:02 AM (13 years ago)
OK. So, if the splashScreenItemId > 1 then the theme in the config.txt file must use a splashScreenItemId. So far so good.... This means that this screen "object" (JSON object) must exist lower in the config.txt file, in the long list of screens. Try this: Open the config.txt file in an editor, or in Eclipse if that's where you are. Do a "search" for the itemId. It should appear one in the BT_theme JSON and then down lower in the data for the screen. If it does not, then this screen does not exist in your control panel anymore. In fact, you mentioned this I think? If you make a splash screen in your control panel, then set it as the Splash Screen in the theme, then delete it from the list of screens. It will NOT delete it from the theme. This happens occasionally but not very often.
 
ElleEyeEssay
Code is Art
Profile
Posts: 36
Reg: Jul 08, 2012
Santa Barbara, ...
4,510
like
07/11/12 02:17 AM (13 years ago)
I looked in the BT_config.txt file and I can't find the splashScreenItemID that exists when I'm debugging the code. I stepped into some of the code and it shows the name I had for the old splash screen as well. I have removed my project from Eclipse, downloaded the package again, reloaded the project and it still seems to pull data from a config file that doesn't match what's in my project or in the Configuration Data link in the Control Panel. Do you know what config file it's pulling the old information from?
 
ElleEyeEssay
Code is Art
Profile
Posts: 36
Reg: Jul 08, 2012
Santa Barbara, ...
4,510
like
07/11/12 02:32 AM (13 years ago)
@David, I was just looking through the LogCat in Eclipse and it says it's ignoring the BT_config.txt file because it's reading the cachedAppConfig.txt from the applications download cache. 07-11 02:24:53.930: W/ZZ(329): BT_activity_root:loadAppData reading cachedAppConfig.txt from the applications download cache... 07-11 02:24:53.930: W/ZZ(329): BT_activity_root:loadAppData ignoring BT_config.txt file in Eclipse project... Could this cachedAppConfig.txt file have the old data in it?
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
07/11/12 02:39 AM (13 years ago)
Yup!!!! Tough to explain in this post (way too late, about crashed, funny)...but... When you first download your source, and open it in Eclipse, it looks at the config.txt file. This file probably has a dataURL in JSON for the entire app. It also has a reportToCloudURL. Both of these are setup in your control panel. So, if these values exist in the JSON, the simulator / device will download the config data from your control panel. Not everyone configures their apps this way. So..you make a change in your control panel, app gets the new data. HOWEVER, when this occurs depends on a few things. But, I'll be anything that the config.txt data in your control panel (use the Configuration Data tab to see it) DOES NOT MATCH the config.txt file in your downloaded project. Again, tough to explain here. But, once it downloads data from your control panel, it ignores the config.txt file in Eclipse / Xcode. The best way to FORCE IT to sue the config.txt file in the project (and not in the control panel), is to remove the dataURL and the reportToCloudURL. Do this in the actual project. If it finds these it will grab the latest version from your control panel. There's a document somewhere with more details about this. How To's v1.5 documentation probably? You'll need to get your head around what's happening or you'll end up pulling your hair out. LOL.
 
ElleEyeEssay
Code is Art
Profile
Posts: 36
Reg: Jul 08, 2012
Santa Barbara, ...
4,510
like
07/11/12 03:01 AM (13 years ago)
Thanks David. I read the documentation and I understand what it's doing now. I just added a line of code to delete the cached config file so it would read the latest one and then put the code back like it was. I was so close to pulling my hair out. lol Now I can finally go to sleep so I can get up for work in 4 hours. lol Thanks for hanging in there with me. :)
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.