Reputation: 91
Hi im developing a BLE App. After i scanned for devices and Display them into a ListFragment i want to get Services and Characteristics of them. If i implemented that in onListItemClick everything is fine i get the Services and the Characteristics. But now i want a new Activity started while i click on one Item.
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
rightPosition = position + 1;
connectToDevice();
Intent intent = new Intent(getActivity(),ServiceCharacteristicAvtivity.class);
startActivity(intent);
}
If i do like above my App crashes really looked for a solution but didnt get my failure. Maybe it is so easy that i dont see it. Can someone help me out?
The Log i get is
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.fkoffle.blescanner/com.example.fkoffle.blescanner.ServiceCharacteristicAvtivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3319)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3415)
at android.app.ActivityThread.access$1100(ActivityThread.java:229)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:7331)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.support.v7.app.AppCompatDelegateImplV9.createSubDecor(AppCompatDelegateImplV9.java:356)
at android.support.v7.app.AppCompatDelegateImplV9.ensureSubDecor(AppCompatDelegateImplV9.java:325)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:286)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
The activity i want to start is just
public class ServiceCharacteristicAvtivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_service_characteristic_avtivity);
}
}
Upvotes: 0
Views: 131
Reputation: 11
If you are extending an AppCompatActivity
you need to use an AppCompat or any descendant theme.
You can use one of the below themes in the manifest of your activity.
android:theme="@style/Theme.AppCompat.Light"
android:theme="@style/Theme.AppCompat.Light.DarkActionBar"
android:theme="@style/Theme.AppCompat.Light.NoActionBar"
eg.
<activity
android:name=".Activity"
android:theme="@style/Theme.AppCompat.Light.DarkActionBar" />
Upvotes: 1
Reputation: 427
Probably the activity you are calling is extending Activity, while your layout is having elements that comes under AppCompatActivity. So in your activity, do something like this:
public class ServiceCharacteristicAvtivity extends AppCompatActivity {
....
....
}
If it isn't the case, can you share your layout code and acytivity code?
Upvotes: 0
Reputation: 2195
Inside your manifest file, add the following theme.
<activity
android:name=". ServiceCharacteristicAvtivity"
android:theme="@style/Theme.AppCompat.Light.DarkActionBar" />
As your logcat suggests, you need to use Theme.AppCompat
or any descendent (like I used in above example).
Upvotes: 1