Android:在应该向后兼容的 3.0 应用程序上崩溃
我已经安装了兼容包并重新启动了Eclipse。然后我使用 Blundell 的代码创建了一个这样的活动:
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));
}
}
}
我的清单包含:
<uses-sdk android:minSdkVersion="8"
android:targetSdkVersion="11"/>
<supports-screens android:smallScreens="false"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"/>
以及
<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>
在项目设置中,我已将构建目标设置为 3.0,否则我将得到“HONEYCOMB 无法解析或不是字段”错误。
现在,如果我在 2.2 AVD 上运行它,应用程序会像这样崩溃:
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
如果在我的 2.3 手机上尝试它,但在 LogCat 中出现一些奇怪的屏幕闪烁和“HDMI 已断开连接”以及其他非常奇怪的消息。不过,我不想重复,所以我无法提供确切的消息。
我做错了什么?
亲切的问候, jellyfish
编辑:
我换回了原来的主要活动,效果很好。另外,我把所有与HC相关的代码都注释掉了,它仍然会崩溃。我还尝试将另一个 Activity 设置为主要活动,这也有效。 :/
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. :/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
编辑
您的活动课程实际上拼写错误!
在清单中更改它或更改您的类名称:
原始答案
您的清单中的活动的类名称之前需要一个句点:
Do a Project >干净,它应该在此之后自动重建
然后您需要检查您的清单以确保您的包是正确的:
在此之后我还会卸载模拟器,只是为了安全起见,模拟器> >设置>应用领域>>标准卸载
EDIT
Your activity class is actually Misspelt!
Change it in your manifest or change your class name:
Original Answer
You need a period before the class name of your activity in your manifest:
Do a Project > Clean and it should Auto rebuild after this
You then need to check your manifest to ensure your package is correct:
I would also uninstall off the emulator after this, just to be safe , Emulator > Settings > Applications > Standard Uninstall
EntryActivity的包是什么?它在我的包中吗?
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: