8

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;
        }
    }
} 
Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
Thamilan S
  • 1,045
  • 3
  • 18
  • 30

2 Answers2

8

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.

Sean Owen
  • 66,182
  • 23
  • 141
  • 173
  • I some what managed to this problem and solved, but I don't know how it solved, and I also tried data == null before, same error, thats why I tried data.equals(null) – Thamilan S Jun 18 '12 at 19:50
  • Then your `NullPointerException` is elsewhere. It's directing you to a line number, so follow that. You didn't post your stack trace -- always a good idea. `data.equals(null)` is never correct in Java. It is always `false` or throws an exception. – Sean Owen Jun 18 '12 at 20:29
  • Same question can anyone tell what is **`who=null`** ? – karanatwal.github.io Feb 06 '17 at 14:57
0

just check null != data , as data equal null

Mina Fawzy
  • 20,852
  • 17
  • 133
  • 156