Thamilan S
Thamilan S

Reputation: 1042

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

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;
        }
    }
} 

Upvotes: 8

Views: 41529

Answers (2)

Mina Fawzy
Mina Fawzy

Reputation: 21452

just check null != data , as data equal null

Upvotes: 0

Sean Owen
Sean Owen

Reputation: 66886

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.

Upvotes: 8

Related Questions