gpt4 book ai didi

android - 重写 View.layout(...) 时出现 VirtualMachineError

转载 作者:太空狗 更新时间:2023-10-29 13:34:06 25 4
gpt4 key购买 nike

Android 抛出 fatal error 然后我膨胀类,它有重写的方法:

Class MyButton extends Button {
....
@Override
public void layout(int l, int t, int r, int b) {
super.layout(l, t, r, b);
}
}

我是否注释我的代码并不重要。只有我删除了这个被覆盖的函数,应用程序才能工作。

错误:

09-18 13:45:43.809: E/AndroidRuntime(13363): FATAL EXCEPTION: main
09-18 13:45:43.809: E/AndroidRuntime(13363): java.lang.VirtualMachineError
09-18 13:45:43.809: E/AndroidRuntime(13363): at dalvik.system.DexFile.defineClass(Native Method)
09-18 13:45:43.809: E/AndroidRuntime(13363): at dalvik.system.DexFile.loadClassBinaryName(DexFile.java:207)
09-18 13:45:43.809: E/AndroidRuntime(13363): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:200)
09-18 13:45:43.809: E/AndroidRuntime(13363): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
09-18 13:45:43.809: E/AndroidRuntime(13363): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
09-18 13:45:43.809: E/AndroidRuntime(13363): at android.view.LayoutInflater.createView(LayoutInflater.java:471)
09-18 13:45:43.809: E/AndroidRuntime(13363): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:570)
09-18 13:45:43.809: E/AndroidRuntime(13363): at android.view.LayoutInflater.inflate(LayoutInflater.java:386)
09-18 13:45:43.809: E/AndroidRuntime(13363): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
09-18 13:45:43.809: E/AndroidRuntime(13363): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
09-18 13:45:43.809: E/AndroidRuntime(13363): at android.view.View.inflate(View.java:8807)
09-18 13:45:43.809: E/AndroidRuntime(13363): at com.eee.android.activities.Screen1.addSubject(Screen1.java:372)
09-18 13:45:43.809: E/AndroidRuntime(13363): at com.xxx.android.activities.Screen1.parseData(Screen1.java:348)
09-18 13:45:43.809: E/AndroidRuntime(13363): at com.xxx.android.activities.Screen1.initalizeData(Screen1.java:178)
09-18 13:45:43.809: E/AndroidRuntime(13363): at com.xxx.android.activities.Screen1.onResume(Screen1.java:139)
09-18 13:45:43.809: E/AndroidRuntime(13363): at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1150)
09-18 13:45:43.809: E/AndroidRuntime(13363): at android.app.Activity.performResume(Activity.java:3832)
09-18 13:45:43.809: E/AndroidRuntime(13363): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2114)
09-18 13:45:43.809: E/AndroidRuntime(13363): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2139)
09-18 13:45:43.809: E/AndroidRuntime(13363): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1672)
09-18 13:45:43.809: E/AndroidRuntime(13363): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
09-18 13:45:43.809: E/AndroidRuntime(13363): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
09-18 13:45:43.809: E/AndroidRuntime(13363): at android.os.Handler.dispatchMessage(Handler.java:99)
09-18 13:45:43.809: E/AndroidRuntime(13363): at android.os.Looper.loop(Looper.java:123)
09-18 13:45:43.809: E/AndroidRuntime(13363): at android.app.ActivityThread.main(ActivityThread.java:3687)
09-18 13:45:43.809: E/AndroidRuntime(13363): at java.lang.reflect.Method.invokeNative(Native Method)
09-18 13:45:43.809: E/AndroidRuntime(13363): at java.lang.reflect.Method.invoke(Method.java:507)
09-18 13:45:43.809: E/AndroidRuntime(13363): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
09-18 13:45:43.809: E/AndroidRuntime(13363): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
09-18 13:45:43.809: E/AndroidRuntime(13363): at dalvik.system.NativeStart.main(Native Method)

有什么想法吗?

编辑:我用其他方式解决了我的问题。刚刚将可绘制生成代码移至其他事件。但我很感兴趣,如果我尝试覆盖此方法,为什么我仍然会收到 VirtualMachineError。

更新:如果我从 View 扩展 MyButton,我会遇到同样的错误。

更新:

我发现了额外的消息:

09-19 09:24:43.789: W/dalvikvm(17401): Method Lcom/videoclasse/android/widgets/SubjectButton;.layout overrides final Landroid/view/View;.layout
09-19 09:24:43.789: W/dalvikvm(17401): failed creating vtable
09-19 09:24:43.789: W/dalvikvm(17401): Link of class 'Lcom/videoclasse/android/widgets/SubjectButton;' failed

终于在android 2.3.3中找到了。 View.layout 被定义为:

public final void layout(int l, int t, int r, int b) {
boolean changed = setFrame(l, t, r, b);
if (changed || (mPrivateFlags & LAYOUT_REQUIRED) == LAYOUT_REQUIRED) {
if (ViewDebug.TRACE_HIERARCHY) {
ViewDebug.trace(this, ViewDebug.HierarchyTraceType.ON_LAYOUT);
}

onLayout(changed, l, t, r, b);
mPrivateFlags &= ~LAYOUT_REQUIRED;
}
mPrivateFlags &= ~FORCE_LAYOUT;
}

抱歉这个愚蠢的问题。

最佳答案

在安卓 2.3.3 中。 View.layout 被定义为最终的。但在 android 4.0 中,此功能不再是最终版本。我收到此错误的原因是因为我使用的是 4.0.0 生成器。

感谢@WarrenFaith 发现了代码中的错误输入,非常感谢@JesusFreke 给出了搜索更多信息的方向。

关于android - 重写 View.layout(...) 时出现 VirtualMachineError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12475770/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com