开发者

Android: crash on 3.0 app thats supposed to be backward compatible

开发者 https://www.devze.com 2023-03-09 05:33 出处:网络
this is a follow-up question to my question earlier this day. I have installed the compatibility pack and restarted Eclipse. Then I created an activity like this, using Blundell\'s code:

this is a follow-up question to my question earlier this day.

I have installed the compatibility pack and restarted Eclipse. Then I created an activity like this, using Blundell's code:

public class EntryActivitiy extends Activity
{
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.about);

        int b = Integer.parseInt(Build.VERSION.SDK);
        if (b >= Build.VERSION_CODES.HONEYCOMB)
        {
            Log.i(getString(R.string.app_name), "Found A Tablet Running Honeycomb or newer");
            //nothing else in here yet
        }
        else
        {
            this.startActivity(new Intent(this, Main.class));
        }
    }

}

My Manifest contains:

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

    <supports-screens android:smallScreens="false"
        android:normalScreens="true"
        android:largeScreens="true"
        android:xlargeScreens="true"/>

as well as

    <activity android:name="EntryActivity"
        android:label="@string/app_name" 
        android:noHistory="true">           

        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

  开发者_开发问答  </activity>

In the project settings, I have set the build target to 3.0 as otherwise I'll get an "HONEYCOMB cannot be resolved or is not a field" error.

Now, if I run it on my 2.2 AVD, the app crashes like this:

05-27 14:13:54.270: ERROR/AndroidRuntime(329): FATAL EXCEPTION: main
05-27 14:13:54.270: ERROR/AndroidRuntime(329): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{/myPackage.EntryActivity}: java.lang.ClassNotFoundException: myPackage.EntryActivity in loader dalvik.system.PathClassLoader[/data/app/myPackage-1.apk]
05-27 14:13:54.270: ERROR/AndroidRuntime(329):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
05-27 14:13:54.270: ERROR/AndroidRuntime(329):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
05-27 14:13:54.270: ERROR/AndroidRuntime(329):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
05-27 14:13:54.270: ERROR/AndroidRuntime(329):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
05-27 14:13:54.270: ERROR/AndroidRuntime(329):     at android.os.Handler.dispatchMessage(Handler.java:99)
05-27 14:13:54.270: ERROR/AndroidRuntime(329):     at android.os.Looper.loop(Looper.java:123)
05-27 14:13:54.270: ERROR/AndroidRuntime(329):     at android.app.ActivityThread.main(ActivityThread.java:4627)
05-27 14:13:54.270: ERROR/AndroidRuntime(329):     at java.lang.reflect.Method.invokeNative(Native Method)
05-27 14:13:54.270: ERROR/AndroidRuntime(329):     at java.lang.reflect.Method.invoke(Method.java:521)
05-27 14:13:54.270: ERROR/AndroidRuntime(329):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-27 14:13:54.270: ERROR/AndroidRuntime(329):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-27 14:13:54.270: ERROR/AndroidRuntime(329):     at dalvik.system.NativeStart.main(Native Method)
05-27 14:13:54.270: ERROR/AndroidRuntime(329): Caused by: java.lang.ClassNotFoundException: myPackage.EntryActivity in loader dalvik.system.PathClassLoader[/data/app/myPackage-1.apk]
05-27 14:13:54.270: ERROR/AndroidRuntime(329):     at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
05-27 14:13:54.270: ERROR/AndroidRuntime(329):     at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
05-27 14:13:54.270: ERROR/AndroidRuntime(329):     at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
05-27 14:13:54.270: ERROR/AndroidRuntime(329):     at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
05-27 14:13:54.270: ERROR/AndroidRuntime(329):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
05-27 14:13:54.270: ERROR/AndroidRuntime(329):     ... 11 more

If tried it on my 2.3 phone but got some weird screen flickering and "HDMI disconnected" and other very strange messages in the LogCat. I don't want to repeat it, though, so I can't provide the exact messages.

What am I doing wrong?

Kind regards, jellyfish

Edit:

I swapped back to my old main activity and it worked fine. Also, I commented all the HC-related code out and it still would crash. I also tried to set another Activity as main and that also worked. :/


EDIT

Your activity class is actually Misspelt!

Change it in your manifest or change your class name:

 public class EntryActivitiy extends // here spellcheck

Original Answer

You need a period before the class name of your activity in your manifest:

 <activity android:name=".EntryActivity"
    android:label="@string/app_name" 
    android:noHistory="true">  

Do a Project > Clean and it should Auto rebuild after this

You then need to check your manifest to ensure your package is correct:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.something.something"
 ....

I would also uninstall off the emulator after this, just to be safe , Emulator > Settings > Applications > Standard Uninstall


What's the package of EntryActivity? Is it in myPackage?


You need to place a period before the class name of your activity in the manifest:

 <activity android:name=".EntryActivity"
0

精彩评论

暂无评论...
验证码 换一张
取 消