Cannot find MainActivity class (imported project)

So, I imported the android project and after a long time, when I was finally finished, I compiled the application 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 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 

Problem with detecting MainActivity class. But why?

This is how I imported the project:

  • Imported source project (without libraries)

  • Added a jar to the libs folder in the project

  • Added missing build path for cans

  • Imported three library projects (source project detected them)

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

If you need more information, please let me know, I need to solve this problem.

Packages and their contents:

enter image description here

Full list of AndroidManifest:

 <?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 in build path:

enter image description here

+6
source share
2 answers

The problem is solved!

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

Now you always need to add google play services from the SDK download location (not from other sources - external sources), so I just deleted the current Google Play services and added the ones that I download using the SDK manager and the problem was solved.

+3
source

1) Keep all actions in one package [say com.compname.proj.views].

2) Make sure that in the manifest the package attribute is set to the above package [ie com.compname.proj.views].

3) In the manifest in the entire activity tag, make sure that the android: name attribute has values ​​that match the pattern below:

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

Ex: android: name = ". SomeActivity"

My point is not to use the package name + activity class name to declare manifest activity.

Once you are sure to exceed the points, if the problem still persists, then:

  • Delete the bin folder.

  • Restore the project and run it.

+2
source

Source: https://habr.com/ru/post/949604/


All Articles