null pointer exception on getStringExtra
up vote
-1
down vote
favorite
I have an intent service that sends an intent, like this:
Intent result = new Intent("TEST_RESULT");
result.putExtra("MODE", "testing");
sendBroadcast(result);
in another application, the intent gets captured by a broadcast receiver, like this:
receiver registration:
IntentFilter testResultIntentFilter = new IntentFilter("TEST_RESULT");
TestResultReceiver receiver = new TestResultReceiver();
this.registerReceiver(receiver,testResultIntentFilter);
onReceive method in the receiver:
@Override
public void onReceive(Context context, Intent intent) {
String message = intent.getStringExtra("MODE");
Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
}
this code fails on the getStringExtra call with null pointer exception, it's as if the putExtra method is ignored. I tried everything but nothing works.
add a comment |
up vote
-1
down vote
favorite
I have an intent service that sends an intent, like this:
Intent result = new Intent("TEST_RESULT");
result.putExtra("MODE", "testing");
sendBroadcast(result);
in another application, the intent gets captured by a broadcast receiver, like this:
receiver registration:
IntentFilter testResultIntentFilter = new IntentFilter("TEST_RESULT");
TestResultReceiver receiver = new TestResultReceiver();
this.registerReceiver(receiver,testResultIntentFilter);
onReceive method in the receiver:
@Override
public void onReceive(Context context, Intent intent) {
String message = intent.getStringExtra("MODE");
Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
}
this code fails on the getStringExtra call with null pointer exception, it's as if the putExtra method is ignored. I tried everything but nothing works.
2
Intent result = new Intentand thenintent.putStri. Is it a typo or you have multiple intents?
– Blackbelt
Nov 21 at 16:45
1
Please provide the complete stack trace. There's really no way that thegetStringExtra()line is throwing an NPE. ThatIntentcannot be null, andgetStringExtra()will return null if there is noStringextra with that key, but it won't throw an NPE there.
– Mike M.
Nov 21 at 17:58
Possible duplicate of What is a NullPointerException, and how do I fix it?
– Mushtak
Nov 21 at 18:16
fixed the issue?
– Jins Lukose
Nov 22 at 6:37
add a comment |
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
I have an intent service that sends an intent, like this:
Intent result = new Intent("TEST_RESULT");
result.putExtra("MODE", "testing");
sendBroadcast(result);
in another application, the intent gets captured by a broadcast receiver, like this:
receiver registration:
IntentFilter testResultIntentFilter = new IntentFilter("TEST_RESULT");
TestResultReceiver receiver = new TestResultReceiver();
this.registerReceiver(receiver,testResultIntentFilter);
onReceive method in the receiver:
@Override
public void onReceive(Context context, Intent intent) {
String message = intent.getStringExtra("MODE");
Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
}
this code fails on the getStringExtra call with null pointer exception, it's as if the putExtra method is ignored. I tried everything but nothing works.
I have an intent service that sends an intent, like this:
Intent result = new Intent("TEST_RESULT");
result.putExtra("MODE", "testing");
sendBroadcast(result);
in another application, the intent gets captured by a broadcast receiver, like this:
receiver registration:
IntentFilter testResultIntentFilter = new IntentFilter("TEST_RESULT");
TestResultReceiver receiver = new TestResultReceiver();
this.registerReceiver(receiver,testResultIntentFilter);
onReceive method in the receiver:
@Override
public void onReceive(Context context, Intent intent) {
String message = intent.getStringExtra("MODE");
Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
}
this code fails on the getStringExtra call with null pointer exception, it's as if the putExtra method is ignored. I tried everything but nothing works.
edited Nov 21 at 16:50
asked Nov 21 at 16:42
user1534252
1115
1115
2
Intent result = new Intentand thenintent.putStri. Is it a typo or you have multiple intents?
– Blackbelt
Nov 21 at 16:45
1
Please provide the complete stack trace. There's really no way that thegetStringExtra()line is throwing an NPE. ThatIntentcannot be null, andgetStringExtra()will return null if there is noStringextra with that key, but it won't throw an NPE there.
– Mike M.
Nov 21 at 17:58
Possible duplicate of What is a NullPointerException, and how do I fix it?
– Mushtak
Nov 21 at 18:16
fixed the issue?
– Jins Lukose
Nov 22 at 6:37
add a comment |
2
Intent result = new Intentand thenintent.putStri. Is it a typo or you have multiple intents?
– Blackbelt
Nov 21 at 16:45
1
Please provide the complete stack trace. There's really no way that thegetStringExtra()line is throwing an NPE. ThatIntentcannot be null, andgetStringExtra()will return null if there is noStringextra with that key, but it won't throw an NPE there.
– Mike M.
Nov 21 at 17:58
Possible duplicate of What is a NullPointerException, and how do I fix it?
– Mushtak
Nov 21 at 18:16
fixed the issue?
– Jins Lukose
Nov 22 at 6:37
2
2
Intent result = new Intent and then intent.putStri. Is it a typo or you have multiple intents?– Blackbelt
Nov 21 at 16:45
Intent result = new Intent and then intent.putStri. Is it a typo or you have multiple intents?– Blackbelt
Nov 21 at 16:45
1
1
Please provide the complete stack trace. There's really no way that the
getStringExtra() line is throwing an NPE. That Intent cannot be null, and getStringExtra() will return null if there is no String extra with that key, but it won't throw an NPE there.– Mike M.
Nov 21 at 17:58
Please provide the complete stack trace. There's really no way that the
getStringExtra() line is throwing an NPE. That Intent cannot be null, and getStringExtra() will return null if there is no String extra with that key, but it won't throw an NPE there.– Mike M.
Nov 21 at 17:58
Possible duplicate of What is a NullPointerException, and how do I fix it?
– Mushtak
Nov 21 at 18:16
Possible duplicate of What is a NullPointerException, and how do I fix it?
– Mushtak
Nov 21 at 18:16
fixed the issue?
– Jins Lukose
Nov 22 at 6:37
fixed the issue?
– Jins Lukose
Nov 22 at 6:37
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
intent.putExtra("MODE", "testing");
should be
result.putExtra("MODE", "testing");
sorry, my mistake in writing the question
– user1534252
Nov 21 at 16:50
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
intent.putExtra("MODE", "testing");
should be
result.putExtra("MODE", "testing");
sorry, my mistake in writing the question
– user1534252
Nov 21 at 16:50
add a comment |
up vote
1
down vote
intent.putExtra("MODE", "testing");
should be
result.putExtra("MODE", "testing");
sorry, my mistake in writing the question
– user1534252
Nov 21 at 16:50
add a comment |
up vote
1
down vote
up vote
1
down vote
intent.putExtra("MODE", "testing");
should be
result.putExtra("MODE", "testing");
intent.putExtra("MODE", "testing");
should be
result.putExtra("MODE", "testing");
answered Nov 21 at 16:48
Peter
132
132
sorry, my mistake in writing the question
– user1534252
Nov 21 at 16:50
add a comment |
sorry, my mistake in writing the question
– user1534252
Nov 21 at 16:50
sorry, my mistake in writing the question
– user1534252
Nov 21 at 16:50
sorry, my mistake in writing the question
– user1534252
Nov 21 at 16:50
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53416799%2fnull-pointer-exception-on-getstringextra%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
Intent result = new Intentand thenintent.putStri. Is it a typo or you have multiple intents?– Blackbelt
Nov 21 at 16:45
1
Please provide the complete stack trace. There's really no way that the
getStringExtra()line is throwing an NPE. ThatIntentcannot be null, andgetStringExtra()will return null if there is noStringextra with that key, but it won't throw an NPE there.– Mike M.
Nov 21 at 17:58
Possible duplicate of What is a NullPointerException, and how do I fix it?
– Mushtak
Nov 21 at 18:16
fixed the issue?
– Jins Lukose
Nov 22 at 6:37