user3591522
user3591522

Reputation: 133

unable to instantiate activity, ClassNotFoundException

I am developing an android application and after moving around some libraries and adjusting my workspace so that it can sync with github I am now encountering a new error that I have not had in the past. Here is the print out in LogCat.

FATAL EXCEPTION: main
Process: com.exmple.loop, PID:1000
java.lang.RuntimeException: Unable to instantiate activity 
ComponentInfo{com.example.loop/com.example.loop.MainActivity}: 
java.lang.ClassNotFoundException: Didn't find class "com.example.loop.MainActivity" on 
path: DexpathList[[zip file "/data/app/com.example.loop-2.apk"]...

I can supply more if needed. I have checked stackoverflow for solutions and came across some that proved to be unhelpful. Here is the first question I found and here is the second. I tried the helpful solutions for both and nothing seems to work. Similar to the user in the first question, the exception is thrown before any line I write because it is failing to recognize my main activity as a class.

Here is my android manifest.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.loop"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="14"
    android:targetSdkVersion="19" />

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application
    android:allowBackup="true"
    android:name="com.example.loop.LoopApplication"
    android:icon="@drawable/loop_icon"
    android:label="@string/app_name"
    android:theme="@style/Theme.Loop" >
    <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
    <activity
        android:name="com.example.loop.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:theme="@style/AppTheme" android:logo="@drawable/loop_icon" android:name="LoginActivity">

    </activity>

</application>

</manifest>

Upvotes: 0

Views: 996

Answers (4)

user3591522
user3591522

Reputation: 133

So after trying every bit of advice given to me I decided to create a new Android Project and copy all the files from the old project the appropriate folder in the new project. While this took a little bit of time that could have probably been shorter if I had messed with the original project some more, ultimately it did fix the error I was encountering and the project now runs.

Upvotes: 0

user3626384
user3626384

Reputation:

There are many causes to this. I'll try to name as much as I can.

1.You tryed to add the library in your Java Build Path and not in the Android libraries. rigt-click on your project> properties > Android. At the bottom there is a place for Android libraries.

2.Right-click your src folder>Build Path > Use as Source Folder

3.Right-click you src folder> Build Path> Configure output folder > set projects default output folder

4.Right-clikc project > Java Build Path > Order and Export > check Android Private Libraries (You CAN'T have any library in Android Private Libraries and in the outside at the same time)

5.If you have set the project to use Maven and removed it after. Delete the bin folder and the pom.xml

6.Check if you R file is being generated. Delete it and see if it rebuild. If not look in your manifest or xml files for any error.

7.Check that Build Atomatically is checked.

Hope this help, I have had this that problem many times, and each time it was something else.

Good luck!

Edit: there is a 8 cause but this is not your case. Its if you forget to add the class to the manifest.

Upvotes: 0

CodeWarrior
CodeWarrior

Reputation: 5176

Change your activity tag to this and it will run:

<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>

Upvotes: 0

Ultimo_m
Ultimo_m

Reputation: 4897

If you look in your logcat it writes:

ComponentInfo{com.exmple.loop/com.example.loop.MainActivity}: 

com.exmple.loop 

I think it should be com.example.loop

Try remove this line and see if it works:

android:name="com.example.loop.LoopApplication"

Upvotes: 1

Related Questions