0

这是代码:

for (int i = 0; i < patharry.length; i++) { 

            String kik = patharry[i];
            int chckvalue = kik.length();

            if (chckvalue > 1){

正是这个“if”语句给出了 java.lang.NullPointerException 错误……你能告诉我为什么吗?什么是好的解决方法?我尝试查看 java 文档,但找不到任何东西。

这是整个错误:

10-16 15:52:09.286: E/AndroidRuntime(1521): FATAL EXCEPTION: main
10-16 15:52:09.286: E/AndroidRuntime(1521): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.customcalenderandroid/com.example.show_all.show_all}: java.lang.NullPointerException
10-16 15:52:09.286: E/AndroidRuntime(1521):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
10-16 15:52:09.286: E/AndroidRuntime(1521):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
10-16 15:52:09.286: E/AndroidRuntime(1521):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
10-16 15:52:09.286: E/AndroidRuntime(1521):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
10-16 15:52:09.286: E/AndroidRuntime(1521):     at android.os.Handler.dispatchMessage(Handler.java:99)
10-16 15:52:09.286: E/AndroidRuntime(1521):     at android.os.Looper.loop(Looper.java:137)
10-16 15:52:09.286: E/AndroidRuntime(1521):     at android.app.ActivityThread.main(ActivityThread.java:5041)
10-16 15:52:09.286: E/AndroidRuntime(1521):     at java.lang.reflect.Method.invokeNative(Native Method)
10-16 15:52:09.286: E/AndroidRuntime(1521):     at java.lang.reflect.Method.invoke(Method.java:511)
10-16 15:52:09.286: E/AndroidRuntime(1521):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
10-16 15:52:09.286: E/AndroidRuntime(1521):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
10-16 15:52:09.286: E/AndroidRuntime(1521):     at dalvik.system.NativeStart.main(Native Method)
10-16 15:52:09.286: E/AndroidRuntime(1521): Caused by: java.lang.NullPointerException
10-16 15:52:09.286: E/AndroidRuntime(1521):     at com.example.show_all.show_all.createData(show_all.java:82)
10-16 15:52:09.286: E/AndroidRuntime(1521):     at com.example.show_all.show_all.onCreate(show_all.java:40)
10-16 15:52:09.286: E/AndroidRuntime(1521):     at android.app.Activity.performCreate(Activity.java:5104)
10-16 15:52:09.286: E/AndroidRuntime(1521):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
10-16 15:52:09.286: E/AndroidRuntime(1521):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
10-16 15:52:09.286: E/AndroidRuntime(1521):     ... 11 more
4

1 回答 1

0

可能是错误在这一行:int chckvalue = kik.length(); 因为 kik 将为空。调试您的代码并找出问题所在。如果您找不到,请将代码发送给我,我会检查它。

于 2013-10-16T16:07:13.150 回答