Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ClassNotFindException while running Android sample EffectiveNavigation for older platform

I am running the sample from Implementing Effective Navigation - EffectiveNavigation.zip - which demonstrates some swipe views with tabs in an activity. It runs fine on a newer platform such as 4.2.2 (API17).

Then I want to support older platforms such as 2.3.3 (API10) too, so I lower the minSdkVersion to 4:

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

I do include the support libraries in one of the following ways:

  1. by the book: V4 Support Library Setup - without resources
  2. or by the book: V7 Support Library Setup - with resources
  3. or right-click in project ->Android Tools->Add Support Library

Anyway, when I run the app on a 2.3.3 device, this ambiguous runtime exception occurs as in the listing below.

Before rushing in that has been asked before please note: my problem is I can't run it on older devices such as 2.3.3 - but runs fine on newer devices such as 4.2.2.

I deleted, reimported and rebuilt and rerun with various changed settings on various emulators. It just doesn't run on older devices (my purpose is using tabs and swipe views in older devices).

 java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.android.effectivenavigation/com.example.android.effectivenavigation.MainActivity}: java.lang.ClassNotFoundException: com.example.android.effectivenavigation.MainActivity in loader dalvik.system.PathClassLoader[/data/app/com.example.android.effectivenavigation-1.apk]
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1569)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
    at android.app.ActivityThread.access$1500(ActivityThread.java:117)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:130)
    at android.app.ActivityThread.main(ActivityThread.java:3683)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:507)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
    at dalvik.system.NativeStart.main(Native Method)
 Caused by: java.lang.ClassNotFoundException: com.example.android.effectivenavigation.MainActivity in loader dalvik.system.PathClassLoader[/data/app/com.example.android.effectivenavigation-1.apk]
    at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
    at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561)
like image 271
RumburaK Avatar asked Aug 05 '13 02:08

RumburaK


Video Answer


1 Answers

Finally solved, after one day and one night wasted!

Most of the problem was that the app was also implementing an ActionBar and that needed more migration effort. I had to change some other bits to use the support libraries (v4 and v7), mostly:

  • everything from Support Library Setup (see V7 with resources + using APIs)
  • plus everything from Chris's video about AppCompat
  • plus be careful to examine every error and warning in Eclipse

Code changes in Java files:

<< import android.app.ActionBar;
<< import android.app.FragmentTransaction;
---
>> import android.support.v7.app.ActionBar;
>> import android.support.v4.app.FragmentTransaction;


<< public class MainActivity extends FragmentActivity implements ActionBar.TabListener {
---
>> public class MainActivity extends ActionBarActivity implements ActionBar.TabListener {


<< final ActionBar actionBar = getActionBar();
---
>> final ActionBar actionBar = getSupportActionBar();

Changes in AndroidManifest.xml:

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

<< android:theme="@android:style/Theme.Holo.Light.DarkActionBar">
---
>> android:theme="@style/Theme.AppCompat.Light.DarkActionBar">

It's not about cleaning up and rebuilding the project, though you may do so if it makes you feel better.

Now I have ActionBar and Tabs with SwipeViews on my 2.3.3 Android.

Google is putting so much emphasis on these backports, and I have to use them, too bad there isn't some more clear and complete documentation about it. I even have troubles finding that video myself unless I refer to YouTube history - don't even know how I found it in the first place.

like image 110
RumburaK Avatar answered Sep 23 '22 12:09

RumburaK