TomSelleck
TomSelleck

Reputation: 6968

ClassNotFoundException: previously working Android Project

I had a working android project but needed to start from scratch. I copied all my source files and layout files over. There are no compilation errors but when I try to run, I get the following error.

11-27 17:21:56.793: E/AndroidRuntime(1450): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{projects.mobile.mapappproject/projects.mobile.mapappproject.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "projects.mobile.mapappproject.MainActivity" on path: /data/app/projects.mobile.mapappproject-1.apk

I am running eclipse juno and trying to run on Android 4.2. Thanks !

Upvotes: 1

Views: 4507

Answers (6)

Mohan
Mohan

Reputation: 1

In my case, following 2 steps fixed the problem

a. Setting compileSdkVersion, buildToolsVersion, targetSdkVersion to the same SDK version in build.gradle.

b. I was missing a dot in application class name in AndroidManifest.xml (Ex. android:name=".ui.ApplicationLoader")

Upvotes: 0

Langusten Gustel
Langusten Gustel

Reputation: 10992

Just for the record in case I can help someone :
I had a project that somehow didnt work after importing it from git. I solved this by giving the name of the activity explicitly.

example:
before: <activity android:name=".Main" [...] /> (relative)
after: <activity android:name="com.example.package.Main" [...] /> (absolute)

This may also occur if you change the manifest package and keep your relative reference (which I think is default).

Upvotes: 0

yansigner
yansigner

Reputation: 895

I had the same problem, but I found out that a library reference path wasn't right. After I fixed that everything worked fine. You can check this at Right-click on your project => Properties => Android -> (Library)

Upvotes: 1

Mahdi Giveie
Mahdi Giveie

Reputation: 640

Try these

  1. Add the Activity to AndroidManifest.xml
  2. Is there a difference in your folder names ? For example projects.mobile.mapappproject-1 or projects.mobile.mapappproject !

Upvotes: 2

devunwired
devunwired

Reputation: 63293

I copied all my source files and layout files over.

It looks like you forgot to copy over the entries that existed in AndroidManifest.xml, however. Each Activity has an entry there and that entry is required for the framework to find and launch the UI.

Upvotes: 1

saum22
saum22

Reputation: 882

Rather than doing copy paste try following

1.Create an android application project

2.Delete the files which was created Eg.MainActivity and layout.

2.Right click on project name and click import ,then from File system.Go to your project directory to import the source from there

3.select that, then finish.

4.Clean and build then run

Upvotes: 5

Related Questions