Raider00321
Raider00321

Reputation: 57

issue with passing data to onActivityResult

im attempting to send a string from one of my activities to the main activity of the group, but am having a small issue. Im attempting to create an object in the onActivityResult part of my code(which seems to work). but when trying to access methods from this class other than getName(), it spits out a resource not found exception. Im sure the solution is simple, but it continues to elude me after looking into it a fair bit. heres the code....

MainActivity

public void onActivityResult(int requestCode, int resultCode, Intent data)
   {
       super.onActivityResult(requestCode, resultCode, data);
       switch(requestCode)
       {
       case 0:
           //for add activity
           if(resultCode == RESULT_OK)
           {

                        namePasser = data.getExtras().getString("tallyName").toString();
                        itemHm.put("item1", new Items(namePasser,1));
                        itemAmt++;
                        currItem = itemHm.get("item1");
                        nameView1.setText(currItem.getName());
                        countView1.setText(currItem.getGroup());
                        count1b.setVisibility(View.VISIBLE);
                        reduce1b.setVisibility(View.VISIBLE);
                        countView1.setVisibility(View.VISIBLE);
                        resetb.setVisibility(View.VISIBLE);

           }
       }
   }

addActivity

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class addActivity extends Activity
{
    EditText name;
    String itemName;
    Button next;
    Intent data;
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.addactivityxml);
        Button next = (Button) findViewById(R.id.button1);
        next.setOnClickListener(new View.OnClickListener() 
        {
            public void onClick(View view) 
            {
                name = (EditText)findViewById(R.id.newitemtxt);
                itemName = name.getText().toString();
                data = new Intent();
                data.putExtra("tallyName", itemName);
                setResult(RESULT_OK, data);
                finish();
            }
        });
    }
}

Items Class

public class Items
{
    int id = 0;
    int group = 0;
    String name = "";
    int count = 0;
    public Items(String name, int count)
    {
        this.count = count;
        this.name = name;
    }
    public Items(String name, int count, int group)
    {
        this.group = group;
        this.name = name;
        this.count = count;
    }
    public Items(int id, String name, int group)
    {
        this.id = id;
        this.group = group;
        this.name = name;
    }
    public String getName()
    {
        return name;
    }
    public int getCount()
    {
        return count;
    }
    public int addCount()
    {
        count++;
        return count;
    }
    public int reduceCount()
    {
        if(count > 0)
        {
            count--;
            return count;
        }
        return count;
    }
    public int resetCount()
    {
        count = 0;
        return count;
    }
    public void setGroup(int group)
    {
        this.group = group;
    }
    public int getGroup()
    {
        return group;
    }
}

The data itself is being passed through to onActivity Result when i run nameView1.setText(currItem.getName()); eiyhout a problem,

but when trying to run countView1.setText(currItem.getGroup()); thats when the issue occurs

oh! heres the error log

04-19 11:09:56.219: W/dalvikvm(1970): threadid=1: thread exiting with uncaught exception (group=0x409c01f8) 04-19 11:09:56.258: E/AndroidRuntime(1970): FATAL EXCEPTION: main 04-19 11:09:56.258: E/AndroidRuntime(1970): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=0, result=-1, data=Intent { (has extras) }} to activity {com.DanielFurnell.iTallyLite/com.DanielFurnell.iTallyLite.ITallyLiteActivity}: android.content.res.Resources$NotFoundException: String resource ID #0x0 04-19 11:09:56.258: E/AndroidRuntime(1970): at android.app.ActivityThread.deliverResults(ActivityThread.java:2980) 04-19 11:09:56.258: E/AndroidRuntime(1970): at android.app.ActivityThread.handleSendResult(ActivityThread.java:3023) 04-19 11:09:56.258: E/AndroidRuntime(1970): at android.app.ActivityThread.access$1100(ActivityThread.java:123) 04-19 11:09:56.258: E/AndroidRuntime(1970): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1177) 04-19 11:09:56.258: E/AndroidRuntime(1970): at android.os.Handler.dispatchMessage(Handler.java:99) 04-19 11:09:56.258: E/AndroidRuntime(1970): at android.os.Looper.loop(Looper.java:137) 04-19 11:09:56.258: E/AndroidRuntime(1970): at android.app.ActivityThread.main(ActivityThread.java:4424) 04-19 11:09:56.258: E/AndroidRuntime(1970): at java.lang.reflect.Method.invokeNative(Native Method) 04-19 11:09:56.258: E/AndroidRuntime(1970): at java.lang.reflect.Method.invoke(Method.java:511) 04-19 11:09:56.258: E/AndroidRuntime(1970): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) 04-19 11:09:56.258: E/AndroidRuntime(1970): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 04-19 11:09:56.258: E/AndroidRuntime(1970): at dalvik.system.NativeStart.main(Native Method) 04-19 11:09:56.258: E/AndroidRuntime(1970): Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x0 04-19 11:09:56.258: E/AndroidRuntime(1970): at android.content.res.Resources.getText(Resources.java:247) 04-19 11:09:56.258: E/AndroidRuntime(1970): at android.widget.TextView.setText(TextView.java:3473) 04-19 11:09:56.258: E/AndroidRuntime(1970): at com.DanielFurnell.iTallyLite.ITallyLiteActivity.onActivityResult(ITallyLiteActivity.java:73) 04-19 11:09:56.258: E/AndroidRuntime(1970): at android.app.Activity.dispatchActivityResult(Activity.java:4649) 04-19 11:09:56.258: E/AndroidRuntime(1970): at android.app.ActivityThread.deliverResults(ActivityThread.java:2976) 04-19 11:09:56.258: E/AndroidRuntime(1970): ... 11 more

I am also quite sure there isnt anything wrong with the textbox of the item as i can assign other values to it outside of ActivityResult Thanks in advance to anyone that can help me with this issue =)

Upvotes: 1

Views: 2514

Answers (2)

idiottiger
idiottiger

Reputation: 5177

countView1.setText(currItem.getGroup());

may be this line has problem, getGroup return the int type, it think is as the string id, so you need check the return value is a valid string id or not, if you only want to set the content with getGroup return, try use:

countView1.setText(currItem.getGroup()+"");

Upvotes: 2

Shankar Agarwal
Shankar Agarwal

Reputation: 34765

name = (EditText)findViewById(R.id.newitemtxt);

remove this line from click event and add below button next = ...

and try..

Upvotes: 0

Related Questions