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.










share|improve this question




















  • 2




    Intent result = new Intent and then intent.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. 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










  • fixed the issue?
    – Jins Lukose
    Nov 22 at 6:37















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.










share|improve this question




















  • 2




    Intent result = new Intent and then intent.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. 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










  • fixed the issue?
    – Jins Lukose
    Nov 22 at 6:37













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.










share|improve this question















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.







android android-intent broadcastreceiver android-intentservice






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 at 16:50

























asked Nov 21 at 16:42









user1534252

1115




1115








  • 2




    Intent result = new Intent and then intent.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. 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










  • fixed the issue?
    – Jins Lukose
    Nov 22 at 6:37














  • 2




    Intent result = new Intent and then intent.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. 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










  • 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












1 Answer
1






active

oldest

votes

















up vote
1
down vote













intent.putExtra("MODE", "testing");


should be



result.putExtra("MODE", "testing");





share|improve this answer





















  • sorry, my mistake in writing the question
    – user1534252
    Nov 21 at 16:50











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















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

























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");





share|improve this answer





















  • sorry, my mistake in writing the question
    – user1534252
    Nov 21 at 16:50















up vote
1
down vote













intent.putExtra("MODE", "testing");


should be



result.putExtra("MODE", "testing");





share|improve this answer





















  • sorry, my mistake in writing the question
    – user1534252
    Nov 21 at 16:50













up vote
1
down vote










up vote
1
down vote









intent.putExtra("MODE", "testing");


should be



result.putExtra("MODE", "testing");





share|improve this answer












intent.putExtra("MODE", "testing");


should be



result.putExtra("MODE", "testing");






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 21 at 16:48









Peter

132




132












  • 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




sorry, my mistake in writing the question
– user1534252
Nov 21 at 16:50


















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Sphinx de Gizeh

Dijon

Guerrita