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>