同様の問題を検索してこの問題を解決しようとしましたが、初心者の質問かもしれません。問題は、長いループを開始するたびにクラッシュすることです!
たとえば、TextView
テキストを 0 に設定し、ループを実行して値を 10 まで増やしたい場合、クラッシュします。スレッドを使用しても、まだクラッシュします。
これが私のコードです:
package com.example.mathexercises;
import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.os.Handler;
import android.text.format.Time;
import android.widget.ProgressBar;
import android.widget.TextView;
public class level1 extends Activity {
TextView QuestionLable;
TextView TimeLable;
int QandA[][];
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.level1);
QuestionLable = (TextView) findViewById(R.id.Level1QuestionLable);
TimeLable = (TextView) findViewById(R.id.Level1Time);
QandA =(int[][]) savedInstanceState.get("ArrayOfExer");
int sum=0;
String Qformated="";
TimeLable.setText("Started !!");
for (int i = 0; QandA !=null && i<QandA.length; i++) {
try {
Qformated = "" + QandA[i][0];
switch (QandA[i][1]) {
case -1:
Qformated += " +";
break;
case -2:
Qformated += " -";
break;
case -3:
Qformated += " X";
break;
case -4:
Qformated += " /";
break;
}
Qformated += " " + QandA[i][2];
sum+=QandA[i][3];
QuestionLable.setText(Qformated);
} catch (Exception e) {
System.out.println(e.getMessage());
i--;
}
}
}
}
logCat
06-04 01:24:42.875: D/dalvikvm(24925): Late-enabling CheckJNI
06-04 01:24:43.275: D/libEGL(24925): loaded /system/lib/egl/libEGL_mali.so
06-04 01:24:43.300: D/libEGL(24925): loaded /system/lib/egl/libGLESv1_CM_mali.so
06-04 01:24:43.305: D/libEGL(24925): loaded /system/lib/egl/libGLESv2_mali.so
06-04 01:24:43.365: D/(24925): Device driver API match
06-04 01:24:43.365: D/(24925): Device driver API version: 10
06-04 01:24:43.365: D/(24925): User space API version: 10
06-04 01:24:43.365: D/(24925): mali: REVISION=Linux-r2p4-02rel0 BUILD_DATE=Tue Oct 16 15:37:13 KST 2012
06-04 01:24:43.425: D/OpenGLRenderer(24925): Enabling debug mode 0
06-04 01:24:43.485: E/SensorManager(24925): thread start
06-04 01:24:43.500: D/SensorManager(24925): registerListener :: handle = 0 name= LSM330DLC 3-axis Accelerometer delay= 200000 Listener= android.view.OrientationEventListener$SensorEventListenerImpl@429e4a30
06-04 01:24:50.705: D/AndroidRuntime(24925): Shutting down VM
06-04 01:24:50.705: W/dalvikvm(24925): threadid=1: thread exiting with uncaught exception (group=0x41d692a0)
06-04 01:24:50.715: E/AndroidRuntime(24925): FATAL EXCEPTION: main
06-04 01:24:50.715: E/AndroidRuntime(24925): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mathexercises/com.example.mathexercises.level1}: java.lang.NullPointerException
06-04 01:24:50.715: E/AndroidRuntime(24925): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2100)
06-04 01:24:50.715: E/AndroidRuntime(24925): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
06-04 01:24:50.715: E/AndroidRuntime(24925): at android.app.ActivityThread.access$600(ActivityThread.java:140)
06-04 01:24:50.715: E/AndroidRuntime(24925): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
06-04 01:24:50.715: E/AndroidRuntime(24925): at android.os.Handler.dispatchMessage(Handler.java:99)
06-04 01:24:50.715: E/AndroidRuntime(24925): at android.os.Looper.loop(Looper.java:137)
06-04 01:24:50.715: E/AndroidRuntime(24925): at android.app.ActivityThread.main(ActivityThread.java:4898)
06-04 01:24:50.715: E/AndroidRuntime(24925): at java.lang.reflect.Method.invokeNative(Native Method)
06-04 01:24:50.715: E/AndroidRuntime(24925): at java.lang.reflect.Method.invoke(Method.java:511)
06-04 01:24:50.715: E/AndroidRuntime(24925): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
06-04 01:24:50.715: E/AndroidRuntime(24925): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
06-04 01:24:50.715: E/AndroidRuntime(24925): at dalvik.system.NativeStart.main(Native Method)
06-04 01:24:50.715: E/AndroidRuntime(24925): Caused by: java.lang.NullPointerException
06-04 01:24:50.715: E/AndroidRuntime(24925): at com.example.mathexercises.level1.onCreate(level1.java:26)
06-04 01:24:50.715: E/AndroidRuntime(24925): at android.app.Activity.performCreate(Activity.java:5206)
06-04 01:24:50.715: E/AndroidRuntime(24925): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1083)
06-04 01:24:50.715: E/AndroidRuntime(24925): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
06-04 01:24:50.715: E/AndroidRuntime(24925): ... 11 more
*お時間をいただきありがとうございます