每当我不时地弄乱相对布局的位置时,我的app力就会关闭。我必须随意重新定位它们,让应用程序再次运行。或者将它们全部放在最左上角,然后重新排列它们。
我正在使用Eclipse。
为什么会这样?有没有办法可以避免这种情况?
[编辑]
07-22 21:39:22.042:D / dalvikvm(520):GC_EXTERNAL_ALLOC释放291K,52% 免费2718K / 5639K,外部741K / 1038K,暂停51ms
07-22 21:39:22.422:D / AndroidRuntime(520):关闭VM 07-22 21:39:22.432:W / dalvikvm(520):threadid = 1:线程退出 未捕获的异常(组= 0x40015560)
07-22 21:39:22.443:E / AndroidRuntime(520):致命异常:主要 07-22 21:39:22.443:E / AndroidRuntime(520):java.lang.RuntimeException: 无法开始活动
ComponentInfo {com.android.tapme / com.android.tapme.TapMe}: java.lang.ClassCastException:android.widget.TextView
07-22 21:39:22.443:E / AndroidRuntime(520):at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
07-22 21:39:22.443:E / AndroidRuntime(520):at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
07-22 21:39:22.443:E / AndroidRuntime(520):at android.app.ActivityThread.access $ 1500(ActivityThread.java:117)
07-22 21:39:22.443:E / AndroidRuntime(520):at android.app.ActivityThread $ H.handleMessage(ActivityThread.java:931)
07-22 21:39:22.443:E / AndroidRuntime(520):at android.os.Handler.dispatchMessage(Handler.java:99)
07-22 21:39:22.443:E / AndroidRuntime(520):at android.os.Looper.loop(Looper.java:123)
07-22 21:39:22.443:E / AndroidRuntime(520):at android.app.ActivityThread.main(ActivityThread.java:3683)
07-22 21:39:22.443:E / AndroidRuntime(520):at java.lang.reflect.Method.invokeNative(Native Method)
07-22 21:39:22.443:E / AndroidRuntime(520):at java.lang.reflect.Method.invoke(Method.java:507)
07-22 21:39:22.443:E / AndroidRuntime(520):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:839)
07-22 21:39:22.443:E / AndroidRuntime(520):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
07-22 21:39:22.443:E / AndroidRuntime(520):at dalvik.system.NativeStart.main(原生方法)
07-22 21:39:22.443:E / AndroidRuntime(520):引起: java.lang.ClassCastException:android.widget.TextView
07-22 21:39:22.443:E / AndroidRuntime(520):at com.android.tapme.TapMe.onCreate(TapMe.java:26)
07-22 21:39:22.443:E / AndroidRuntime(520):at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-22 21:39:22.443:E / AndroidRuntime(520):at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611) 07-22 21:39:22.443:E / AndroidRuntime(520):... 11更多
[编辑]
我随机编辑了布局,最后让它工作了。然后我添加了一个进度条,瞧!再次强制关闭错误。这是日志。
07-26 00:06:57.445:D / AndroidRuntime(876):关闭虚拟机
07-26 00:06:57.465:W / dalvikvm(876):threadid = 1:线程退出时未捕获异常(组= 0x40015560)
07-26 00:06:57.486:E / AndroidRuntime(876):致命异常:主
07-26 00:06:57.486:E / AndroidRuntime(876):java.lang.RuntimeException:无法实例化活动ComponentInfo {com.android.tapme / com.android.tapme.TapMe}:java.lang。的NullPointerException
07-26 00:06:57.486:E / AndroidRuntime(876):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1569)
07-26 00:06:57.486:E / AndroidRuntime(876):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
07-26 00:06:57.486:E / AndroidRuntime(876):在android.app.ActivityThread.access $ 1500(ActivityThread.java:117)
07-26 00:06:57.486:E / AndroidRuntime(876):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:931)
07-26 00:06:57.486:E / AndroidRuntime(876):在android.os.Handler.dispatchMessage(Handler.java:99)
07-26 00:06:57.486:E / AndroidRuntime(876):在android.os.Looper.loop(Looper.java:123)
07-26 00:06:57.486:E / AndroidRuntime(876):在android.app.ActivityThread.main(ActivityThread.java:3683)
07-26 00:06:57.486:E / AndroidRuntime(876):at java.lang.reflect.Method.invokeNative(Native Method)
07-26 00:06:57.486:E / AndroidRuntime(876):at java.lang.reflect.Method.invoke(Method.java:507)
07-26 00:06:57.486:E / AndroidRuntime(876):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:839)
07-26 00:06:57.486:E / AndroidRuntime(876):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
07-26 00:06:57.486:E / AndroidRuntime(876):at dalvik.system.NativeStart.main(Native Method)
07-26 00:06:57.486:E / AndroidRuntime(876):引起:java.lang.NullPointerException
07-26 00:06:57.486:E / AndroidRuntime(876):在android.app.Activity.findViewById(Activity.java:1647)
07-26 00:06:57.486:E / AndroidRuntime(876):at com.android.tapme.TapMe。(TapMe.java:17)
07-26 00:06:57.486:E / AndroidRuntime(876):at java.lang.Class.newInstanceImpl(Native Method)
07-26 00:06:57.486:E / AndroidRuntime(876):at java.lang.Class.newInstance(Class.java:1409)
07-26 00:06:57.486:E / AndroidRuntime(876):在android.app.Instrumentation.newActivity(Instrumentation.java:1021)
07-26 00:06:57.486:E / AndroidRuntime(876):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561)
07-26 00:06:57.486:E / AndroidRuntime(876):... 11更多
答案 0 :(得分:0)
在RelativeLayout中,所有子元素都相对于彼此放置。
这是一个代码段。
android:layout_below="@id/elementOne"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="@+id/elementTwo"
所以,搞乱其中一个,你就搞乱了一切。