MutantTurtlez
MutantTurtlez

Reputation: 61

Android Intent "Expression Expected"

I am following the Sams 24hr programming book, but for the life of me cannot seem to fix an issue i am having with Hour 2.

I am trying to create a simple button that launches a second activity and changes the TextArea on the second activity.

This is my code for the second activity. I am getting "Expression Expected" on the Intent in "Intent= getIntent();" and "getStringExtra" is non static method cannot be referenced from static content.

My code looks the same as my book :S

package co.jamesbrown.hour2app;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;

public class Second extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_second);

        Intent= getIntent();
        String message = Intent.getStringExtra("co.jamesbrown.MESSAGE");
        TextView messageTextView = (TextView) findViewById(R.id.message);
        messageTextView.setText(message);
    }
}

Thanks in advance

James

Upvotes: 0

Views: 2037

Answers (3)

John Joe
John Joe

Reputation: 12803

Apart from the answer given , you can also write it in another way

String message = getIntent().getStringExtra("co.jamesbrown.MESSAGE");

Source : How do I get extra data from intent on Android?

Upvotes: 0

Jinal
Jinal

Reputation: 44

Correct it to as below

 Intent intent= getIntent();
 String message = intent.getStringExtra("co.jamesbrown.MESSAGE");

Upvotes: 2

Ashish Ranjan
Ashish Ranjan

Reputation: 5543

Intent= getIntent(); this is not a Java expresssion. You need to give a name while declaring the variable in Java like this :

Intent yourIntent = getIntent();

then you can do :

String message = yourIntent.getStringExtra("co.jamesbrown.MESSAGE");

to get the String value passed through the Intent.

Upvotes: 1

Related Questions