0
但我實現了在代碼中沒有錯誤,但是當我嘗試在模擬器中執行它說非常幸運的應用程序已停止。 問題必須在這一部分,因爲它僅停止時klassenNr = 6不幸的是,應用程序已停止,隨機數字崩潰
int zufallsNr1;
int zufallsNr2 = 300;
int zufallsNr3 = 300;
int zufallsNr4 = 300;
int zufallsNr5 = 300;
if (klassenNr == 6) {
Random zufall = new Random();
int zufallsNr1 = zufall.nextInt(name[4].length);
while (zufallsNr1 == zufallsNr2 && zufallsNr2 == 300) {
zufallsNr2 = zufall.nextInt(name[4].length);
}
while (zufallsNr3 == zufallsNr2 && zufallsNr3 == zufallsNr1 && zufallsNr3 == 300) {
zufallsNr3 = zufall.nextInt(name[4].length);
}
while (zufallsNr4 == zufallsNr2 && zufallsNr4 == zufallsNr1 && zufallsNr4 == zufallsNr3
&& zufallsNr4 == 300) {
zufallsNr4 = zufall.nextInt(name[4].length);
}
while (zufallsNr5 == zufallsNr2 && zufallsNr5 == zufallsNr1 && zufallsNr5 == zufallsNr3
&& zufallsNr5 == zufallsNr4 && zufallsNr5 == 300) {
zufallsNr5 = zufall.nextInt(name[4].length);
}
valuelist = new String[] { name[4][zufallsNr1],
name[4][zufallsNr2], name[4][zufallsNr3],
name[4][zufallsNr4], name[4][zufallsNr5] };
} else {
if (klassenNr == 5) {
valuelist = topographienamen;
} else {
valuelist = name[klassenNr];
}
}
300比名得多[4]。長度
logcat的:
05-30 01:46:09.725: I/ActivityManager(297): START u0 {cmp=com.jafapp.igeo/.FuenfteActivity (has extras)} from pid 12533
05-30 01:46:09.738: W/WindowManager(297): Failure taking screenshot for (328x583) to layer 21020
05-30 01:46:10.355: D/AndroidRuntime(12533): Shutting down VM
05-30 01:46:10.406: W/dalvikvm(12533): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
05-30 01:46:10.506: E/AndroidRuntime(12533): FATAL EXCEPTION: main
05-30 01:46:10.506: E/AndroidRuntime(12533): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.jafapp.igeo/com.jafapp.igeo.FuenfteActivity}: java.lang.ArrayIndexOutOfBoundsException: length=254; index=300
05-30 01:46:10.506: E/AndroidRuntime(12533): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
05-30 01:46:10.506: E/AndroidRuntime(12533): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
05-30 01:46:10.506: E/AndroidRuntime(12533): at android.app.ActivityThread.access$600(ActivityThread.java:141)
05-30 01:46:10.506: E/AndroidRuntime(12533): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
05-30 01:46:10.506: E/AndroidRuntime(12533): at android.os.Handler.dispatchMessage(Handler.java:99)
05-30 01:46:10.506: E/AndroidRuntime(12533): at android.os.Looper.loop(Looper.java:137)
05-30 01:46:10.506: E/AndroidRuntime(12533): at android.app.ActivityThread.main(ActivityThread.java:5041)
05-30 01:46:10.506: E/AndroidRuntime(12533): at java.lang.reflect.Method.invokeNative(Native Method)
05-30 01:46:10.506: E/AndroidRuntime(12533): at java.lang.reflect.Method.invoke(Method.java:511)
05-30 01:46:10.506: E/AndroidRuntime(12533): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
05-30 01:46:10.506: E/AndroidRuntime(12533): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
05-30 01:46:10.506: E/AndroidRuntime(12533): at dalvik.system.NativeStart.main(Native Method)
05-30 01:46:10.506: E/AndroidRuntime(12533): Caused by: java.lang.ArrayIndexOutOfBoundsException: length=254; index=300
05-30 01:46:10.506: E/AndroidRuntime(12533): at com.jafapp.igeo.FuenfteActivity.onCreate(FuenfteActivity.java:449)
05-30 01:46:10.506: E/AndroidRuntime(12533): at android.app.Activity.performCreate(Activity.java:5104)
05-30 01:46:10.506: E/AndroidRuntime(12533): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
05-30 01:46:10.506: E/AndroidRuntime(12533): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
05-30 01:46:10.506: E/AndroidRuntime(12533): ... 11 more
05-30 01:46:10.585: W/ActivityManager(297): Force finishing activity com.jafapp.igeo/.FuenfteActivity
05-30 01:46:10.645: W/ActivityManager(297): Force finishing activity com.jafapp.igeo/.KlassenlisteActivity
05-30 01:46:11.189: W/ActivityManager(297): Activity pause timeout for ActivityRecord{40fbe7f0 u0 com.jafapp.igeo/.FuenfteActivity}
05-30 01:46:11.255: E/SurfaceFlinger(37): ro.sf.lcd_density must be defined as a build property
05-30 01:46:11.775: E/SurfaceFlinger(37): ro.sf.lcd_density must be defined as a build property
將您的堆棧跟蹤從log cat複製到這裏。 – Trinimon
也許愚蠢的問題,但...怎麼樣? – user3047349
FuenfteActivity的449行是什麼?那裏發生了錯誤。 – tcooc