I've created an app widget that has the following classes and xml files:
AFBWidget.java
WidgetConfig.java (Configuration screen for users to input something into a textfield that shows up in the widget layout)
widget.xml (the layout of the actual widget)
widgetconfig.xml (same as widgetconfig.java ((except it is the actual layout)))
widget_stuff.xml (the android appwidget provider)
Here is my Manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.awesomefilebuilderwidget"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<receiver android:name=".AFBWidget" android:label="#string/app_name">
<intent-filter>
<action android:name="android.appwidet.action.APPWIDGET_UPDATE"/>
</intent-filter>
<meta-data android:name="android.appwidget.provider"
android:resource="#xml/widget_stuff"/>
</receiver>
<activity android:name=".WidgetConfig" android:label="#string/app_name">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE"/>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".widget" 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>
Originally, I didn't have the .widget activity in there and I didn't have the
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
either, so I got the error "No laucher activity found!". So to fix that, I added the launcher to my appwidget config and it fixed the error but then the widget would stop working and force close on the emulator.
My issue is that I don't know what activity to put the launcher on to make the widget work without crashing.
New Errors:
10-06 08:58:29.448: D/AndroidRuntime(6994): Shutting down VM
10-06 08:58:29.448: W/dalvikvm(6994): threadid=1: thread exiting with uncaught exception (group=0x4001d5a0)
10-06 08:58:29.458: E/AndroidRuntime(6994): FATAL EXCEPTION: main
10-06 08:58:29.458: E/AndroidRuntime(6994): java.lang.RuntimeException: Unable to instantiate receiver com.example.awesomefilebuilderwidget.AFBWidget: java.lang.ClassNotFoundException: com.example.awesomefilebuilderwidget.AFBWidget in loader dalvik.system.PathClassLoader[/data/app/com.example.awesomefilebuilderwidget-1.apk]
10-06 08:58:29.458: E/AndroidRuntime(6994): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2012)
10-06 08:58:29.458: E/AndroidRuntime(6994): at android.app.ActivityThread.access$2400(ActivityThread.java:135)
10-06 08:58:29.458: E/AndroidRuntime(6994): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1101)
10-06 08:58:29.458: E/AndroidRuntime(6994): at android.os.Handler.dispatchMessage(Handler.java:99)
10-06 08:58:29.458: E/AndroidRuntime(6994): at android.os.Looper.loop(Looper.java:150)
10-06 08:58:29.458: E/AndroidRuntime(6994): at android.app.ActivityThread.main(ActivityThread.java:4333)
10-06 08:58:29.458: E/AndroidRuntime(6994): at java.lang.reflect.Method.invokeNative(Native Method)
10-06 08:58:29.458: E/AndroidRuntime(6994): at java.lang.reflect.Method.invoke(Method.java:507)
10-06 08:58:29.458: E/AndroidRuntime(6994): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
10-06 08:58:29.458: E/AndroidRuntime(6994): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
10-06 08:58:29.458: E/AndroidRuntime(6994): at dalvik.system.NativeStart.main(Native Method)
10-06 08:58:29.458: E/AndroidRuntime(6994): Caused by: java.lang.ClassNotFoundException: com.example.awesomefilebuilderwidget.AFBWidget in loader dalvik.system.PathClassLoader[/data/app/com.example.awesomefilebuilderwidget-1.apk]
10-06 08:58:29.458: E/AndroidRuntime(6994): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
10-06 08:58:29.458: E/AndroidRuntime(6994): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
10-06 08:58:29.458: E/AndroidRuntime(6994): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
10-06 08:58:29.458: E/AndroidRuntime(6994): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2003)
10-06 08:58:29.458: E/AndroidRuntime(6994): ... 10 more
10-06 08:58:36.535: W/dalvikvm(7066): threadid=1: thread exiting with uncaught exception (group=0x4001d5a0)
I FINALLY FIXED IT AFTER 3 DAYS! Ok, so it was indeed because my two java classes were in a default package. So to fix that, since my classes were being accessed via a different package, I created a new package that was my app (com.example.awesomefilebuilderwidget) and then moved the classes into there and now it works with no problemos! :DD Thanks for all you've done I really do apperciate it! – user1628978
If you want to create widget only without any, lets call it, "main" activity, there is no need to declare intent and category filters for your configuration activity. You only need to specify intent filter for action android.appwidget.action.APPWIDGET_CONFIGURE. This activity will be lauched when user adds widget to home screen. You also need to declate this activity inside your appwidget-provider xml file with following attribute android:configure.
So in your case manifest should look something like this:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.awesomefilebuilderwidget"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<receiver android:name=".AFBWidget" android:label="#string/app_name">
<intent-filter>
<action android:name="android.appwidet.action.APPWIDGET_UPDATE"/>
</intent-filter>
<meta-data android:name="android.appwidget.provider"
android:resource="#xml/widget_stuff"/>
</receiver>
<activity android:name=".WidgetConfig" android:label="#string/app_name">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE"/>
</intent-filter>
</activity>
</application>
</manifest>
And in your widget_stuff.xml:
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
//put your config data here
android:configure="com.example.awesomefilebuilderwidget.WidgetConfig"
</appwidget-provider>
Related
please my app crashes whenever i click the navigation item to start activity. i Have tried all the solutions from similar questions in the last 6 hours to no avail. that includes registering the activity in manifest, changing intent (this,menu_profile.class); to (mainactivity.this, menu_profile.class); to `(getApplicationContext(), menu_profile.class);. googling permission (13) error to brought no solution.
snippet
else if (itemId == R.id.third) {
Intent intent = new Intent(getApplicationContext(), Menu_Profile.class);
startActivity(intent);
}
manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.majesty.adesanmi.viewpager_nav">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
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=".Menu_Profile"
android:label="DestinationActivity"/>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</application>
</manifest>
Logcat error
06-16 09:46:56.913 2889-2889/? E/Trace: error opening trace file: Permission denied (13)
06-16 09:46:56.983 2889-2889/com.majesty.adesanmi.viewpager_nav E/dalvikvm: Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method android.support.v7.widget.AppCompatImageHelper.hasOverlappingRendering
06-16 09:47:41.673 2889-2889/com.majesty.adesanmi.viewpager_nav E/AndroidRuntime: FATAL EXCEPTION: main
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.majesty.adesanmi.viewpager_nav/com.majesty.adesanmi.viewpager_nav.Menu_About}; have you declared this activity in your AndroidManifest.xml?
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1541)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1416)
at android.app.Activity.startActivityForResult(Activity.java:3351)
at android.support.v4.app.BaseFragmentActivityJB.startActivityForResult(BaseFragmentActivityJB.java:50)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:79)
at android.app.Activity.startActivityForResult(Activity.java:3312)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:859)
at android.app.Activity.startActivity(Activity.java:3522)
at android.app.Activity.startActivity(Activity.java:3490)
at com.majesty.adesanmi.viewpager_nav.MainActivity$2.onNavigationItemSelected(MainActivity.java:157)
at android.support.design.widget.NavigationView$1.onMenuItemSelected(NavigationView.java:156)
at android.support.v7.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:822)
at android.support.v7.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:156)
at android.support.v7.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:969)
at android.support.design.internal.NavigationMenuPresenter$1.onClick(NavigationMenuPresenter.java:342)
at android.view.View.performClick(View.java:4084)
at android.view.View$PerformClick.run(View.java:16966)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
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:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
just remove intent filter from your menu profilr activity this from your Manifist file or replace this
<?xml version="1.0" encoding="utf-8"?>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
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=".Menu_Profile"
android:label="DestinationActivity"/>
</application>
Hi I am new to android and I have created 2 projects.
Now I want to call an activity in the second project from the first project upon a button click.
The 1st project only handles login screen and when I click on the login button I need to call an activity which is present in the second project.
I searched the net but didn't find any tutorials which I understood properly.
Hi I found the following error.
01-30 08:36:47.230: E/dalvikvm(3408): Could not find class 'com.androidhive.googleplacesandmaps.MainActivity', referenced from method org.fluturasymphony.recommendation.LoginActivity$DownloadWebPageTask.doInBackground
01-30 08:36:52.587: E/AndroidRuntime(3408): FATAL EXCEPTION: AsyncTask #1
01-30 08:36:52.587: E/AndroidRuntime(3408): java.lang.RuntimeException: An error occured while executing doInBackground()
01-30 08:36:52.587: E/AndroidRuntime(3408): at android.os.AsyncTask$3.done(AsyncTask.java:299)
01-30 08:36:52.587: E/AndroidRuntime(3408): at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
01-30 08:36:52.587: E/AndroidRuntime(3408): at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
01-30 08:36:52.587: E/AndroidRuntime(3408): at java.util.concurrent.FutureTask.run(FutureTask.java:239)
01-30 08:36:52.587: E/AndroidRuntime(3408): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
01-30 08:36:52.587: E/AndroidRuntime(3408): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
01-30 08:36:52.587: E/AndroidRuntime(3408): at java.lang.Thread.run(Thread.java:856)
01-30 08:36:52.587: E/AndroidRuntime(3408): Caused by: java.lang.NoClassDefFoundError: com.androidhive.googleplacesandmaps.MainActivity
01-30 08:36:52.587: E/AndroidRuntime(3408): at org.fluturasymphony.recommendation.LoginActivity$DownloadWebPageTask.doInBackground(LoginActivity.java:69)
01-30 08:36:52.587: E/AndroidRuntime(3408): at org.fluturasymphony.recommendation.LoginActivity$DownloadWebPageTask.doInBackground(LoginActivity.java:1)
01-30 08:36:52.587: E/AndroidRuntime(3408): at android.os.AsyncTask$2.call(AsyncTask.java:287)
01-30 08:36:52.587: E/AndroidRuntime(3408): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
01-30 08:36:52.587: E/AndroidRuntime(3408): ... 3 more
I have declared the manifest as this.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.fluturasymphony.recommendation"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="9"
android:targetSdkVersion="11" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<application android:icon="#drawable/ic_launcher" android:label="#string/app_name">
<activity android:label="#string/app_name" 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="org.achartengine.GraphicalActivity" />
<activity android:name=".CategoryWiseSalesChartActivity" />
<activity android:name=".ProductWiseSalesChartActivity" />
<activity android:name="com.androidhive.googleplacesandmaps.MainActivity"/>
<activity android:label="#string/home_screen" android:name=".HomeActivity" android:configChanges="orientation">
</activity>
<activity android:label="#string/store_screen" android:name=".StoreActivity" android:configChanges="orientation">
</activity>
<activity android:label="#string/store_list_screen" android:name=".StoreListActivity" android:configChanges="orientation">
</activity>
<activity android:label="#string/location_screen" android:name=".StoreMapActivity" android:configChanges="orientation">
</activity>
<activity android:label="#string/recommended_products_list_screen" android:name=".RecommendedProductsListActivity" android:configChanges="orientation">
</activity>
<activity android:label="#string/category_wise_sales_screen" android:name=".CategoryWiseSalesActivity" android:configChanges="orientation">
</activity>
<activity android:label="#string/product_wise_sales_screen" android:name=".ProductWiseSalesActivity" android:configChanges="orientation">
</activity>
<uses-library android:name="com.google.android.maps" />
</application>
</manifest>
And I am calling the activity in the 2nd class like this.
Intent loginintent = new Intent("com.androidhive.googleplacesandmaps.MainActivity");
startActivity(loginintent);
Is this right??
According to Android you can handle this by making the project Library and then Define it in the manifest file and call it in what ever manner you want
for an explanation i did this as per my requirement
the activity you want to call on Button click Define it in the Manifest with its full package name and then when you call it on button click the activity of the new project will trigger
the sample to do this is following
in the manifest file of your 1st project define some thing like this
<activity
android:name="packagefull.activityname"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen">
</activity>
in the package name define the full path of the the activity you want to call and after the package name give the name of the activity
hope this will work for you as this worked perfect for me
Use this:
Intent i = new Intent(Intent.ACTION_MAIN);
i.setComponent(new ComponentName("app package name", "app launch activity's classname"));
i.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(i);
This is really not a good way for developing any application. But still if you want to achieve this , you will have to declare an Intent Filter for the target activity in that application's Manifest file and use it as implicit intent from your login activity.
Inside project A's Manifest:
<activity android:name="com.example.android.TargetActivity">
<intent-filter>
<action android:name="com.someone.wants.to.call.me"></action>
</intent-filter>
</activity>
Inside project B's Activity:
Intent intent = new Intent("com.someone.wants.to.call.me");
startActivity(intent);
in the map project's AndroidManifest file add your custom intent filter
<!-- add custom action -->
<activity android:name="MapActivity"
android:label="#string/mapLabel"
>
<intent-filter>
<action android:name="com.example.map.show" />
</intent-filter>
</activity>
from the login button call this activity like this:
Intent intent = new Intent("com.example.map.show");
startActivity(intent);
You should be using one project for each application. If you want to split up your login from the rest of your application you could use different packages. Unless I am misunderstanding what you mean by "project"?
I have built an application for a large multicultural festival in my city that kicks off on Saturday. I've tweaked a lot of bugs in the iPhone version and we are waiting for Apple to approve it. I have taken that perfected version as the basis for the Android version.
The Android version looks and works great. I can run it on my Samsung Galaxy S II by either "Run as Android Application" in Eclipse or by uploading it to a server and downloading it into the phone. I can also email the app to myself and it works, too. I submitted it to the Google Play store and once it got into the wild (this is advertised on billboards, buses, everywhere) it crashes the minute it is opened.
I'm not really sure how to troubleshoot this when it works fine on the device before publication. I read about how it has to do with the MainActivity activity name, but everything looks like it lines up.
Error 1 [ClassNotFoundException in PathClassLoader.findClass()]:
java.lang.RuntimeException: Unable to instantiate activity
ComponentInfo{com.honestapi.folk2011/com.honestapi.folk2011.Folklorama}:
java.lang.ClassNotFoundException: com.honestapi.folk2011.Folklorama in loader
dalvik.system.PathClassLoader[/data/app/com.honestapi.folk2011-1.apk]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1660)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1752)
at android.app.ActivityThread.access$1500(ActivityThread.java:123)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:993)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:126)
at android.app.ActivityThread.main(ActivityThread.java:3997)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:491)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: com.honestapi.folk2011.Folklorama in loader dalvik.system.PathClassLoader[/data/app/com.honestapi.folk2011-1.apk]
at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:251)
at java.lang.ClassLoader.loadClass(ClassLoader.java:548)
at java.lang.ClassLoader.loadClass(ClassLoader.java:508)
at android.app.Instrumentation.newActivity(Instrumentation.java:1022)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
Error 2 [ClassNotFoundException in BaseDexClassLoader.findClass()]:
java.lang.RuntimeException: Unable to instantiate activity
ComponentInfo{com.honestapi.folk2011/com.honestapi.folk2011.Folklorama}:
java.lang.ClassNotFoundException: com.honestapi.folk2011.Folklorama
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1894)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1995)
at android.app.ActivityThread.access$600(ActivityThread.java:128)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4514)
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:980)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:747)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: com.honestapi.folk2011.Folklorama
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.newActivity(Instrumentation.java:1027)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1885)
Any help would be greatly appreciated! I am in quite the pickle.
Edit - Here is the AndroidManifest.xml from the bin folder
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="15" />
<supports-screens android:largeScreens="true" android:normalScreens="true" android:smallScreens="true" android:resizeable="false" android:anyDensity="true" />
<uses-permission android:name="android.permission.VIBRATE" />
<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_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.BROADCAST_STICKY" />
<uses-permission android:name="android.permission.CAMERA" />
<application android:icon="#drawable/ic_launcher" android:label="#string/app_name" android:theme="#style/AppTheme">
<activity android:name=".MainActivity" 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>
<activity android:name="com.google.zxing.client.android.CaptureActivity" android:screenOrientation="landscape" android:configChanges="orientation|keyboardHidden" android:theme="#android:style/Theme.NoTitleBar.Fullscreen" android:windowSoftInputMode="stateAlwaysHidden">
<intent-filter>
<action android:name="com.phonegap.plugins.barcodescanner.SCAN"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<activity android:name="com.google.zxing.client.android.encode.EncodeActivity" android:label="#string/share_name">
<intent-filter>
<action android:name="com.phonegap.plugins.barcodescanner.ENCODE"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
</application>
</manifest>
It turned out my main Java file was named "MainActivity.java" but it was being called as "Folklorama.java" throughout the project files. I renamed the file to Folklorama.java.
I got the stack trace below in the Android developer account. There is just one occurrence of this error.
java.lang.RuntimeException: Unable to instantiate application com.mysite.myapp.TestApplication: java.lang.ClassNotFoundException: com.mysite.myapp.TestApplication in loader dalvik.system.PathClassLoader[/data/app-private/com.mysite.myapp-2.apk]
at android.app.LoadedApk.makeApplication(LoadedApk.java:466)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3268)
at android.app.ActivityThread.access$2200(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:973)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3691)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:670)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: com.myapp.myapp.TestApplication in loader dalvik.system.PathClassLoader[/data/app-private/com.mysite.myapp-2.apk]
at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at android.app.Instrumentation.newApplication(Instrumentation.java:945)
at android.app.LoadedApk.makeApplication(LoadedApk.java:461)
... 11 more
In my manifest file, I have declared com.mysite.myapp.TestApplication.
My Manifest file looks like this:
<application
android:name="com.mysite.myapp.TestApplication"
android:icon="#drawable/app_icon"
android:label="#string/app_name"
android:theme="#style/Theme.myapp" >
<activity
android:name="com.mysite.myapp.ActivityDashboard"
android:configChanges="orientation|keyboard"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
...
If your main home page is ActivityDashboard.java
insert as below or if TestApplication.java
replace .ActivityDashboard as .TestApplication in the activity tag
<package name="com.mysite.myapp"
<application
android:name="TestApplication"
android:icon="#drawable/app_icon"
android:label="#string/app_name"
android:theme="#style/Theme.myapp" >
<activity android:name=".ActivityDashboard" android:configChanges="orientation|keyboard"
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>
android:name="com.mysite.myapp.ActivityDashboard"
Replace thr above in your manifest with the below.
android:name=".ActivityDashboard"
Alternatively:
android:name="com.mysite.myapp.TestApplication.ActivityDashboard"
I have an app with ~11k active installs for which I sometimes receive ClassNotFoundExceptions that I can't explain. They look like this:
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{name.of.my.MainActivityClass}: java.lang.ClassNotFoundException: name.of.my.MainActivityClass in loader dalvik.system.PathClassLoader[/mnt/asec/name.of.my-2/pkg.apk]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1743)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1851)
at android.app.ActivityThread.access$1500(ActivityThread.java:132)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1038)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:150)
at android.app.ActivityThread.main(ActivityThread.java:4293)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:849)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:607)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: name.of.my.MainActivityClass in loader dalvik.system.PathClassLoader[/mnt/asec/name.of.my-2/pkg.apk]
at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at android.app.Instrumentation.newActivity(Instrumentation.java:1040)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1735)
... 11 more
I received some of these exceptions from users that updated my app (not only for the most recent version), so I think it is not a problem that is specific to some phones as the app worked for them before.
I got these exception reports for my main activity class, a receiver class and a BackupAgent class.
All of those classes are always instantiated directly from Android. My Manifest file looks like this:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="name.of.my"
android:versionCode="20"
android:versionName="1.10.2"
android:installLocation="auto">
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="8" />
<application android:icon="#drawable/icon" android:label="#string/app_name" android:backupAgent="name.of.my.OwnBackupAgent">
<activity android:name="name.of.my.MainActivityClass"
android:label="#string/app_name"
android:theme="#style/MyTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name="name.of.my.OwnReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.media.RINGER_MODE_CHANGED" />
</intent-filter>
</receiver>
</application>
</manifest>
After searching the net for some hours, the most likely explanations I found are:
it might be related to moving the app to SD card while there are still some services running (but the android dev guide says that all services are canceled in this case, and it doesn't explain why my main activity class suddenly can't be found anymore)
the .apk might be corrupted after updating via the android market. Could this be true? If yes, what can I do against it - if not, what else might be the problem?