API Version Incompatibilities
I have made an app using android studio, until now I have been testing it on a 'Nexus 5X (API 23) emulator'. However, today i started debugging the app on a 'Samsung Galaxy Tab 2 7.0 (API 18)' and the app will not even start. I know this is because of incompatibilities between the API's specifically something to do with the Theme i'm using. What i want to know is how i can fix this problem without changing the look of the app drastically.
Log Cat Crash Log
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.***.********/com.***.********.MenuActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2245)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2295)
at android.app.ActivityThread.access$700(ActivityThread.java:150)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1280)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:175)
at android.app.ActivityThread.main(ActivityThread.java:5279)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.support.v7.app.AppCompatDelegateImplBase.onCreate(AppCompatDelegateImplBase.java:124)
at android.support.v7.app.AppCompatDelegateImplV7.onCreate(AppCompatDelegateImplV7.java:146)
at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:59)
at com.***.*******.MenuActivity.onCreate(MenuActivity.java:47)
at android.app.Activity.performCreate(Activity.java:5283)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1097)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2209)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2295)
at android.app.ActivityThread.access$700(ActivityThread.java:150)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1280)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:175)
at android.app.ActivityThread.main(ActivityThread.java:5279)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(Native Method)
Android Manifest
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".MenuActivity"
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=".About" />
<activity android:name=".SettingsActivity" />
<activity android:name=".********Activity" />
<activity android:name=".********Activity" />
<activity
android:name=".VideoPlayerActivity"
android:screenOrientation="landscape" />
<activity android:name=".*******Activity"></activity>
</application>
Gradle Build App File
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.***.*******"
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName "2.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:22.2.1'
compile 'com.android.support:design:22.2.1'
}
Note: The last two lines (the ones with compile...) are underlined in red and say 'This support library should not use a different version(22) than the compile SDK version(21).'
Edit: If I change the Theme for the main activity to '#style/Theme.AppCompat.NoActionBar' the application will start however, the look of the application changes. Also, other activities that do not use the new theme work fine.
Any Help is Appreciated.
Related
I've tried and tried and tried to figure this problem out. I've searched everywhere and I haven't found a solution yet. I understand that there are many forums on this topic, but none have helped me come up with a solution.
The problem I'm having is that when I run my android application, in the emulator, the area for the map comes up only with grey tiles. I've read online that the problem is most likely the Google API key, but I've tried multiples way to generate it (Used the Android Studio Terminal to obtain SHA1, I had Android studio generate a link to google so it can automatically create the key).
I'm hoping someone can help me out, I'm pretty desperate here!
Here's my Activity class
package com.bignerdranch.android.taskmanager;
import android.os.Bundle;
import com.google.android.maps.MapActivity;
public class AddLocationMapActivity extends MapActivity {
public static final String ADDRESS_RESULT = "address";
#Override
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.add_location);
}
#Override
protected boolean isRouteDisplayed() {
return false;
}
#Override
protected boolean isLocationDisplayed() {
return true;
}
}
This is the layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/location_title"
.../>
<EditText
android:id="#+id/task_address"
.../>
<Button
android:id="#+id/map_location_button"
.../>
<com.google.android.maps.MapView
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/map_location_button"
android:layout_above="#+id/use_this_location_button"
android:clickable="true"
android:apiKey="AIza.................................." />
<Button
android:id="#id/use_this_location_button"
.../>
</RelativeLayout>
Then, this is the manifest file:
?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.bignerdranch.android.taskmanager">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:name=".TaskManagerApplication"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIza..........................." />
<activity android:name=".ViewTasksActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".AddTaskActivity"
android:text="#string/add_task"/>
<activity android:name=".AddLocationMapActivity"
android:text="#string/add_location_to_task"/>
<uses-library android:name="com.google.android.maps" />
</application>
</manifest>
Then the build.gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 'Google Inc.:Google APIs:24'
buildToolsVersion "24.0.2"
defaultConfig {
applicationId "com.bignerdranch.android.taskmanager"
minSdkVersion 16
targetSdkVersion 24
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.google.android.gms:play-services-maps:10.0.1'
compile 'com.google.android.gms:play-services-location:10.0.1'
}
And lastly, this is what is generated by the Monitor:
12-02 22:37:10.351 22387-22537/com.bignerdranch.android.taskmanager W/System.err: IOException processing: 26
12-02 22:37:10.351 22387-22537/com.bignerdranch.android.taskmanager W/System.err: java.io.IOException: Server returned: 3
12-02 22:37:10.352 22387-22537/com.bignerdranch.android.taskmanager W/System.err: at android_maps_conflict_avoidance.com.google.googlenav.map.BaseTileRequest.readResponseData(BaseTileRequest.java:115)
12-02 22:37:10.352 22387-22537/com.bignerdranch.android.taskmanager W/System.err: at android_maps_conflict_avoidance.com.google.googlenav.map.MapService$MapTileRequest.readResponseData(MapService.java:1473)
12-02 22:37:10.352 22387-22537/com.bignerdranch.android.taskmanager W/System.err: at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.processDataRequest(DataRequestDispatcher.java:1117)
12-02 22:37:10.352 22387-22537/com.bignerdranch.android.taskmanager W/System.err: at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.serviceRequests(DataRequestDispatcher.java:994)
12-02 22:37:10.352 22387-22537/com.bignerdranch.android.taskmanager W/System.err: at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher$DispatcherServer.run(DataRequestDispatcher.java:1702)
12-02 22:37:10.352 22387-22537/com.bignerdranch.android.taskmanager W/System.err: at java.lang.Thread.run(Thread.java:818)
I WOULD BE FOREVER GRATEFUL TO THE PERSON WHO CAN HELP ME FIGURE THIS PROBLEM OUT!
Grey tiles instead of map
The map that you're using com.google.android.maps.MapView is a v1 of Google Map API. Unfortunately, it is officially deprecated.
You should use the new version of Google Maps API which is Version 2
Here's a tutorial for Google Map V2
I created an Android Library to implement FCM to use in my internal projects, where I implement a class to extend FirebaseMessagingService (.services.MyFirebaseMessagingService ) and another one to extend FirebaseInstanceIdService (.services.MyFirebaseInstanceIDService).
I defined this in my AndroidManifest.xml inside the library as below:
<!-- [START firebase_service] -->
<service
android:name=".services.MyFirebaseMessagingService"
android:exported="true">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<!-- [END firebase_service] -->
<!-- [START firebase_iid_service] -->
<service android:name=".services.MyFirebaseInstanceIDService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
<!-- [END firebase_iid_service] -->
When I included all the library source code as a module in my App, everything worked well, but when I included only the AAR generated, I received this error when I run my application:
java.lang.RuntimeException: Unable to instantiate service com.example.lib.services.MyFirebaseMessagingService: java.lang.ClassNotFoundException: com.example.lib.services.MyFirebaseMessagingService
at android.app.ActivityThread.handleCreateService(ActivityThread.java:2380)
at android.app.ActivityThread.access$1600(ActivityThread.java:138)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1286)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4905)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: com.example.lib.services.MyFirebaseMessagingService
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:2377)
at android.app.ActivityThread.access$1600(ActivityThread.java:138)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1286)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4905)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
at dalvik.system.NativeStart.main(Native Method)
The service com.example.lib.services.MyFirebaseInstanceIDService works correctly.
What I need to do with AAR generated library to work?
For FCM follow this step :
1 - in main Build.gradle (not in app folder) add this line :
buildscript {
// ...
dependencies {
// ...
classpath 'com.google.gms:google-services:3.0.0'
}
2- in app/build.gradle add this line :
apply plugin: 'com.android.application'
android {
// ...
}
dependencies {
// ...
compile 'com.google.firebase:firebase-core:9.8.0'
compile 'com.google.firebase:firebase-messaging:9.8.0'
// Getting a "Could not find" error? Make sure you have
// the latest Google Repository in the Android SDK manager
}
// ADD THIS AT THE BOTTOM
apply plugin: 'com.google.gms.google-services'
Note : "Android Support Repository" in you SDk most be updated .
Hope this help
click on Build - > Clean then install & run the app
I am developing a chat application for Android. But while trying to register with GCM, I am receiving the following error:
04-02 16:59:29.793 29773-30031/purepush.group101.talktoday W/InstanceID/Rpc: Found 10010
04-02 16:59:29.920 29773-30031/purepush.group101.talktoday W/System.err: java.io.IOException: SERVICE_NOT_AVAILABLE
04-02 16:59:29.922 29773-30031/purepush.group101.talktoday W/System.err: at com.google.android.gms.iid.zzc.zzb(Unknown Source)
04-02 16:59:29.922 29773-30031/purepush.group101.talktoday W/System.err: at com.google.android.gms.iid.zzc.zza(Unknown Source)
04-02 16:59:29.922 29773-30031/purepush.group101.talktoday W/System.err: at com.google.android.gms.iid.InstanceID.zzc(Unknown Source)
04-02 16:59:29.922 29773-30031/purepush.group101.talktoday W/System.err: at com.google.android.gms.iid.InstanceID.getToken(Unknown Source)
04-02 16:59:29.922 29773-30031/purepush.group101.talktoday W/System.err: at purepush.group101.talktoday.LoginActivity$GetGCMTokenTask.doInBackground(LoginActivity.java:240)
04-02 16:59:29.923 29773-30031/purepush.group101.talktoday W/System.err: at purepush.group101.talktoday.LoginActivity$GetGCMTokenTask.doInBackground(LoginActivity.java:211)
04-02 16:59:29.923 29773-30031/purepush.group101.talktoday W/System.err: at android.os.AsyncTask$2.call(AsyncTask.java:295)
04-02 16:59:29.923 29773-30031/purepush.group101.talktoday W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:237)
04-02 16:59:29.923 29773-30031/purepush.group101.talktoday W/System.err: at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
04-02 16:59:29.923 29773-30031/purepush.group101.talktoday W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
04-02 16:59:29.923 29773-30031/purepush.group101.talktoday W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
04-02 16:59:29.923 29773-30031/purepush.group101.talktoday W/System.err: at java.lang.Thread.run(Thread.java:818)
04-02 16:59:29.958 29773-29773/purepush.group101.talktoday E/GcmReceiver: Failed to resolve target intent service, skipping classname enforcement
04-02 16:59:29.958 29773-29773/purepush.group101.talktoday E/GcmReceiver: Error while delivering the message: ServiceIntent not found.
I am obtaining GCM token using the following code:
InstanceID instanceID = InstanceID.getInstance(context);`
regToken = instanceID.getToken(getString(R.string.gcm_defaultSenderId), GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
MANIFEST:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="purepush.group101.talktoday">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<permission
android:name="purepush.group101.talktoday.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="purepush.group101.talktoday.permission.C2D_MESSAGE" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".LoginActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity" />
<activity android:name=".ChatActivity" />
<receiver
android:name="com.google.android.gms.gcm.GcmReceiver"
android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="purepush.group101.talktoday" />
</intent-filter>
</receiver>
<service
android:name=".utils.GCMMessageListener"
android:enabled="true"
android:exported="false">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</service>
</application>
</manifest>
Build.Gradle (App Module)
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "21.1.2"
useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId 'purepush.group101.talktoday'
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.1'
compile 'com.android.support:design:23.2.1'
compile 'org.apache.httpcomponents:httpmime:4.5.2'
compile 'org.apache.httpcomponents:httpclient:4.5.2'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.google.android.gms:play-services:8.4.0'
}
Now the funny thing is, this error occurs only on my Nexus 5 running 6.0.1 (Build: MMB29Q). I tested this application on my colleague's Samsung Note 4 running 5.1.1 and I was able to successfully register his device with GCM. I am getting this error with multiple of our applications using GCM only my Nexus 5.
Any help on this would be appreciated
Thanks!
Please check your "Nexus 5" clock, it should be exact, and try to change
buildToolsVersion "21.1.2"
to something like: buildToolsVersion "23.0.2" => i'm using this version and GCM working well with Android 6
Update:
I'm using this Method to register my GCM
public void getRegId() {
new AsyncTask<Void, Void, String>() {
#Override
protected String doInBackground(Void... params) {
try {
if (gcm == null) {
gcm = GoogleCloudMessaging.getInstance(getApplicationContext());
}
regid = gcm.register(R.string.gcm_defaultSenderId);
msg = "Device registered, registration ID=" + regid;
} catch (IOException ex) {
msg = "Error :" + ex.getMessage();
System.out.println("Error---" + ex.getMessage());
}
return msg;
}
#Override
protected void onPostExecute(String msg) {
System.out.println("Registerid---" + regid);
}
}.execute(null, null, null);
}
please try it and let me know.
Well, it turns out that my Google Play store wasn't working properly. I could view apps and install new ones but when I entered "My apps & games", it gave me the Check your connection and try again error. So, I am posting this solution for anyone who might be having a similar problem since I spend 4-5 days looking for errors and trying different fixes.
Note: This is only for rooted users.
Steps:
Open your FIle Manager. I used ES File Explorer.
Goto "/" or the root of your phone
There will be folder called etc
Inside etc, you'll see a file name hosts
Inside the hosts file, you'll see 2 IP addresses. The second one will vary depending upon your location
Add a # at the start of the 2nd IP Address. # will change that line to a comment
I recommend making a backup of the hosts file before editing.
Credits to "Ronny927": http://forum.xda-developers.com/showthread.php?t=2273994
I have faced the same situation some days ago, it is not the problem of GCM it is the problem of our internet connection. see below points for more understanding
you phone is connected to wifi but there is no internet from wifi, try to google in browser, if it is working perfectly then you should try some more things, like checking play services in your device and many more.
your phone's data pack could have been over , it means that you are connected to internet , but you won't get any kind of data from it. this error can not be identified without checking connection to your server.
You can get additional details from this link
How to fix Google Cloud Messaging Registration error: SERVICE_NOT_AVAILABLE?
I had an old project in Eclipse and I imported it into Android Studio to rebuild it with Material Design.
I done all things...
configured build.gradle and dependencies:
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.mhrz.Minesweeper"
minSdkVersion 8
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.1.1'
compile 'com.android.support:cardview-v7:+'
}
and styles:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#1E9618</item>
<item name="colorPrimaryDark">#146310</item>
<item name="colorAccent">#1E9618</item>
</style>
</resources>
and this is Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mhrz.Minesweeper"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".MinesweeperGame"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
and also CardView works well.
The problem is that app works correctly with this and give me Holo Design:
public class MinesweeperGame extends Activity {
but I want Material and I get FC on:
public class MinesweeperGame extends AppCompatActivity {
with this log:
01-03 16:29:38.779 12720-12720/com.mhrz.Minesweeper E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.mhrz.Minesweeper, PID: 12720
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mhrz.Minesweeper/com.mhrz.Minesweeper.MinesweeperGame}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2219)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2269)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5045)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.support.v7.app.AppCompatDelegateImplBase.onCreate(AppCompatDelegateImplBase.java:113)
at android.support.v7.app.AppCompatDelegateImplV7.onCreate(AppCompatDelegateImplV7.java:146)
at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:59)
at com.mhrz.Minesweeper.MinesweeperGame.onCreate(MinesweeperGame.java:55)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2163)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2269)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5045)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Where is mistake? How to fix it?
Android system doesn't know that you want to use alternate theme for application (like yours AppTheme) until you define it in application or activity attribute inside AndroidManifest.xml file.
You need to add the android:theme="#style/AppTheme" attribute to your <application> tag in AndroidManifest.xml like this:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mhrz.Minesweeper"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="#drawable/icon"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<activity android:name=".MinesweeperGame"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
I can't find the solution of this error. Can you please give the permanent solution? I have no idea how to solve it.
01-04 11:06:42.302: E/AndroidRuntime(1906): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{e.gochat/e.gochat.gochat.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "e.gochat.gochat.MainActivity" on path: DexPathList[[zip file "/data/app/e.gochat-1.apk"],nativeLibraryDirectories=[/data/app-lib/e.gochat-1, /vendor/lib, /system/lib]]
01-04 11:06:42.302: E/AndroidRuntime(1906): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2102)
01-04 11:06:42.302: E/AndroidRuntime(1906): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2226)
01-04 11:06:42.302: E/AndroidRuntime(1906): at android.app.ActivityThread.access$700(ActivityThread.java:135)
01-04 11:06:42.302: E/AndroidRuntime(1906): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1397)
01-04 11:06:42.302: E/AndroidRuntime(1906): at android.os.Handler.dispatchMessage(Handler.java:102)
01-04 11:06:42.302: E/AndroidRuntime(1906): at android.os.Looper.loop(Looper.java:137)
01-04 11:06:42.302: E/AndroidRuntime(1906): at android.app.ActivityThread.main(ActivityThread.java:4998)
01-04 11:06:42.302: E/AndroidRuntime(1906): at java.lang.reflect.Method.invokeNative(Native Method)
01-04 11:06:42.302: E/AndroidRuntime(1906): at java.lang.reflect.Method.invoke(Method.java:515)
01-04 11:06:42.302: E/AndroidRuntime(1906): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
01-04 11:06:42.302: E/AndroidRuntime(1906): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593)
01-04 11:06:42.302: E/AndroidRuntime(1906): at dalvik.system.NativeStart.main(Native Method)
01-04 11:06:42.302: E/AndroidRuntime(1906): Caused by: java.lang.ClassNotFoundException: Didn't find class "e.gochat.gochat.MainActivity" on path: DexPathList[[zip file "/data/app/e.gochat-1.apk"],nativeLibraryDirectories=[/data/app-lib/e.gochat-1, /vendor/lib, /system/lib]]
01-04 11:06:42.302: E/AndroidRuntime(1906): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
01-04 11:06:42.302: E/AndroidRuntime(1906): at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
01-04 11:06:42.302: E/AndroidRuntime(1906): at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
01-04 11:06:42.302: E/AndroidRuntime(1906): at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
01-04 11:06:42.302: E/AndroidRuntime(1906): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2093)
01-04 11:06:42.302: E/AndroidRuntime(1906): ... 11 more
01-04 11:07:06.772: I/Process(1906): Sending signal. PID: 1906 SIG: 9
This is my app Manifest XML
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="e.gochat"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="18" />
<permission
android:name="e.gochat.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="e.gochat.permission.C2D_MESSAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<application
android:name="e.gochat.Common"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="e.gochat.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="e.gochat.ChatActivity"
/>
<activity
android:name="e.gochat.SettingsActivity"
android:label="#string/title_activity_settings" />
<receiver
android:name="e.gochat.client.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="e.gochat" />
</intent-filter>
</receiver>
<provider
android:name="e.gochat.DataProvider"
android:authorities="e.gochat.provider"
android:exported="false">
</provider>
</application>
I'm not sure what's wrong here. I've added the .jar file in the java build path. And yet I'm getting this classnotfound exception. The app loads when I import the android.app.Application
I have solved this problem by disabling the instant run option of android studio.
To disable Instant Run Goto
File -> Settings
-> Build,Execution, Deployment -> Instant Run -> Uncheck the checkbox for instant run
I don't know for sure what is your package name, but if it is e.gochat do this.
Add package="e.gochat" to manifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="e.gochat"
.....
.....
>
On each activity declaration for android:name put a dot before activity name:
<activity
android:name=".MainActivity">
............
</activity>
<activity
android:name=".ChatActivity">
EDIT
After your edited I can see e.gochat is your package name.
Now you only need to remove e.gochat from each activity/provider/receiver name as I said in second part of my answer.
Android will add that for you.
Using Android Studio
After upgrading to Android Stuido 0.8.2, I had this problem. I tried a lot of things, including
Clean project
Clean project (gradle clean)
Invalidate Caches and Restart
De-qualify the Activity Name in AndroidManifest.xml (.MyActivity)
Nothing worked until I re-imported the entire project.
File -> Close Project -> Import Project... -> Choose the same project -> OK
This fixed it for me
Uninstalling the app in the device and running the project again fixed it for me.
The reason why this was affecting me was due to an incorrect path name in a layout file
<android.support.v4.app.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v4.app.view.ViewPager>
The correct absolute path of ViewPager is
android.support.v4.view.ViewPager
After correcting the path it worked. I did not have to prefix the activity name with a '.'.
For me, this was occurring on devices running < Android 5.0 because I didn't have multidex support enabled (this is, over 65k total methods incl. libs). Multidex is automatic and native on Android 5.0+ (specifically, devices using ART).
The problem was solved by removing MultiDexSupport from build.gradle file :
defaultConfig {
multiDexEnabled true // This line was causing above problem
}
Removing the MultiDexSupport solved the problem
This issue has multiple answers based on the different scenario.
I was getting the same error when using a library(.aar) in my Android Studio project.
The root cause in my case was that I missed to add a third party lib dependency in app's build.gradle file which was being used by the .aar file.
e.g:- The library(.aar) was using 'com.squareup.okhttp3:okhttp:3.4.1'. So I had to add
compile 'com.squareup.okhttp3:okhttp:3.4.1'
in the app's build.gradle. Hope it helps someone.
ANDROID STUDIO
In addittion to Kishor's answer:
The error occured on my small project when I enabled multiDexEnabled = true in the gradle defaultconfig.
Using the generated .apk file crashes on start of the app with the known error message.
For me it was solved when I built the .apk file via gradle (right side of android studio) -> "yourapp" -> Tasks- > install -> installDebug
Hope this helps someone with this strange error
I implemented a listener that was not available in the android version I was running yet and this led to the same error.
Example MainActivity:
// RecyclerView.OnScrollChangeListener is only available on API >= 23
public class MainActivity implements RecyclerView.OnScrollChangeListener
{
}
Running this activity on a device with API < 23 will result in this error as well...
If you tried other solitions and none of them work. Sometimes this error happen because some library use Java 8 features. To solve the problem, configure Android Gradle Plugin to support Java 8 by adding the following code to your build.gradle file
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
For me the issue occurred as I wasn't including the kotlin-android and kotlin-android-extensions plugins in my :app modules build.gradle.
E.g.
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-android-extensions'
}
Or if you're using the Kotlin DSL
plugins {
id("com.android.application")
kotlin("android")
kotlin("android.extensions")
}
dependencies {
implementation 'androidx.appcompat:appcompat:+'
implementation 'androidx.constraintlayout:constraintlayout:+'
}
Remove this line from Gradle