0

I have two classes MainActivity.Java and second one is non Activity class named Display.Java whose purpose is just to add two numbers. And return result to MainActivity.Java whcih will show result in EditTextView. But when i run app it stops immediately. Below is the code for both classes.

public class Display
{
    int a;

    public int display1()
    {
        a=2+2;
        return a;
    }
}
public class MainActivity extends ActionBarActivity {

    Display d;
    int c;
    EditText t;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        d=new Display();
        c=d.display1();
        t=(EditText) findViewById(R.id.editText1);
        t.setText(c);
    }
}
  • When you call `setText()` with an `int`, that `int` must be the ID for a `String` resource, or you'll get a `Resources.NotFoundException`. Convert your `c` value to a `String` first; e.g., `t.setText(String.valueOf(c));`. – Mike M. Apr 18 '17 at 02:53
  • Dear Mike my question is not duplicate as it has no similarity with answer you referenced. I am a newbie in android development. –  Apr 18 '17 at 02:54
  • It's the solution that's the same. You're calling `setText()` with an `int` that is not a Resource ID. – Mike M. Apr 18 '17 at 02:55
  • Thanks i have understood a bit. –  Apr 18 '17 at 02:57
  • Thanks you have solved my problem. I had been searching for it for very long time. –  Apr 18 '17 at 02:58
  • No problem. You should have a look at the following posts. They will help you in the future to determine what exactly is the problem when you get a crash, and how to fix it: [Unfortunately MyApp has stopped. How can I solve this?](http://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-solve-this), [What Is A Stack Trace And How Can I Use It To Debug My Application Errors](http://stackoverflow.com/questions/3988788/), [What is a NullPointerException, and how do I fix it?](http://stackoverflow.com/questions/218384/). – Mike M. Apr 18 '17 at 03:01

0 Answers0