-3

I am very new to android and just starting to understand how to develop simple apps (AndroidStudio, Ubuntu 14.04, LG G3). From a main activity I want to start another activity (i.e. to show a different screen where the user can make some input) following this solution. In the file MainActivity.java I have the following method:

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.menu_add:           
            Intent myIntent = new Intent(MainActivity.this, NewEntryActivity.class);
            MainActivity.this.startActivity(myIntent);
            return true;          
        default:
            return super.onOptionsItemSelected(item);
    }
}

And the file NewEntryActivity.java is defined as follows:

package com.example.alexander.myapplication;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.Button;
import android.widget.EditText;

public class NewEntryActivity extends AppCompatActivity {

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

        final EditText editNewIsin = (EditText) findViewById(R.id.new_isin);
        final EditText editNewPrice = (EditText) findViewById(R.id.new_price);
        final EditText editNewNumber = (EditText) findViewById(R.id.new_number);
        Button buttonNewOk = (Button) findViewById(R.id.new_ok);
        Button buttonNewCancel = (Button) findViewById(R.id.new_cancel);


    }

}

No error is indicated for this file (everything seems to be defined properly). When I start the app on my phone, the main activity starts without problem, but when I choose the menu item to start the other activity the app closes immediately and I see an error:

Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity

However, both activities are derived from AppCompatActivity. Maybe it refers to something else (Manifest, layout.xml, ...?), but this is not clear from the error message. Any help is appreciated here...

Here is also the manifest file:

<?xml version="1.0" encoding="utf-8"?>
<manifest
    xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.alexander.myapplication" >

    <application>
        android:allowBackup="true"
        android:icon="@mipmap/stoxx"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/Theme.AppCompat.Light.DarkActionBar" />     

        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity
            android:name=".NewEntryActivity"
            android:label="@string/menu_add"
        />

    </application>

</manifest>
Community
  • 1
  • 1
Alex
  • 41,580
  • 88
  • 260
  • 469

1 Answers1

0

Just use the same theme as home in your other activity. like this

    <activity
        android:name=".SecondActivity"
        android:label="@string/second"
        android:theme="@style/AppTheme.NoActionBar" >
    </activity>
Arslan Ashraf
  • 867
  • 7
  • 12
  • I have only 'style name="AppTheme"' in my `styles.xml` file. But when I replace this and the entry in the manifest file, I still get the same error as before. – Alex Oct 27 '15 at 15:11
  • Check the updated answer. this worked for me and kindly accept this answer if it works. Thanks – Arslan Ashraf Oct 27 '15 at 15:28
  • Do I need to put this 'AppTheme.NoActionBar' just to the new activity, or to the main application in the manifest as well? What about I have defined in styles.xml? And why do I need three places to define the theme? And why does the app crash because of a theme? Isn't that just how the graphics look? And what are the differences between those many themes? Where can I get answers to all of my questions? – Alex Oct 27 '15 at 15:31