-4

I'm a newb at Java, but know python.

I put an EditText in my xml, with a number input type. When someone inputs a number, I want it to get multiplied by, say, 80

this is my main activity code

public void sendMessage(View view) {
    Intent intent = new Intent(this, DisplayMessageActivity.class);
    EditText editText = (EditText) findViewById(R.id.edit_message);
    String message = editText.getText().toString();
    intent.putExtra(EXTRA_MESSAGE, message);
    startActivity(intent);

then the displaymessage activity:

Intent intent = getIntent();
String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);
int ma = Integer.parseInt(message.trim());
int result = ma * 80;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);



    TextView textView = new TextView(this);
    textView.setTextSize(40);
    textView.setText(result);


    setContentView(textView);
}

When input a number and send the messagem the app crashes.

zx81
  • 41,100
  • 9
  • 89
  • 105

1 Answers1

0
Intent intent = getIntent();

I assume this is a member variable. Calling getIntent() at this point in your code is an error. You should move this and the rest of your member variables to onCreate().

Further reading:

Starting Another Activity

The Activity Lifecycle

Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268