Android - exception when compiling and running the application - android

I am running a debug android application with eclipse and the simulator, and on a restarting of the app, I get this exception,
03-23 02:19:51.384: E/AndroidRuntime(605): FATAL EXCEPTION: main
03-23 02:19:51.384: E/AndroidRuntime(605): java.lang.RuntimeException: Unable to instantiate application android.app.Application: java.lang.NullPointerException
03-23 02:19:51.384: E/AndroidRuntime(605): at android.app.LoadedApk.makeApplication(LoadedApk.java:482)
03-23 02:19:51.384: E/AndroidRuntime(605): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3938)
03-23 02:19:51.384: E/AndroidRuntime(605): at android.app.ActivityThread.access$1300(ActivityThread.java:123)
03-23 02:19:51.384: E/AndroidRuntime(605): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1185)
03-23 02:19:51.384: E/AndroidRuntime(605): at android.os.Handler.dispatchMessage(Handler.java:99)
03-23 02:19:51.384: E/AndroidRuntime(605): at android.os.Looper.loop(Looper.java:137)
03-23 02:19:51.384: E/AndroidRuntime(605): at android.app.ActivityThread.main(ActivityThread.java:4424)
03-23 02:19:51.384: E/AndroidRuntime(605): at java.lang.reflect.Method.invokeNative(Native Method)
03-23 02:19:51.384: E/AndroidRuntime(605): at java.lang.reflect.Method.invoke(Method.java:511)
03-23 02:19:51.384: E/AndroidRuntime(605): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
03-23 02:19:51.384: E/AndroidRuntime(605): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
03-23 02:19:51.384: E/AndroidRuntime(605): at dalvik.system.NativeStart.main(Native Method)
03-23 02:19:51.384: E/AndroidRuntime(605): Caused by: java.lang.NullPointerException
03-23 02:19:51.384: E/AndroidRuntime(605): at android.app.LoadedApk.initializeJavaContextClassLoader(LoadedApk.java:362)
03-23 02:19:51.384: E/AndroidRuntime(605): at android.app.LoadedApk.getClassLoader(LoadedApk.java:305)
03-23 02:19:51.384: E/AndroidRuntime(605): at android.app.LoadedApk.makeApplication(LoadedApk.java:474)
03-23 02:19:51.384: E/AndroidRuntime(605): ... 11 more
But this doesn't really say where the error happened in my code. Any idea why this might be happening and how to prevent it?
and this is the entire manifest of the small application:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.problemio"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="15" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".ProblemioActivity"
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=".AddProblemActivity"
android:label="#string/add_problem" />
<activity
android:name=".LoginActivity"
android:label="#string/login" />
<activity
android:name=".MyProblemsActivity"
android:label="#string/your_problems" />
<activity
android:name=".LogoutActivity"
android:label="#string/app_name" />
<activity
android:name=".CreateProfileActivity"
android:label="#string/create_account" />
<activity
android:name=".ProblemActivity"
android:label="#string/problem_page_header" />
<activity
android:name=".SuggestSolutionActivity"
android:label="#string/suggest_solution_header" />
<activity
android:name=".SuggestedSolutionActivity"
android:label="#string/suggested_solution_header" />
<activity
android:name=".ViewSolutionsActivity"
android:label="#string/view_solutions_header" />
<activity
android:name=".TopicActivity"
android:label="#string/topic_header" />
</application>
</manifest>
Thanks!

I also get this excepiton.
I am using Nexus S, and update to 4.0.3
I just ignore this exception.

The real solution to this problem is a folder permissions issue. Make sure you are operating in a folder that you can modify. I just fixed that same problem for my self by making sure I was in a folder with the right permissions.

Related

Errors in a testing android project

I'm trying to run this code (android app):
manifest file:
<<<<<<< Original
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.testamish"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".Results"
android:label="#string/title_activity_results" >
</activity>
<activity
android:name=".SpinnerDemo"
android:label="#string/title_activity_spinner_demo" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
=======
<manifest xmlns:android="http://schemas.android.com/apk/res/android" >
<application>
<activity android:name="com.example.testamish.MainActivity"
android:label="#string/title_activity_main"
>
</activity>
</application>
</manifest>
>>>>>>> Added
However, when trying to launch this on a virtual device, I get those errors and I don't get why (code has no errors/warnings):
10-17 17:07:22.685: E/Trace(819): error opening trace file: No such file or directory (2)
10-17 17:07:23.430: D/AndroidRuntime(819): Shutting down VM
10-17 17:07:23.430: W/dalvikvm(819): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
10-17 17:07:23.445: E/AndroidRuntime(819): FATAL EXCEPTION: main
10-17 17:07:23.445: E/AndroidRuntime(819): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.testamish/com.example.testamish.MainActivity}: java.lang.ClassNotFoundException: com.example.testamish.MainActivity
10-17 17:07:23.445: E/AndroidRuntime(819): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1983)
10-17 17:07:23.445: E/AndroidRuntime(819): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
10-17 17:07:23.445: E/AndroidRuntime(819): at android.app.ActivityThread.access$600(ActivityThread.java:130)
10-17 17:07:23.445: E/AndroidRuntime(819): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
10-17 17:07:23.445: E/AndroidRuntime(819): at android.os.Handler.dispatchMessage(Handler.java:99)
10-17 17:07:23.445: E/AndroidRuntime(819): at android.os.Looper.loop(Looper.java:137)
10-17 17:07:23.445: E/AndroidRuntime(819): at android.app.ActivityThread.main(ActivityThread.java:4745)
10-17 17:07:23.445: E/AndroidRuntime(819): at java.lang.reflect.Method.invokeNative(Native Method)
10-17 17:07:23.445: E/AndroidRuntime(819): at java.lang.reflect.Method.invoke(Method.java:511)
10-17 17:07:23.445: E/AndroidRuntime(819): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
10-17 17:07:23.445: E/AndroidRuntime(819): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
10-17 17:07:23.445: E/AndroidRuntime(819): at dalvik.system.NativeStart.main(Native Method)
10-17 17:07:23.445: E/AndroidRuntime(819): Caused by: java.lang.ClassNotFoundException: com.example.testamish.MainActivity
10-17 17:07:23.445: E/AndroidRuntime(819): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
10-17 17:07:23.445: E/AndroidRuntime(819): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
10-17 17:07:23.445: E/AndroidRuntime(819): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
10-17 17:07:23.445: E/AndroidRuntime(819): at android.app.Instrumentation.newActivity(Instrumentation.java:1053)
10-17 17:07:23.445: E/AndroidRuntime(819): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1974)
10-17 17:07:23.445: E/AndroidRuntime(819): ... 11 more
Thanks for your help!
Solution
Remove this from you Manifest (from the original one!):
<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>
And add this four line to the Activity, you want to start on launch:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
Details
In Android, the data&actions between activities is driven by Intents. When you want to launch an app, it's kind an action between the Launcher app, and your app. It's also an Intent, when you start the Gallery, to choose an image for Facebook, or to start the Twitter app, to share something.
You can define in the Manifest.xml, for each Activity of your app, to which Intents to catch. You defined a MainActivity in your Manifest, and set to catch the android.intent.action.MAIN and android.intent.category.LAUNCHER intents. These two Intents responds, to start the app from the Launcher.
So the emulator was finding for your MainActivity, 'cause it read from you Manifest, to start that. But cannot found it, so throw an exception.

Android : illegaljavaexception Could not execute the method for activity

I'm trying using intent to add class to an application. I have made SecondAcitivity class and modified the manifest file as well. My application is running i.e. First activity Containing the button works well, but onclick on button the error comes and it does not displays a second activity.
This is my MainActivity.java file
package com.intent.usingintent;
import android.os.Bundle;
import android.content.Intent;
import android.app.Activity;
import android.view.View;
public class MainActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void onClick(View view){
startActivity(new Intent("com.intent.SecondActivity"));
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.intent.usingintent"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.intent.usingintent.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="com.intent.SecondActivity"
android:label="SecondActivity" >
</activity>
<intent-filter>
<action android:name=".SecondActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</application>
</manifest>
ERROR LOG
07-09 13:57:45.922: W/dalvikvm(20185): threadid=1: thread exiting with uncaught exception (group=0x40d8e2a0)
07-09 13:57:45.932: E/AndroidRuntime(20185): FATAL EXCEPTION: main
07-09 13:57:45.932: E/AndroidRuntime(20185): java.lang.IllegalStateException: Could not execute method of the activity
07-09 13:57:45.932: E/AndroidRuntime(20185): at android.view.View$1.onClick(View.java:3699)
07-09 13:57:45.932: E/AndroidRuntime(20185): at android.view.View.performClick(View.java:4223)
07-09 13:57:45.932: E/AndroidRuntime(20185): at android.view.View$PerformClick.run(View.java:17275)
07-09 13:57:45.932: E/AndroidRuntime(20185): at android.os.Handler.handleCallback(Handler.java:615)
07-09 13:57:45.932: E/AndroidRuntime(20185): at android.os.Handler.dispatchMessage(Handler.java:92)
07-09 13:57:45.932: E/AndroidRuntime(20185): at android.os.Looper.loop(Looper.java:137)
07-09 13:57:45.932: E/AndroidRuntime(20185): at android.app.ActivityThread.main(ActivityThread.java:4898)
07-09 13:57:45.932: E/AndroidRuntime(20185): at java.lang.reflect.Method.invokeNative(Native Method)
07-09 13:57:45.932: E/AndroidRuntime(20185): at java.lang.reflect.Method.invoke(Method.java:511)
07-09 13:57:45.932: E/AndroidRuntime(20185): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1008)
07-09 13:57:45.932: E/AndroidRuntime(20185): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:775)
07-09 13:57:45.932: E/AndroidRuntime(20185): at dalvik.system.NativeStart.main(Native Method)
07-09 13:57:45.932: E/AndroidRuntime(20185): Caused by: java.lang.reflect.InvocationTargetException
07-09 13:57:45.932: E/AndroidRuntime(20185): at java.lang.reflect.Method.invokeNative(Native Method)
07-09 13:57:45.932: E/AndroidRuntime(20185): at java.lang.reflect.Method.invoke(Method.java:511)
07-09 13:57:45.932: E/AndroidRuntime(20185): at android.view.View$1.onClick(View.java:3694)
07-09 13:57:45.932: E/AndroidRuntime(20185): ... 11 more
07-09 13:57:45.932: E/AndroidRuntime(20185): Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.intent.SecondActivity }
07-09 13:57:45.932: E/AndroidRuntime(20185): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1580)
07-09 13:57:45.932: E/AndroidRuntime(20185): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1431)
07-09 13:57:45.932: E/AndroidRuntime(20185): at android.app.Activity.startActivityForResult(Activity.java:3446)
07-09 13:57:45.932: E/AndroidRuntime(20185): at android.app.Activity.startActivityForResult(Activity.java:3407)
07-09 13:57:45.932: E/AndroidRuntime(20185): at android.app.Activity.startActivity(Activity.java:3617)
07-09 13:57:45.932: E/AndroidRuntime(20185): at android.app.Activity.startActivity(Activity.java:3585)
07-09 13:57:45.932: E/AndroidRuntime(20185): at com.intent.usingintent.MainActivity.onClick(MainActivity.java:17)
07-09 13:57:45.932: E/AndroidRuntime(20185): ... 14 more
07-09 13:57:57.072: I/Process(20185): Sending signal. PID: 20185 SIG: 9
In your App, your second activity in com.intent.usingintent package.And your intent action is com.intent.SecondActivity,and write <intent-filter> inside <activity> tag.
So in manifest file,Change
<activity
android:name="com.intent.SecondActivity"
android:label="SecondActivity" >
</activity>
<intent-filter>
<action android:name=".SecondActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
to
<activity
android:name="com.intent.usingintent.SecondActivity"
android:label="SecondActivity" >
<intent-filter>
<action android:name="com.intent.SecondActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
You have misplaced IntentFilter for the SecondActivity in the manifest. Put it insude <activity></activity>
Though you do no treally need that you can simply do startActivity(new Intent(this, SecondActivity.class));
in your manifest file instead of this
<activity
android:name="com.intent.SecondActivity"
android:label="SecondActivity" >
</activity>
replace with
<activity
android:name="com.intent.usingintent.SecondActivity"
android:label="SecondActivity" >
</activity>
and even in your java class also
startActivity(new Intent("com.intent.SecondActivity"));
replace this with
startActivity(new Intent("com.intent.usingintent.SecondActivity"));
change in manifest file
<activity
android:name="com.intent.usingintent.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="SecondActivity"></activity>
change in click event
Intent n=new Intent(MainActivity.this,SecondActivity.class);
startActivity(n);

Weird Android error

I'm trying to run my start my app, but i get a weird error. I've changed my OS but I've imported my projects in my Workspace. What can be wrong? Every thing is added to the maniferst file like is should, and this app was running nice before I change my OS.
12-13 18:48:10.578: W/dalvikvm(19830): Unable to resolve superclass of Lcom/darkovski/quran/Main; (56)
12-13 18:48:10.578: W/dalvikvm(19830): Link of class 'Lcom/darkovski/quran/Main;' failed
12-13 18:48:10.578: D/AndroidRuntime(19830): Shutting down VM
12-13 18:48:10.578: W/dalvikvm(19830): threadid=1: thread exiting with uncaught exception (group=0x2b542210)
12-13 18:48:10.598: E/AndroidRuntime(19830): FATAL EXCEPTION: main
12-13 18:48:10.598: E/AndroidRuntime(19830): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.darkovski.quran/com.darkovski.quran.Main}: java.lang.ClassNotFoundException: com.darkovski.quran.Main
12-13 18:48:10.598: E/AndroidRuntime(19830): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1891)
12-13 18:48:10.598: E/AndroidRuntime(19830): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
12-13 18:48:10.598: E/AndroidRuntime(19830): at android.app.ActivityThread.access$600(ActivityThread.java:127)
12-13 18:48:10.598: E/AndroidRuntime(19830): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
12-13 18:48:10.598: E/AndroidRuntime(19830): at android.os.Handler.dispatchMessage(Handler.java:99)
12-13 18:48:10.598: E/AndroidRuntime(19830): at android.os.Looper.loop(Looper.java:137)
12-13 18:48:10.598: E/AndroidRuntime(19830): at android.app.ActivityThread.main(ActivityThread.java:4441)
12-13 18:48:10.598: E/AndroidRuntime(19830): at java.lang.reflect.Method.invokeNative(Native Method)
12-13 18:48:10.598: E/AndroidRuntime(19830): at java.lang.reflect.Method.invoke(Method.java:511)
12-13 18:48:10.598: E/AndroidRuntime(19830): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
12-13 18:48:10.598: E/AndroidRuntime(19830): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
12-13 18:48:10.598: E/AndroidRuntime(19830): at dalvik.system.NativeStart.main(Native Method)
12-13 18:48:10.598: E/AndroidRuntime(19830): Caused by: java.lang.ClassNotFoundException: com.darkovski.quran.Main
12-13 18:48:10.598: E/AndroidRuntime(19830): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
12-13 18:48:10.598: E/AndroidRuntime(19830): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
12-13 18:48:10.598: E/AndroidRuntime(19830): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
12-13 18:48:10.598: E/AndroidRuntime(19830): at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
12-13 18:48:10.598: E/AndroidRuntime(19830): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1882)
12-13 18:48:10.598: E/AndroidRuntime(19830): ... 11 more
Here is my manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.darkovski.quran"
android:installLocation="preferExternal"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.darkovski.quran.Main"
android:label="#string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.darkovski.quran.Playlist"
android:screenOrientation="portrait" />
<activity
android:name="com.darkovski.quran.AlbumDetails"
android:screenOrientation="portrait" />
<service
android:name=".MediaPlayerService"
android:enabled="true" />
<activity
android:name="com.darkovski.quran.Favorites"
android:screenOrientation="portrait" />
<activity
android:name="com.darkovski.quran.DownloadManager"
android:screenOrientation="portrait" />
</application>
</manifest>
This has nothing to do with Manifest. It is because somehow the super class of your class com/darkovski/quran/Main is not getting loaded in the apk which leads to a class not found.
Try cleaning and rebuilding the project or restarting eclipse. Just check if all the libraries are present in the new workspace and are build properly.

Why does my manifest.xml keep deleting the changes I make when I put the program into an apk

EDIT: STILL NEED HELP >:( Logcat added, as well as the manifest fix I can use for emulators only but not physical devices. If I transfer file to APK and load onto my device the manifest.xml file for that project just reverts to the second copy of the manifest.xml file.
I had this code working literally 5 minutes ago where the whole app would run a welcome screen, 6 different "flash cards", and an exit screen with button transitions. Now all of a sudden if I push any button the app crashes. Just says app has stopped working unexpectedly. I would put the logcat, but the error message is always dealing with the activity missing in the manifest. I am getting frustrated and just want to sleep.
logcat I get for the bottom manifest file that it always goes to. If it manually add the others then I do not get it. DOES NOT WORK WHEN TURNING PROJECT INTO APK FORMAT
11-04 05:29:01.912: D/gralloc_goldfish(819): Emulator without GPU emulation detected.
11-04 05:29:04.302: D/AndroidRuntime(819): Shutting down VM
11-04 05:29:04.302: W/dalvikvm(819): threadid=1: thread exiting with uncaught exception (group=0x41465700)
11-04 05:29:04.382: E/AndroidRuntime(819): FATAL EXCEPTION: main
11-04 05:29:04.382: E/AndroidRuntime(819): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.androidassignment2/com.example.androidassignment2.MainActivity}; have you declared this activity in your AndroidManifest.xml?
11-04 05:29:04.382: E/AndroidRuntime(819): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1628)
11-04 05:29:04.382: E/AndroidRuntime(819): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1424)
11-04 05:29:04.382: E/AndroidRuntime(819): at android.app.Activity.startActivityForResult(Activity.java:3390)
11-04 05:29:04.382: E/AndroidRuntime(819): at android.app.Activity.startActivityForResult(Activity.java:3351)
11-04 05:29:04.382: E/AndroidRuntime(819): at com.example.androidassignment2.Startup$1.onClick(Startup.java:22)
11-04 05:29:04.382: E/AndroidRuntime(819): at android.view.View.performClick(View.java:4240)
11-04 05:29:04.382: E/AndroidRuntime(819): at android.view.View$PerformClick.run(View.java:17721)
11-04 05:29:04.382: E/AndroidRuntime(819): at android.os.Handler.handleCallback(Handler.java:730)
11-04 05:29:04.382: E/AndroidRuntime(819): at android.os.Handler.dispatchMessage(Handler.java:92)
11-04 05:29:04.382: E/AndroidRuntime(819): at android.os.Looper.loop(Looper.java:137)
11-04 05:29:04.382: E/AndroidRuntime(819): at android.app.ActivityThread.main(ActivityThread.java:5103)
11-04 05:29:04.382: E/AndroidRuntime(819): at java.lang.reflect.Method.invokeNative(Native Method)
11-04 05:29:04.382: E/AndroidRuntime(819): at java.lang.reflect.Method.invoke(Method.java:525)
11-04 05:29:04.382: E/AndroidRuntime(819): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
11-04 05:29:04.382: E/AndroidRuntime(819): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-04 05:29:04.382: E/AndroidRuntime(819): at dalvik.system.NativeStart.main(Native Method)
working manifest file fix
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.androidassignment2"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.androidassignment2.Startup"
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.example.androidassignment2.DisplayMessageActivity"
android:label="#string/title_activity_display_message"
android:parentActivityName="com.example.AndroidAssignment2.MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.AndroidAssignment2.MainActivity" />
</activity>
<activity
android:name="com.example.androidassignment2.AndroidAssignment2_1" >
</activity>
<activity
android:name="com.example.androidassignment2.AndroidAssignment2_2" >
</activity>
<activity
android:name="com.example.androidassignment2.AndroidAssignment2_3" >
</activity>
<activity
android:name="com.example.androidassignment2.AndroidAssignment2_4" >
</activity>
<activity
android:name="com.example.androidassignment2.AndroidAssignment2_5" >
</activity>
<activity
android:name="com.example.androidassignment2.AndroidAssignment2" >
</activity>
<activity
android:name="com.example.androidassignment2.MainActivity" >
</activity>
</application>
</manifest>
all of the activities just go away once put into apk
this happens to the manifest file after putting the project into apk
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.androidassignment2"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.androidassignment2.Startup"
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.example.androidassignment2.DisplayMessageActivity"
android:label="#string/title_activity_display_message"
android:parentActivityName="com.example.AndroidAssignment2.MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.AndroidAssignment2.MainActivity" />
</activity>
</application>
</manifest>
EDIT: Before and after manifests.
LOGCAT JUST SAYS ACTIVITY NOT FOUND DECLARE IN MANIFEST

Unable to instantiate activity error? how to solve it?

I made an App. and since I just wanted to test some functions before adding them to the App,
I decided to copy my project into a new Project. When I tried to run the new project, the app crashes and the log-cat output is as follows.
Manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.androidbook.MP"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.CAMERA"/>
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" android:debuggable="true">
<activity
android:name=".MPActivity"
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="AddLocationActivity"></activity>
<activity android:name="MPData"></activity>
<activity android:name="MyLocations"></activity>
<activity android:name="MPInfo"></activity>
<activity android:name="Navigation"></activity>
</application>
LogCat:
05-21 15:30:03.710: E/AndroidRuntime(11294): FATAL EXCEPTION: main
05-21 15:30:03.710: E/AndroidRuntime(11294): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.androidbook.MP/com.androidbook.MP.MPActivity}:
java.lang.ClassNotFoundException: com.androidbook.MP.MPActivity in loader
dalvik.system.PathClassLoader[/data/app/com.androidbook.MP-1.apk]
05-21 15:30:03.710: E/AndroidRuntime(11294): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1573)
05-21 15:30:03.710: E/AndroidRuntime(11294): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
05-21 15:30:03.710: E/AndroidRuntime(11294): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
05-21 15:30:03.710: E/AndroidRuntime(11294): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
05-21 15:30:03.710: E/AndroidRuntime(11294): at android.os.Handler.dispatchMessage(Handler.java:99)
05-21 15:30:03.710: E/AndroidRuntime(11294): at android.os.Looper.loop(Looper.java:130)
05-21 15:30:03.710: E/AndroidRuntime(11294): at android.app.ActivityThread.main(ActivityThread.java:3691)
05-21 15:30:03.710: E/AndroidRuntime(11294): at java.lang.reflect.Method.invokeNative(Native Method)
05-21 15:30:03.710: E/AndroidRuntime(11294): at java.lang.reflect.Method.invoke(Method.java:507)
05-21 15:30:03.710: E/AndroidRuntime(11294): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
05-21 15:30:03.710: E/AndroidRuntime(11294): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
05-21 15:30:03.710: E/AndroidRuntime(11294): at dalvik.system.NativeStart.main(Native Method)
05-21 15:30:03.710: E/AndroidRuntime(11294): Caused by: java.lang.ClassNotFoundException: com.androidbook.MP.MPActivity in loader dalvik.system.PathClassLoader[/data/app/com.androidbook.MP-1.apk]
05-21 15:30:03.710: E/AndroidRuntime(11294): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
05-21 15:30:03.710: E/AndroidRuntime(11294): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
05-21 15:30:03.710: E/AndroidRuntime(11294): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
05-21 15:30:03.710: E/AndroidRuntime(11294): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
05-21 15:30:03.710: E/AndroidRuntime(11294): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1565)
05-21 15:30:03.710: E/AndroidRuntime(11294): ... 11 more
Check your Manifest file, if the activity is to be declared.
for Ex:
<application>
<activity android:name=".MyActivity" 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>
Look through all the files in your new project and make sure they aren't referencing classes from the old project.
I think I found the solution, i should have checked that, the package name of the new project is included in the manifest file as for an example
"package="com.androidbook.MPTest" ..
my mistake is the i used the package name of the old project as a package name of the new project.

Categories

Resources