java.lang.RuntimeException: Unable to instantiate activity ComponentInfo - NFC access - java

I have seen a number of questions similar to this one, but they seem to be specific to the classes and packages that they use. I tried some of the solutions, but did not help me. I get the following error:
03-27 14:30:08.604: D/AndroidRuntime(8057): Shutting down VM
03-27 14:30:08.604: W/dalvikvm(8057): threadid=1: thread exiting with uncaught exception (group=0x41c02c80)
03-27 14:30:08.604: E/AndroidRuntime(8057): FATAL EXCEPTION: main
03-27 14:30:08.604: E/AndroidRuntime(8057): Process: org.nick.nfc.seaccess, PID: 8057
03-27 14:30:08.604: E/AndroidRuntime(8057): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{org.nick.nfc.seaccess/org.nick.nfc.seaccess.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "org.nick.nfc.seaccess.MainActivity" on path: DexPathList[[zip file "/system/framework/com.android.nfc_extras.jar", zip file
Any idea, how I should address it?
Here is the beginning of the main activity:
public class MainActivity extends Activity implements OnClickListener {
private static final String TAG = MainActivity.class.getSimpleName();
private Button gpInfoButton;
private Button emvInfoButton;
private Button walletInfoButton;
private TextView infoText;
private Terminal terminal;
private CardConnection seConn;
#Override
public void onCreate(Bundle savedInstanceState) {
...
Here is my activity tag from my manifest. I have seem sometimes folks add the full package name to the manifest. Shall I do this and see what happens?
<activity
android:name=".MainActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|s mallestScreenSize"
android:label="#string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
I found a link that states the issue may be with how I have edited an xml file, which holds certificates. I have pasted the file below; removed the certs. Do you see any issue with it?
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<!-- Applications granted NFCEE access on user builds
See packages/apps/Nfc/etc/sample_nfcee_access.xml for full documentation.
-->
<!-- Google wallet release signature -->
<signer android:signature="308205bd852e" />
<!-- Sequent Wallet signature -->
<signer android:signature="30820243badc1df9d"/>
<!-- android-se-access signature-->
<signer
android:signature="3082044cbd852e">
<package android:name="org.nic.nfc.seaccess"/>
</signer>
</resources>
Here is a view of the project workspace
I just saw something in the logs, which I wanted to add to this thread. Seems like the is a "-1", and "-2" next to the package name. Is that supposed to be there, or is that the cause of my issue?
Here are the log messages I am talking about:
03-27 22:55:10.884: E/AndroidRuntime(9436): Caused by: java.lang.ClassNotFoundException: Didn't find class "org.nick.nfc.seaccess.MainActivity" on path: DexPathList[[zip file "/system/framework /com.android.nfc_extras.jar", zip file "/data/app/org.nick.nfc.seaccess- 1.apk"],nativeLibraryDirectories=[/data/app-lib/org.nick.nfc.seaccess-1, /vendor/lib, /system/lib]]
03-27 22:58:02.104: E/AndroidRuntime(9880): Caused by: java.lang.ClassNotFoundException: Didn't find class "org.nick.nfc.seaccess.MainActivity" on path: DexPathList[[zip file "/system/framework /com.android.nfc_extras.jar", zip file "/data/app/org.nick.nfc.seaccess- 2.apk"],nativeLibraryDirectories=[/data/app-lib/org.nick.nfc.seaccess-2, /vendor/lib, /system/lib]]

From the trace: java.lang.ClassNotFoundException: Didn't find class "org.nick.nfc.seaccess.MainActivity"
This means the class org.nick.nfc.seaccess.MainActivity is undefined or can't be loaded.
Do you have a class org.nick.nfc.seaccess.MainActivity? What is the code? Does it have a default constructor? Is it declared in the manifest?

Related

ClassNotFoundException: Didn't find class "android.support.v4.content.FileProvider" after androidx migration

I'm trying to move to migrate to androidx. I used the migration tool in Android Studio. When I do this I get the following stacktrace when I run my app.
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.peerke.outdoorpuzzlegame.debug, PID: 10901
java.lang.RuntimeException: Unable to get provider android.support.v4.content.FileProvider: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.content.FileProvider" on path: DexPathList[[zip file "/data/app/com.peerke.outdoorpuzzlegame.debug-IBtFsngoLqc-cQb_hOO5wQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.peerke.outdoorpuzzlegame.debug-IBtFsngoLqc-cQb_hOO5wQ==/lib/x86, /system/lib]]
at android.app.ActivityThread.installProvider(ActivityThread.java:6376)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:5932)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5847)
at android.app.ActivityThread.access$1000(ActivityThread.java:198)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1637)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6649)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:826)
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.content.FileProvider" on path: DexPathList[[zip file "/data/app/com.peerke.outdoorpuzzlegame.debug-IBtFsngoLqc-cQb_hOO5wQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.peerke.outdoorpuzzlegame.debug-IBtFsngoLqc-cQb_hOO5wQ==/lib/x86, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:125)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.app.AppComponentFactory.instantiateProvider(AppComponentFactory.java:121)
at androidx.core.app.CoreComponentFactory.instantiateProvider(CoreComponentFactory.java:62)
at android.app.ActivityThread.installProvider(ActivityThread.java:6360)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:5932) 
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5847) 
at android.app.ActivityThread.access$1000(ActivityThread.java:198) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1637) 
at android.os.Handler.dispatchMessage(Handler.java:106) 
at android.os.Looper.loop(Looper.java:164) 
at android.app.ActivityThread.main(ActivityThread.java:6649) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:826) 
The exception is correct. android.support.v4.content.FileProvider doesn't exist in my app. But androidx.core.content.FileProvider is included in my app.
The big question is why does it want to load the old version of FileProvider?
Thanks to #CommonsWare
More explanation:
What to do, find the android.support.v4.FileProvider in your <provider> in AndroidManifest.xml.
Change it to androidx.core.content.FileProvider
In manifiest.xml file simply change this
<provider
android:name="android.support.v4.content.FileProvider"
.....
</provider>
To this one
<provider
android:name="androidx.core.content.FileProvider"
......
</provider>
Or Simply
Go to Refactor (Studio -> Menu -> Refactor)
Click the Migrate to AndroidX.
it's working.
why does it want to load the old version of FileProvider?
Based on the stack trace, perhaps you are still using the old package name in the <provider> element in the manifest.

Activity class not found even though the class appears in dex disassembly

I'm developing an Android app (let's call it AppName) in Unity 2017.3 Beta 1. I need a custom Activity to run some Java code on Startup. I have the code for the AppNameActivity in a separate project which uses gradle to package the Activity into the AppName.jar file which is then dropped into Unity's AppName/Assets/Plugins/Android folder, along with a custom AndroidManifest.xml which referencet it. I uses Unity's Build and Run feature (Build System: Gradle, Development Build).
When I start the app on my Android device, it crashes instantly. It seems as if the Activity class was missing, but on closer inspection, it is actually there.
Via adb logcat I can obtain this error:
V/ActivityThread(24831): Handling launch of ActivityRecord{2609126c token=android.os.BinderProxy#2101f035 {de.companyname.appname.rebuild/de.companyname.appname.rebuild.AppNameActivity}}
D/OpenGLRenderer(23986): Flushing caches (mode 0)
D/OpenGLRenderer(23986): Flushing caches (mode 0)
I/art (24831): Rejecting re-init on previously-failed class java.lang.Class<de.companyname.appname.rebuild.AppNameActivity>
D/AndroidRuntime(24831): Shutting down VM
E/AndroidRuntime(24831): FATAL EXCEPTION: main
E/AndroidRuntime(24831): Process: de.companyname.appname.rebuild, PID: 24831
E/AndroidRuntime(24831): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{de.companyname.appname.rebuild/de.companyname.appname.rebuild.AppNameActivity}: java.lang.ClassNotFoundException: Didn't find class "de.companyname.appname.rebuild.AppNameActivity" on path: DexPathList[[zip file "/data/app/de.companyname.appname.rebuild-2/base.apk"],nativeLibraryDirectories=[/data/app/de.companyname.appname.rebuild-2/lib/arm, /vendor/lib, /system/lib]]
E/AndroidRuntime(24831): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2381)
E/AndroidRuntime(24831): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2532)
E/AndroidRuntime(24831): at android.app.ActivityThread.access$900(ActivityThread.java:169)
E/AndroidRuntime(24831): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1421)
E/AndroidRuntime(24831): at android.os.Handler.dispatchMessage(Handler.java:111)
E/AndroidRuntime(24831): at android.os.Looper.loop(Looper.java:194)
E/AndroidRuntime(24831): at android.app.ActivityThread.main(ActivityThread.java:5562)
E/AndroidRuntime(24831): at java{de.companyname.appname.rebuild/de.companyname.appname.rebuild.AppNameActivity}.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(24831): at java.lang.reflect.Method.invoke(Method.java:372)
E/AndroidRuntime(24831): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:968)
E/AndroidRuntime(24831): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:763)
E/AndroidRuntime(24831): Caused by: java.lang.ClassNotFoundException: Didn't find class "de.companyname.appname.rebuild.AppNameActivity" on path: DexPathList[[zip file "/data/app/de.companyname.appname.rebuild-2/base.apk"],nativeLibraryDirectories=[/data/app/de.companyname.appname.rebuild-2/lib/arm, /vendor/lib, /system/lib]]
E/AndroidRuntime(24831): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
E/AndroidRuntime(24831): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
E/AndroidRuntime(24831): at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
E/AndroidRuntime(24831): at android.app.Instrumentation.newActivity(Instrumentation.java:1070)
E/AndroidRuntime(24831): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2371)
E/AndroidRuntime(24831): ... 10 more
E/AndroidRuntime(24831): Suppressed: java.lang.NoClassDefFoundError: de.companyname.appname.rebuild.AppNameActivity
E/AndroidRuntime(24831): at dalvik.system.DexFile.defineClassNative(Native Method)
E/AndroidRuntime(24831): at dalvik.system.DexFile.defineClass(DexFile.java:226)
E/AndroidRuntime(24831): at dalvik.system.DexFile.loadClassBinaryName(DexFile.java:219)
E/AndroidRuntime(24831): at dalvik.system.DexPathList.findClass(DexPathList.java:321)
E/AndroidRuntime(24831): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:54)
E/AndroidRuntime(24831): ... 14 more
E/AndroidRuntime(24831): Suppressed: java.lang.ClassNotFoundException: de.companyname.appname.rebuild.AppNameActivity
E/AndroidRuntime(24831): at java.lang.Class.classForName(Native Method)
E/AndroidRuntime(24831): at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
E/AndroidRuntime(24831): at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
E/AndroidRuntime(24831): at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
E/AndroidRuntime(24831): ... 13 more
E/AndroidRuntime(24831): Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
The relevant part of my AndroidManifest.xml:
<application android:theme="#style/UnityThemeSelector" android:icon="#drawable/app_icon" android:label="#string/app_name" android:isGame="false" android:banner="#drawable/app_banner">
<activity android:label="#string/app_name" android:screenOrientation="fullSensor" android:launchMode="singleTask" android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale|layoutDirection" android:name="de.companyname.appname.rebuild.AppNameActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data android:name="unityplayer.UnityActivity" android:value="true" />
</activity>
(...)
</application>
Here's the output of dexdump, executed on the Android device via adb shell with the argument /data/app/de.companyname.appname.rebuild-2/base.apk.
Processing './base.apk'...
Opened './base.apk', DEX version '035'
(...)
Class #69 -
Class descriptor : 'Lde/companyname/appname/rebuild/AppNameActivity;'
Access flags : 0x0001 (PUBLIC)
Superclass : 'Lde/companyname/appname/rebuild/UnityPlayerActivity;'
Interfaces -
Static fields -
#0 : (in Lde/companyname/appname/rebuild/AppNameActivity;)
name : 'ACTION_USB_PERMISSION'
type : 'Ljava/lang/String;'
access : 0x001a (PRIVATE STATIC FINAL)
#1 : (in Lde/companyname/appname/rebuild/AppNameActivity;)
name : 'TAG'
type : 'Ljava/lang/String;'
access : 0x001a (PRIVATE STATIC FINAL)
Instance fields -
#0 : (in Lde/companyname/appname/rebuild/AppNameActivity;)
name : 'mUsbManager'
type : 'Landroid/hardware/usb/UsbManager;'
access : 0x0002 (PRIVATE)
#1 : (in Lde/companyname/appname/rebuild/AppNameActivity;)
name : 'mUsbReceiver'
type : 'Landroid/content/BroadcastReceiver;'
access : 0x0012 (PRIVATE FINAL)
#2 : (in Lde/companyname/appname/rebuild/AppNameActivity;)
name : 'validProductNames'
type : 'Ljava/util/Collection;'
access : 0x0002 (PRIVATE)
Direct methods -
#0 : (in Lde/companyname/appname/rebuild/AppNameActivity;)
name : '<init>'
type : '()V'
access : 0x10001 (PUBLIC CONSTRUCTOR)
code -
registers : 4
ins : 1
outs : 2
insns size : 32 16-bit code units
catches : (none)
positions :
0x0000 line=27
0x0003 line=22
0x000a line=25
0x0018 line=28
0x001f line=29
locals :
0x0000 - 0x0020 reg=3 this Lde/companyname/appname/rebuild/AppNameActivity;
(...)
I also used the tool AndroidSdk/tools/bin/apkanalyzer dex packages ~/src/appname/UnityExport.apk to get a disassembly on my dev machin, which yields:
sh: 0: getcwd() failed: No such file or directory
P d 465 944 66105 <TOTAL>
P d 420 454 49362 com
(...)
C d 8 10 1067 de.companyname.appname.rebuild.AppNameActivity
M d 1 1 119 de.companyname.appname.rebuild.AppNameActivity <init>()
(...)
So I'm rather sure that the class de.companyname.appname.rebuild.AppNameActivity is present on the device.
Update:
I was worried about the package being mentioned twice in a row in the error log: {de.companyname.appname.rebuild/de.companyname.appname.rebuild.AppNameActivity} so I changed the value in the manifest from android:name="de.companyname.appname.rebuild.AppNameActivity" to android:name=".AppNameActivity". Still, I get exactly the same error message.
I found the solution to my own problem: I was missing a superclass.
When I tried to make a release build (before, I always tried the debug build), I got several error messages, including this line:
Warning: de.companyname.appname.rebuild.AppNameActivity: can't find superclass or interface de.companyname.appname.rebuild.UnityPlayerActivity
In fact, I had made a mistake while bundling AppName.jar, so that the superclass was missing. I'm still surprised about the rather unspecific runtime error from the AndroidRuntime which only mentioned AppNameActivity.
I rebuilt the jar and the release build and now this error is fixed, AppNameActivity is loaded and it's constructor executed (and then crashes during execution due to some other problems which are beyond the scope).
For a moment, I was still unsure about this whole thing because I looked at the old output of dexdump (which I quoted partially in my question) which confirmed the presence of UnityPlayerActivity. Upon closer inspection, I noticed that com.unity3d.player.UnityPlayerActivity was included, but the actual superclass was de.companyname.appname.rebuild.UnityPlayerActivity

ApplicationClass ClassNotFoundException

I'm using the application class , so I had to create the manifest file, as follows:
<application
android.name="com.moonae.android.common.ApplicationClass"
android.icon="#drawble/ic_launcher"
android.largeHeap="true"
....>
<activity..../>
I have to work normally without problems when testing , often the error occurred in the Google Play Store error report.
But the error report is posted on the Android version 4.4 , I even tested at 4.4 operate normally.
If the person experiencing this problem help me.
java.lang.RuntimeException: Unable to instantiate application com.moonae.android.common.ApplicationClass: java.lang.ClassNotFoundException: Didn't find class "com.culturelandnew.android.common.ApplicationClass" on path: DexPathList[[],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
at android.app.LoadedApk.makeApplication(LoadedApk.java:516)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4524)
at android.app.ActivityThread.access$1500(ActivityThread.java:163)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1317)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5335)
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:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.moonae.android.common.ApplicationClass" on path: DexPathList[[],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:67)
at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
at android.app.Instrumentation.newApplication(Instrumentation.java:993)
at android.app.LoadedApk.makeApplication(LoadedApk.java:511)
... 11 more
<application
android.name="com.moonae.android.common.ApplicationClass"
android.icon="#drawble/ic_launcher"
android.largeHeap="true"
....>
<activity..../>
is this a typo? i have not seen this before i mean android.name to android:name..btw
quick suggestion, remove your application tag, and use the eclipse gui side to search the application class and reference it.. mostly it references the it without package name included.. like this.. =>
<application
android:name="ApplicationClass"
android:icon="#drawble/ic_launcher"
android:largeHeap="true"
....>

Unable to instantiate application error which extends Application class

The below error occurs sometimes for some users.
I haven't seen it through android phones which I have for testing, but I got this crush via Google developer console.
[Error]
java.lang.RuntimeException: Unable to instantiate application com.***.***.MyApplication: java.lang.ClassNotFoundException: com.***.***.MyApplication
at android.app.LoadedApk.makeApplication(LoadedApk.java:501)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4253)
at android.app.ActivityThread.access$1400(ActivityThread.java:143)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1301)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4950)
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:997)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:764)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: com.***.***.MyApplication
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.Instrumentation.newApplication(Instrumentation.java:982)
at android.app.LoadedApk.makeApplication(LoadedApk.java:496)
... 11 more
[MyApplication.java]
public class MyApplication extends Application {
#Override
public void onCreate() {
super.onCreate();
...
}
#Override
public void onTerminate() {
super.onTerminate();
}
...
}
[manifest.xml]
...
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
...
<application
android:name="com.***.***.MyApplication"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
I've tried to find out to solve this problem.
I doubt it might be due to external SD card problem or 'public constructor'.
Because even I do not know how to reenact the situation, I can't be sure whether this is due to SD card or public constructor stuff.
I'm sure there's somebody who got this error and already know how to solve this.
Thus, please help me know what's wrong and how I can fix it.
Thanks.
add your class name in your manifest file. hope this solve your problem
<application android:icon="#drawable/icon" android:label="#string/app_name"
android:name=".MyApplication">
........
for further reading , how to extends Application class, read here.

Activity is not assignable to Activity

I have read several posts for the last couple of days and i can not seem to figure out what my issue is. I have checked the Activity names and they are the same. I have also checked my manifest and I have the . in front of the activities as well.
Here is my logcat file:
02-23 16:48:22.438 1508-1508/com.pctoolman.planme.app E/AndroidRuntime﹕ FATAL
EXCEPTION: main
java.lang.RuntimeException: Unable to instantiate activity
ComponentInfo{com.pctoolman.planme.app/com.pctoolman.planme.app.PlanMeMainActivity}:
java.lang.ClassCastException: com.pctoolman.planme.app.PlanMeMainActivity cannot be
cast
to android.app.Activity
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2137)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassCastException: com.pctoolman.planme.app.PlanMeMainActivity
cannot
be cast to android.app.Activity
at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2128)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.pctoolman.planme.app" >
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.pctoolman.planme.app.PlanMeMainActivity"
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="com.pctoolman.planme.app.NewEventSetupActivity"
android:label="#string/setup">
</activity>
</application>
PlanMeMainFragment.java
package com.pctoolman.planme.app;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
public class PlanMeMainFragment extends Fragment {
private Button mNewButton, mExistingButton;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRetainInstance(true);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.planme_main_fragment, parent, false);
mNewButton = (Button)v.findViewById(R.id.new_event_button);
mNewButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent myIntent = new Intent(getActivity(), NewEventSetupActivity.class);
getActivity().startActivity(myIntent);
}
});
return v;
}
}
PlanMeMainActivity.java
package com.pctoolman.planme.app;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
public class PlanMeMainActivity extends Fragment {
public Fragment createFragment() {
return new PlanMeMainFragment();
}
}
Change this line
public class PlanMeMainActivity extends Fragment {
to
public class PlanMeMainActivity extends FragmentActivity {
Here you can find all that you need to know about Activities and even more. Cheers
Where are you wrong?
<activity
android:name="com.pctoolman.planme.app.PlanMeMainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Why are you wrong?
The mistake is that you added the Fragment in the Manifest as
Activity. However Fragments are not activities
What you should do?
You should add the fragment in an activity and then define that activity in the
Manifest
Your PlanMeMainActivity isn't an Activity; it's a Fragment. Your activity needs to be an activity, and you can then add fragments to it.
Clean Project solved this error. The root cause of the error in my case was different, but I got the same "Activity is not assignable to Activity" error.
I faced this problem after copying existing (perfectly working) Android Project to create a new one.
After copying the project, the AppCompatActivity was not recognized causing all the activities in the Android Manifest file to show the error "activity-is-not-assignable-to-activity".
Which was solved by cleaning the project.
Your PlanMainActivity extends a Fragment. A fragment cannot be cast to an activity
Finally, I find out the solution is add following line in your dependencies:
compile 'com.android.support:support-v4:23.2.0'
just delete ".gradle" folder of your project
and press sync button .
its solved my problem
In my case the error was occurred by just installed plugin in Android Studio. So check your plugins and uninstall odd ones.
My problem was solved by Invalidating Caches and Restarting after having Cleaned the Project.

Categories