0

Basically I want to press a button and display a predefined string variable in a new blank window. I've tried several methods and none work. This is my first app ever so I dont have much knowledge on how to use classes. this is the code I have now for the Onclick action

public void receivedata(View data) {
    Intent intent= new Intent(this, ReceivedataActivity.class);
    intent.putExtra("My Message", false);
    startActivity(intent);
}

and this is the code I have on the class

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.receivedata);
    Intent intent = getIntent();
    String message = intent.getStringExtra("My Message");

    TextView comm = (TextView) findViewById(R.id.textView1);
    comm.setTextSize(40);
    comm.setText(message);

    setContentView(comm);

    if (savedInstanceState == null) {
        getSupportFragmentManager().beginTransaction()
                .add(R.id.container, new PlaceholderFragment()).commit();
    }
}

The App just crashes whenever I press the button... any ideas on how to do this?

This is what the LogCat says: this is what te logcat says E/AndroidRuntime(11090): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mcudisplay/com.example.mcudisplay.ReceivedataActivity}‌​: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity

Cod_Ubau
  • 37
  • 1
  • 1
  • 10
  • Always post a stack trace from logcat if you dont understand the cause of a crash. – Karakuri May 26 '14 at 23:00
  • Why are you calling `setContentView` twice? – Karakuri May 26 '14 at 23:02
  • possible duplicate of [Unfortunately MyApp has stopped. How can I solve this?](http://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-solve-this) – Code-Apprentice May 26 '14 at 23:07
  • What does log cat logs say? What is the exception? – prijupaul May 26 '14 at 23:07
  • @prijupaul this is what te logcat says E/AndroidRuntime(11090): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mcudisplay/com.example.mcudisplay.ReceivedataActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. – Cod_Ubau May 26 '14 at 23:52
  • Well, the log entry seems pretty self-explanatory... :) – matiash May 27 '14 at 00:43

2 Answers2

1

You are calling setContentView twice, which suggests to me that one of these calls is wrong and unnecessary. Either R.layout.receivedata contains the TextView you are retrieving with findViewById() and you did not mean to make second call; or you DO mean to call setContentView with just the TextView, in which case you should inflate it separately with a LayoutInflater or create it with new.

Karakuri
  • 38,365
  • 12
  • 84
  • 104
0

try to run your app without the line:

setContentView(comm);

You already set your content view to your receivedata.xml file.

Penta
  • 241
  • 2
  • 4
  • 12