执行LinearLayout.addView时查看IllegalStateException(View)

时间:2014-06-13 18:23:38

标签: android android-layout android-linearlayout illegalstateexception

所以我试图在buttonclick上添加一个视图,但是它会抛出IllegalStateException。我将此视图添加到LinearLayout内部的LinearLayout,它在活动开始时显示。

这是日志:

06-13 20:05:20.415  12368-12368/com.nttkjwmp.syncc.app V/Zygote﹕ Switching descriptor 9 to /dev/null
06-13 20:05:20.420  12368-12368/com.nttkjwmp.syncc.app D/dalvikvm﹕ Late-enabling CheckJNI
06-13 20:05:20.495  12368-12368/com.nttkjwmp.syncc.app D/ActivityThread﹕ handleBindApplication:com.nttkjwmp.syncc.app
06-13 20:05:20.495  12368-12368/com.nttkjwmp.syncc.app D/ActivityThread﹕ setTargetHeapUtilization:0.75
06-13 20:05:20.495  12368-12368/com.nttkjwmp.syncc.app D/ActivityThread﹕ setTargetHeapMinFree:2097152
06-13 20:05:20.925  12368-12368/com.nttkjwmp.syncc.app D/libEGL﹕ loaded /system/lib/egl/libEGL_mali.so
06-13 20:05:20.930  12368-12368/com.nttkjwmp.syncc.app D/libEGL﹕ loaded /system/lib/egl/libGLESv1_CM_mali.so
06-13 20:05:20.935  12368-12368/com.nttkjwmp.syncc.app D/libEGL﹕ loaded /system/lib/egl/libGLESv2_mali.so
06-13 20:05:20.940  12368-12368/com.nttkjwmp.syncc.app E/﹕ Device driver API match
    Device driver API version: 23
    User space API version: 23
06-13 20:05:20.940  12368-12368/com.nttkjwmp.syncc.app E/﹕ mali: REVISION=Linux-r3p2-01rel3 BUILD_DATE=Wed Oct  9 21:05:57 KST 2013
06-13 20:05:21.005  12368-12368/com.nttkjwmp.syncc.app D/OpenGLRenderer﹕ Enabling debug mode 0
06-13 20:05:21.415  12368-12368/com.nttkjwmp.syncc.app I/Timeline﹕ Timeline: Activity_idle id: android.os.BinderProxy@41b6cf08 time:2108923
06-13 20:05:27.535  12368-12368/com.nttkjwmp.syncc.app I/Timeline﹕ Timeline: Activity_launch_request id:com.nttkjwmp.syncc.app time:2115041
06-13 20:05:28.185  12368-12368/com.nttkjwmp.syncc.app E/SpannableStringBuilder﹕ SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
06-13 20:05:28.185  12368-12368/com.nttkjwmp.syncc.app E/SpannableStringBuilder﹕ SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
06-13 20:05:28.185  12368-12368/com.nttkjwmp.syncc.app I/Timeline﹕ Timeline: Activity_idle id: android.os.BinderProxy@41dd3b68 time:2115693
06-13 20:05:30.830  12368-12368/com.nttkjwmp.syncc.app D/AndroidRuntime﹕ Shutting down VM
06-13 20:05:30.830  12368-12368/com.nttkjwmp.syncc.app W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x418b4ce0)
06-13 20:05:30.840  12368-12368/com.nttkjwmp.syncc.app E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.nttkjwmp.syncc.app, PID: 12368
    java.lang.IllegalStateException: Could not execute method of the activity
            at android.view.View$1.onClick(View.java:3830)
            at android.view.View.performClick(View.java:4445)
            at android.view.View$PerformClick.run(View.java:18446)
            at android.os.Handler.handleCallback(Handler.java:733)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5128)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:611)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.reflect.InvocationTargetException
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at android.view.View$1.onClick(View.java:3825)
            at android.view.View.performClick(View.java:4445)
            at android.view.View$PerformClick.run(View.java:18446)
            at android.os.Handler.handleCallback(Handler.java:733)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5128)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:611)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.NullPointerException
            at com.nttkjwmp.syncc.app.NewEventActivity.addReminder(NewEventActivity.java:104)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at android.view.View$1.onClick(View.java:3825)
            at android.view.View.performClick(View.java:4445)
            at android.view.View$PerformClick.run(View.java:18446)
            at android.os.Handler.handleCallback(Handler.java:733)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5128)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:611)
            at dalvik.system.NativeStart.main(Native Method)
06-13 20:05:32.365  12368-12368/com.nttkjwmp.syncc.app I/Process﹕ Sending signal. PID: 12368 SIG: 9
06-13 20:05:32.470  12740-12740/com.nttkjwmp.syncc.app D/ActivityThread﹕ handleBindApplication:com.nttkjwmp.syncc.app
06-13 20:05:32.475  12740-12740/com.nttkjwmp.syncc.app D/ActivityThread﹕ setTargetHeapUtilization:0.75
06-13 20:05:32.475  12740-12740/com.nttkjwmp.syncc.app D/ActivityThread﹕ setTargetHeapMinFree:2097152
06-13 20:05:32.700  12740-12740/com.nttkjwmp.syncc.app D/libEGL﹕ loaded /system/lib/egl/libEGL_mali.so
06-13 20:05:32.700  12740-12740/com.nttkjwmp.syncc.app D/libEGL﹕ loaded /system/lib/egl/libGLESv1_CM_mali.so
06-13 20:05:32.705  12740-12740/com.nttkjwmp.syncc.app D/libEGL﹕ loaded /system/lib/egl/libGLESv2_mali.so
06-13 20:05:32.710  12740-12740/com.nttkjwmp.syncc.app E/﹕ Device driver API match
    Device driver API version: 23
    User space API version: 23
06-13 20:05:32.710  12740-12740/com.nttkjwmp.syncc.app E/﹕ mali: REVISION=Linux-r3p2-01rel3 BUILD_DATE=Wed Oct  9 21:05:57 KST 2013
06-13 20:05:32.775  12740-12740/com.nttkjwmp.syncc.app D/OpenGLRenderer﹕ Enabling debug mode 0
06-13 20:05:33.070  12740-12740/com.nttkjwmp.syncc.app I/Timeline﹕ Timeline: Activity_idle id: android.os.BinderProxy@41b72bf8 time:2120575

这里也是按钮的onClick方法:

public void addReminder(View view){
    View reminder=(View)findViewById(R.id.reminder_layout);
    reminderContainer.addView(reminder);
    reminders.add(reminder);
}

reminderContainer是我要添加视图的LinearLayout。它在另一个LinearLayout内。

这里是reminder_layout.xml文件:

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/reminder_layout"
    >

    <Spinner
        android:id="@+id/reminder_time"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        />

    <Spinner
        android:id="@+id/reminder_type"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        />

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_action_remove"
        />

</LinearLayout>

那么有谁可以指出错误?我在这里缺少什么?

提前致谢!

0 个答案:

没有答案