Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't find class MainActivity (imported project)

So I imported an android project and after struggling for a while when I was finally done, I compiled the app and it crashed.

This is the logcat file:

07-16 23:02:23.700: E/AndroidRuntime(23092): FATAL EXCEPTION: main
07-16 23:02:23.700: E/AndroidRuntime(23092): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{si.dvanadva.evanturist/si.dvanadva.evanturist.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "si.dvanadva.evanturist.MainActivity" on path: /data/app/si.dvanadva.evanturist-2.apk
07-16 23:02:23.700: E/AndroidRuntime(23092):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2106)
07-16 23:02:23.700: E/AndroidRuntime(23092):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
07-16 23:02:23.700: E/AndroidRuntime(23092):    at android.app.ActivityThread.access$600(ActivityThread.java:141)
07-16 23:02:23.700: E/AndroidRuntime(23092):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
07-16 23:02:23.700: E/AndroidRuntime(23092):    at android.os.Handler.dispatchMessage(Handler.java:99)
07-16 23:02:23.700: E/AndroidRuntime(23092):    at android.os.Looper.loop(Looper.java:137)
07-16 23:02:23.700: E/AndroidRuntime(23092):    at android.app.ActivityThread.main(ActivityThread.java:5041)
07-16 23:02:23.700: E/AndroidRuntime(23092):    at java.lang.reflect.Method.invokeNative(Native Method)
07-16 23:02:23.700: E/AndroidRuntime(23092):    at java.lang.reflect.Method.invoke(Method.java:511)
07-16 23:02:23.700: E/AndroidRuntime(23092):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
07-16 23:02:23.700: E/AndroidRuntime(23092):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
07-16 23:02:23.700: E/AndroidRuntime(23092):    at dalvik.system.NativeStart.main(Native Method)
07-16 23:02:23.700: E/AndroidRuntime(23092): Caused by: java.lang.ClassNotFoundException: Didn't find class "si.dvanadva.evanturist.MainActivity" on path: /data/app/si.dvanadva.evanturist-2.apk
07-16 23:02:23.700: E/AndroidRuntime(23092):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
07-16 23:02:23.700: E/AndroidRuntime(23092):    at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
07-16 23:02:23.700: E/AndroidRuntime(23092):    at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
07-16 23:02:23.700: E/AndroidRuntime(23092):    at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
07-16 23:02:23.700: E/AndroidRuntime(23092):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)

I can see from this line:

07-16 23:02:23.700: E/AndroidRuntime(23092): Caused by: java.lang.ClassNotFoundException: Didn't find class "si.dvanadva.evanturist.MainActivity" on path: /data/app/si.dvanadva.evanturist-2.apk

That there is a problem finding MainActivity class. But why?

This is how I imported the project:

  • Imported raw project (without libraries)

  • Added jars to libs folder in the project

  • Added missing build path for jars

  • Imported three library projects (the original project detected them)

Those three library projects are all in the same folder as the original project (in case I placed them wrong or something)

If you need any additional info please let me know, I need to solve this problem

Packages and their content:

enter image description here

AndroidManifest full code:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="si.dvanadva.evanturist"
android:versionCode="7"
android:versionName="1.1.2" 
android:installLocation="preferExternal">

<!-- ZA MAPE -->
<permission
    android:name="com.dd.evanturist.permission.MAPS_RECEIVE"
    android:protectionLevel="signature"/>
<uses-permission android:name="com.dd.evanturist.permission.MAPS_RECEIVE"/>

  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
  <uses-permission android:name="android.permission.INTERNET"/>
  <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
  <!-- External storage for caching. -->
  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
  <!-- My Location -->
  <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
  <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
  <!-- Maps API needs OpenGL ES 2.0. -->
  <uses-feature
    android:glEsVersion="0x00020000"
    android:required="true"/>
  <!-- End of copy. -->

<!-- QR STUFF -->

<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.FLASHLIGHT"/>

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="17" />

<application
    android:allowBackup="true"
    android:name=".MyApplication"
    android:icon="@drawable/ic_launcher"
    android:label="@string/evanturist"
    android:theme="@style/AppTheme" >
    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="AIzaSyDK5zGCwh3awW08BOAwupjU4hw8750WuLM"/>
    <activity
        android:name=".MainActivity"
        android:label="@string/evanturist" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".DBActivity"></activity>
    <activity android:name=".DbTestActivity"></activity>
    <activity android:name=".PlaceItemActivity"></activity>
    <activity android:name=".CheckpointsActivity"></activity>
    <activity android:name=".OptionsActivity"></activity>
    <activity android:name=".MapDirectionsActivity"></activity>
    <activity android:name=".VictoryActivity"></activity>
    <activity android:name=".QrActivity"
        android:screenOrientation="landscape"
        android:theme="@android:style/Theme.NoTitleBar.Fullscreen"></activity>
    <activity android:name=".QrPortraitActivity"
        android:screenOrientation="portrait" android:theme="@android:style/Theme.NoTitleBar"></activity>

</application>

Export tab at build paths:

enter image description here

like image 570
Guy Avatar asked Jul 16 '13 21:07

Guy


2 Answers

Problem solved!!

The entire problem was caused by Google Play Services library project. When someone sent me this project, he also attached all three library projects needed for the project. I then added all three library project directly from the file that he sent me.

Now the thing is, you always need to add google play services from SDK download location (not from anywhere else - external sources), so I just removed the current google play services and added the ones that I downloadad with the SDK manager and the problem was solved.

like image 116
Guy Avatar answered Nov 05 '22 23:11

Guy


1) Keep all activities under same package[say com.compname.proj.views].

2) Ensure in manifest, package attribute is set to the above package[i.e com.compname.proj.views].

3) In manifest, under all activity tag, make sure android:name attribute has values matching to below pattern:

    android:name=".<your activity class name>"

Ex: android:name=".SomeActivity"

My point is not to use package name + activity class name for manifest activity declaration.

Once you are sure about above points, if still problem persists, then :

  1. Delete bin folder.

  2. Rebuild your project and run.

like image 36
Chandan Adiga Avatar answered Nov 05 '22 22:11

Chandan Adiga