i am beginner , so do not understand how i fix this problem. My XML code is ok. but when run emulator then click on app its say " unfortunately.... has stopped "
Error msg :
java.lang.RuntimeException: Unable to instantiate activity
ComponentInfo{com.example.imran.justjava/com.example.imran.justjava.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.example.imran.justjava.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.imran.justjava-2/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2209)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.imran.justjava.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.imran.justjava-2/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at android.app.Instrumentation.newActivity(Instrumentation.java:1065)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2199)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Suppressed: java.lang.ClassNotFoundException: com.example.imran.justjava.MainActivity
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
Here is my java code
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;
import com.example.imran.justjava.R;
/**
* This app displays an order form to order coffee.
*/
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
/**
* This method is called when the order button is clicked.
*/
public void submitOrder(View view) {
display(1);
}
/**
* This method displays the given quantity value on the screen.
*/
private void display(int number) {
TextView quantityTextView = (TextView) findViewById(
R.id.quantity_text_view);
quantityTextView.setText("" + number);
}
}
Here is Xml Code
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:text="quantity"
android:textAllCaps="true"
android:padding="16dp"
android:textSize="16sp"
/>
<TextView
android:id="#+id/quantity_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:padding="16dp"
android:textSize="16sp"
android:textColor="#android:color/black"
/>
<Button
android:id="#+id/order_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="order"
android:onClick="submitOrder"
/>
</LinearLayout>
AndroidManifast.xml code
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.imran.justjava" >
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
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 had the same issue in latest AndroidStudio. Everything was compiling and running fine in later versions of Android.
However, as soon as I ran the application on an emulator with Android 4.x, it would crash with the same ClassNotFoundException as mentioned in this post.
After trying a lot of solutions suggested online, it turns out the issue was related to multiDexEnabled being set to true. I could have sworn this was working fine before. Disabling the multidex solved the issue.
Following the guide at https://developer.android.com/studio/build/multidex.html#mdex-gradle should probably fix it as well, although I have not tried that out myself.
What is your logcat throws
Caused by: java.lang.ClassNotFoundException: Didn't find class
"com.example.imran.justjava.MainActivity"
ClassNotFoundException : ClassNotFoundException occurs when class loader could not find the required class in class path . So , basically you should check your class path and add the class in the classpath.
I guess your activity in manifest is not correct.
Post your manifest.xml .
Have a look here
https://developer.android.com/intl/es/samples/BasicContactables/AndroidManifest.html
Example
<activity
android:name=".MainActivity"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
Error:
java.lang.RuntimeException: Unable to instantiate activity
ComponentInfo{com.example.imran.justjava/com.example.imran.justjava.MainActivity}:
java.lang.ClassNotFoundException: Didn't find class
I have also faced this issue.
Your MainActivity.java is excluded from compile, so this class isn't included in .apk
Remove following line from excludeFromCompile section of the .idea/compiler.xml file
<file url="file://$PROJECT_DIR$/src/com/example/imran/justjava/MainActivity.java" />
I think error is in your Manifest file.
first ensure that you've declared the MainActivity correctly in AndroidManifest.xml
<activity android:name=".MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Related
App is crashing on restart of app after tablet/mobile orientation change,
I m going to develop an application in landscape mode only, and I have made a layout in layout-land with name acitivty_main and there is no any portrait layout in my application and no any layout folder as well, I have also added screenOrientation="landscape" in manifest activity.
Activity Code Following:
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
}
Manifest.xml code following:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.yasir.sample">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity"
android:screenOrientation="landscape">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Project Structure:
FATAL EXCEPTION: main
Process: com.example.yasir.sample, PID: 12611
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.example.yasir.sample/com.example.yasir.sample.MainActivity}:
android.content.res.Resources$NotFoundException: Resource ID #0x7f04001b
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3151)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3261)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:5205)
at android.app.ActivityThread.access$1100(ActivityThread.java:219)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1741)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6939)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f04001b
at android.content.res.Resources.getValue(Resources.java:2495)
at android.content.res.Resources.loadXmlResourceParser(Resources.java:4236)
at android.content.res.Resources.getLayout(Resources.java:2311)
at android.view.LayoutInflater.inflate(LayoutInflater.java:413)
at android.view.LayoutInflater.inflate(LayoutInflater.java:366)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:289)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at com.example.yasir.sample.MainActivity.onCreate(MainActivity.java:12)
at android.app.Activity.performCreate(Activity.java:6609)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1134)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3104)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3261)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:5205)
at android.app.ActivityThread.access$1100(ActivityThread.java:219)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1741)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6939)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
Resources$NotFoundException
This exception is thrown by the resource APIs when a requested
resource can not be found
FYI
Remove
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
Add android:configChanges="orientation|screenLayout" in Manifest section .
Finally
<activity android:name=".MainActivity"
android:screenOrientation="landscape"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout">
Then Clean and Rebuild your project .
https://androidresearch.wordpress.com/2013/05/10/dealing-with-asynctask-and-screen-orientation/
This link will explain how to prevent crashes from AsyncTask and Screen Orentation
I have made functional changes in my ionic app and tested in browser by ionic serve. Everything went fine and proceeded for ionic build. So it returned me below error.
I:\myprojects\fizion>ionic package info 30
id │ 30
status │ FAILED
platform │ android
mode │ debug
started │ Jul 30th, 2017 10:32:28
output:
ANDROID_HOME=/opt/android-sdk
JAVA_HOME=/usr/lib/jvm/java-8-oracle
Error: Could not find gradle wrapper within Android SDK. Might need to update your Android SDK.
Looked here: /opt/android-sdk/tools/templates/gradle/wrapper
I am not sure whose Android SDK it is suggesting to upgrade. Mine or ionic cloud's ?
Ok, I tried to upgrade my android studio SDK and then other problem started. Then I have issued below command to propogate the new changes to the android.
cordova prepare android
I have built the .apk file and launched in phone. It crashed, so tried in emulator and got the below error.
--------- beginning of crash
07-30 12:18:53.350 3040-3040/com.ionicframework.fizion233539 E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.ionicframework.fizion233539, PID: 3040
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.ionicframework.fizion233539/com.ionicframework.fizion233539.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.ionicframework.fizion233539.MainActivity" on path: DexPathList[[zip file "/data/app/com.ionicframework.fizion233539-1/base.apk"],nativeLibraryDirectories=[/data/app/com.ionicframework.fizion233539-1/lib/x86_64, /vendor/lib64, /system/lib64]]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2327)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.ionicframework.fizion233539.MainActivity" on path: DexPathList[[zip file "/data/app/com.ionicframework.fizion233539-1/base.apk"],nativeLibraryDirectories=[/data/app/com.ionicframework.fizion233539-1/lib/x86_64, /vendor/lib64, /system/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at android.app.Instrumentation.newActivity(Instrumentation.java:1067)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2317)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Suppressed: java.lang.NoClassDefFoundError: com.ionicframework.fizion233539.MainActivity
at dalvik.system.DexFile.defineClassNative(Native Method)
at dalvik.system.DexFile.defineClass(DexFile.java:226)
at dalvik.system.DexFile.loadClassBinaryName(DexFile.java:219)
at dalvik.system.DexPathList.findClass(DexPathList.java:338)
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:54)
... 13 more
Suppressed: java.lang.ClassNotFoundException: com.ionicframework.fizion233539.MainActivity
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 12 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available
07-30 12:18:53.352 1584-1596/system_process W/ActivityManager: Force finishing activity com.ionicframework.fizion233539/.MainActivity
my manifest file:
<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="1" android:versionName="0.0.1" package="com.ionicframework.fizion233539" xmlns:android="http://schemas.android.com/apk/res/android">
<supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application android:hardwareAccelerated="true" android:icon="#drawable/icon" android:label="#string/app_name" android:supportsRtl="true">
<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="#string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="#android:style/Theme.DeviceDefault.NoActionBar" android:windowSoftInputMode="adjustResize">
<intent-filter android:label="#string/launcher_name">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:host="https://hs7pj.app.goo.gl/" android:scheme="https" />
</intent-filter>
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:host="fizion-f4286.firebaseapp.com" android:path="/__/auth/callback" android:scheme="https" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="23" />
<uses-feature android:name="android.hardware.location.gps" />
</manifest>
I have been going through many SO posts and tried many but nothing worked out.
I am happy to share my android studio screenshots for configurations. I am sure this is due to upgrade of android studio but where to crack it.
Could someone guide me I am blocked.
My android studio was showing me warning mentioned in the below post. So I ignored it. But that is the culprit and fixed the issue.
Android, IntelliJ Idea, changing module type
Using these configurations I did add sugar orm to my project, but my application stopped unfortunately by this error :
FATAL EXCEPTION: main
Process: gigacycle.geoaudiotag, PID: 22760
java.lang.RuntimeException: Unable to instantiate application com.orm.SugarApp: java.lang.ClassNotFoundException: Didn't find class "com.orm.SugarApp" on path: DexPathList[[zip file "/data/app/gigacycle.geoaudiotag-1/base.apk"],nativeLibraryDirectories=[/data/app/gigacycle.geoaudiotag-1/lib/arm, /vendor/lib, /system/lib]]
at android.app.LoadedApk.makeApplication(LoadedApk.java:676)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6289)
at android.app.ActivityThread.access$1800(ActivityThread.java:221)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1860)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7224)
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.ClassNotFoundException: Didn't find class "com.orm.SugarApp" on path: DexPathList[[zip file "/data/app/gigacycle.geoaudiotag-1/base.apk"],nativeLibraryDirectories=[/data/app/gigacycle.geoaudiotag-1/lib/arm, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at android.app.Instrumentation.newApplication(Instrumentation.java:1004)
at android.app.LoadedApk.makeApplication(LoadedApk.java:666)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6289)
at android.app.ActivityThread.access$1800(ActivityThread.java:221)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1860)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7224)
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)
Suppressed: java.lang.ClassNotFoundException: com.orm.SugarApp
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 12 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available
This is my Manifest :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="gigacycle.geoaudiotag">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme"
android:name="com.orm.SugarApp">
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="#string/google_maps_key" />
<meta-data android:name="DATABASE" android:value="geoaudiotagdb.db" />
<meta-data android:name="VERSION" android:value="2" />
<meta-data android:name="QUERY_LOG" android:value="true" />
<meta-data android:name="DOMAIN_PACKAGE_NAME" android:value="gigacycle.geoaudiotag"/>
<activity
android:name="gigacycle.geoaudiotag.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>
</application>
</manifest>
also this line is compiling successfully!
compile 'com.github.satyan:sugar:1.4'
I don't know why this fatal error occurred? where is my mistake?
Sync gradle and build.
Just download the package does not generate com.orm.SugarApp. Gradle sync will generate the class and before syncing, it appears as lint error in AndroidManifest.
Unfortunately this cannot be captured as compiler error and results in runtime error as you get.
I am working with the new DirectBoot feature in Android 7.0 and I am trying to determine when the phone is still locked after a restart and in Direct Boot mode. To do this, I have implemented a BroadcastReceiver which I defined in the Manifest.
My understanding is that when a phone is restarted, it sends out an ACTION_LOCKED_BOOT_COMPLETED broadcast when it finishes booting but prior to the user entering their PIN. When the PIN is entered and phone becomes unlocked, an ACTION_BOOT_COMPLETED broadcast is sent. My Receiver works fine if I define its intent-filter to be ACTION_BOOT_COMPLETED, but as soon as I add LOCKED_BOOT_COMPLETED, I get Fatal error messages like this upon restarting the phone saying it couldn't instantiate my receiver:
01-06 07:25:30.917 3872-3872/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.nougatencryptiontest, PID: 3872
java.lang.RuntimeException: Unable to instantiate receiver com.example.nougatencryptiontest.MyReceiver: java.lang.ClassNotFoundException: Didn't find class "com.example.nougatencryptiontest.MyReceiver" on path: DexPathList[[zip file "/data/app/com.example.nougatencryptiontest-1/base.apk"],nativeLibraryDirectories=[/data/app/com.example.nougatencryptiontest-1/lib/arm64, /system/lib64, /vendor/lib64]]
at android.app.ActivityThread.handleReceiver(ActivityThread.java:3021)
at android.app.ActivityThread.-wrap18(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1561)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.nougatencryptiontest.MyReceiver" on path: DexPathList[[zip file "/data/app/com.example.nougatencryptiontest-1/base.apk"],nativeLibraryDirectories=[/data/app/com.example.nougatencryptiontest-1/lib/arm64, /system/lib64, /vendor/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.app.ActivityThread.handleReceiver(ActivityThread.java:3016)
at android.app.ActivityThread.-wrap18(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1561)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
I'm not sure why this DexPathList issue occurs only when I change my Receiver's intent-filter from BOOT_COMPLETED to LOCKED_BOOT_COMPLETED. Below is my Manifest that does not work (however, if I change intent-filter to just be BOOT_COMPLETED, application doesn't crash and receiver works perfectly fine!):
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.nougatencryptiontest">
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<application
android:allowBackup="true"
android:directBootAware="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<receiver android:name=".MyReceiver"
android:exported="true"
android:directBootAware="true">
<!-- Listening the BOOT_COMPLETED action for legacy pre-N devices -->
<intent-filter>
<action android:name="android.intent.action.LOCKED_BOOT_COMPLETED" />
</intent-filter>
</receiver>
<activity android:name=".MainActivity"
android:directBootAware="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Any advice or pointers would be greatly appreciated.
I know that there are problems like this before. I have tried some of the solution given from the thread but it did not seem to solve the error for my application
This is my android.manifest file for the second activity
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".RevGPAActivity"
android:label="#string/title_activity_rev_gpa">
<intent-filter>
<action android:name="com.example.user.testapp.RevGPAActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<!-- ATTENTION: This was auto-generated to add Google Play services to your project for
App Indexing. See https://g.co/AppIndexing/AndroidStudio for more information. -->
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
</application>
And here is my MainActivity
private GoogleApiClient client;
Button start_rev_gpa;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
//Start Rev GPA
startRevGPA();
}
public void startRevGPA(){
start_rev_gpa = (Button)findViewById(R.id.startRevGPA);
start_rev_gpa.setOnClickListener(
new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent("com.example.user.testapp.RevGPAActivity");
startActivity(intent);
}
}
);
}
I did not do anything on the xml file like android:onClick or anything. The app hangs for about 3 seconds then it stopped working
Logcat
FATAL EXCEPTION: main
Process: com.example.user.testapp, PID: 29051
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.user.testapp/com.example.user.testapp.RevGPAActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:151)
at android.support.v7.app.ActionBarActivityDelegateBase.onCreate(ActionBarActivityDelegateBase.java:138)
at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:123)
at com.example.user.testapp.RevGPAActivity.onCreate(RevGPAActivity.java:10)
at android.app.Activity.performCreate(Activity.java:5937)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Solved my own problem. If someone stumbled on the same error, the target activity should be extending Activity not ActionBarActivity
You need to use a Theme.AppCompat theme (or descendant) with this activity
As you see in log file: You need to use a Theme.AppCompat theme (or descendant) with this activity could you check `#style/AppTheme" in style.xml of your project, this style need have parent="#style/Theme.AppCompat" or descendant ò