Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { (has extras) }} to activity; java.lang.NullPointerException

Tags:

android

null

Im creating Triggers and Action Application for my Final Year Project,

I return a child Activity result to intermediate activity and ther add some data to that activity and send it again to main activity,

I did for both Trigger sub module and Action sub module, both like same coding....

trigger module is working perfectly, but when action module run application is force stopped

and error is

E/AndroidRuntime(5104): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { (has extras) }} to activity {mani.droid.mechanize/mani.droid.mechanize.ActionListActivity}: java.lang.NullPointerException

Child onActivityResult

public void onSave(View v)
{
    if(txtNum.length() != 0)
    {
        String strTmp = null;
        Intent resultInt = new Intent();
        strTmp = txtNum.getText().toString();
        resultInt.putExtra("Num", strTmp);
        resultInt.putExtra("SubName", strTmp);
        setResult(Activity.RESULT_OK, resultInt);
        finish();
    }
    else
        Toast.makeText(getApplicationContext(), "Please enter number or choose from contact", Toast.LENGTH_SHORT).show();
}

Intermediate onActivityResult

//getting result from other activity and sending to action list activity
@Override
public void onActivityResult(int reqCode, int resultCode, Intent data) {
    super.onActivityResult(reqCode, resultCode, data);
    if(resultCode == Activity.RESULT_OK)
    {
        switch(reqCode)
        {
            case 1:
                    data.putExtra("ActionName", txtAction);
                    setResult(Activity.RESULT_OK, data);
                    finish();
                    break;
        }
    }
}

Main onActivityResult

//Getting Trigger parameters and adding to list
@Override
public void onActivityResult(int reqCode, int resultCode, Intent data) {
    super.onActivityResult(reqCode, resultCode, data);
    if(resultCode == Activity.RESULT_OK)
    {
        switch(reqCode)
        {
            case 1:
                if (data.equals(null))
                {
                    Toast.makeText(context, "Intent is Null", Toast.LENGTH_SHORT).show();
                }
                else
                {
                    //String actName = data.getStringExtra("ActionName");
                    String subName = data.getStringExtra("SubName");
                    Toast.makeText(context, subName, Toast.LENGTH_SHORT).show();
                }
                break;
        }
    }
} 
like image 663
Mani Avatar asked Jun 18 '12 12:06

Mani


1 Answers

It means the Intent receiver threw an exception in its onActivityResult(). And I can see the NullPointerException right here: data.equals(null) is definitely wrong as it throws an exception when data is null. You mean data == null.

like image 136
Sean Owen Avatar answered Oct 05 '22 12:10

Sean Owen