0

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); } 

}

5
  • Can you please add the logs? Commented Sep 21, 2017 at 10:12
  • one "solution" i found didnt helped me stackoverflow.com/questions/15514831/… Commented Sep 21, 2017 at 10:17
  • Sorry Eselfar of course i can add the logs Commented Sep 21, 2017 at 10:23
  • add more code and logs Commented Sep 21, 2017 at 10:24
  • Can you post code of the activity you are trying to start Commented Sep 21, 2017 at 10:31

3 Answers 3

1

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).

Sign up to request clarification or add additional context in comments.

1 Comment

Oh my God... that was the failure i didnt watched in my manifest thx to all
1

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" /> 

Comments

0

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?

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.