Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help Needed With NullPointerException

 
Jared Snyder
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wanted to utilize the search view widget in the action bar with the Google Places API and stumbled upon a link to a tutorial that was shared in various posts on Stack Overflow, so I decided to check it out. I have it all implemented into my existing code, but I am getting a NullPointerException and am hoping someone can help me out a bit, so I can debug the issue.

Logcat specifies that it is caused by lines 119 and 123, so I know that it has to do with Intents.

MainActivity.java:



My first thought was to go sniffing in my Manifest, but that all seems to be in order. Thanks, y'all!
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jared Snyder wrote:Logcat specifies that it is caused by lines 119 and 123 ...

Your example only has 24 lines, so which lines these represent is unclear.
 
Jared Snyder
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:
Jared Snyder wrote:Logcat specifies that it is caused by lines 119 and 123 ...

Your example only has 24 lines, so which lines these represent is unclear.


If you look closely, I've left comments in the code to mark each line.
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, there are two possible causes of that.

1. intent is null on line 123
2. intent.getAction() is null

So first, find out which. You can add log statements to do that. Then work out why you think it shouldn't be null - that's where I'd be looking.
 
Ron McLeod
Bartender
Pie
Posts: 1039
65
Android Eclipse IDE Java Linux MySQL Database Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jared Snyder wrote:

What are you doing in ... before calling handleIntent()?
 
Jared Snyder
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Matthew Brown wrote:OK, there are two possible causes of that.

1. intent is null on line 123
2. intent.getAction() is null

So first, find out which. You can add log statements to do that. Then work out why you think it shouldn't be null - that's where I'd be looking.


My understanding is that, that shouldn't happen. I thought it was exactly the reason for...

 
Jared Snyder
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ron McLeod wrote:
Jared Snyder wrote:

What are you doing in ... before calling handleIntent()?



Um. Nothing that should add to this issue...

 
Ron McLeod
Bartender
Pie
Posts: 1039
65
Android Eclipse IDE Java Linux MySQL Database Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure that intent.getStringExtra(SearchManager.QUERY) and intent.getStringExtra(SearchManager.EXTRA_DATA_KEY) are not null?

Can you post the stack trace from LogCat when the NPE occurs?
 
Jared Snyder
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
03-09 18:05:09.533: E/AndroidRuntime(6495): FATAL EXCEPTION: main
03-09 18:05:09.533: E/AndroidRuntime(6495): java.lang.RuntimeException: Unable to start activity ComponentInfo{com..../com.....MainActivity}: java.lang.NullPointerException
03-09 18:05:09.533: E/AndroidRuntime(6495): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1696)
03-09 18:05:09.533: E/AndroidRuntime(6495): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1716)
03-09 18:05:09.533: E/AndroidRuntime(6495): at android.app.ActivityThread.access$1500(ActivityThread.java:124)
03-09 18:05:09.533: E/AndroidRuntime(6495): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:968)
03-09 18:05:09.533: E/AndroidRuntime(6495): at android.os.Handler.dispatchMessage(Handler.java:99)
03-09 18:05:09.533: E/AndroidRuntime(6495): at android.os.Looper.loop(Looper.java:130)
03-09 18:05:09.533: E/AndroidRuntime(6495): at android.app.ActivityThread.main(ActivityThread.java:3806)
03-09 18:05:09.533: E/AndroidRuntime(6495): at java.lang.reflect.Method.invokeNative(Native Method)
03-09 18:05:09.533: E/AndroidRuntime(6495): at java.lang.reflect.Method.invoke(Method.java:507)
03-09 18:05:09.533: E/AndroidRuntime(6495): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
03-09 18:05:09.533: E/AndroidRuntime(6495): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
03-09 18:05:09.533: E/AndroidRuntime(6495): at dalvik.system.NativeStart.main(Native Method)
03-09 18:05:09.533: E/AndroidRuntime(6495): Caused by: java.lang.NullPointerException
03-09 18:05:09.533: E/AndroidRuntime(6495): at com.....MainActivity.handleIntent(MainActivity.java:123)
03-09 18:05:09.533: E/AndroidRuntime(6495): at com.....MainActivity.onCreate(MainActivity.java:119)
03-09 18:05:09.533: E/AndroidRuntime(6495): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-09 18:05:09.533: E/AndroidRuntime(6495): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1660)
03-09 18:05:09.533: E/AndroidRuntime(6495): ... 11 more
 
Jared Snyder
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So as it turned out, I did not assign an action to the Intent that launched the Activity (MainActivity) on which searches were conducted and returned. So after I inserted after the Intent was declared, but before it was started, the bug is no more. Now, on to the next bug!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic