我正在做一個項目,要求在應用程序中顯示最高級別的地震。我遇到的問題是for循環崩潰了應用程序。如果我採取循環,我會得到顯示的最低震級。android for loop magnitude array
我檢查了logcat,但沒有給我任何線索爲什麼。所以我要求我想要一些幫助指向我的方向來解決這個問題。
感謝您的幫助
這裏是代碼按鈕
private void DisplayInfo(String result){
try{
JSONObject jsonObject = new JSONObject(result);
JSONArray arr = new JSONArray(jsonObject.getString("earthquakes"));
for (int a = 0; a<arr.length(); a++){
JSONObject element = arr.getJSONObject(a);
//Toast.makeText(getBaseContext(), element.getString("magnitude"), Toast.LENGTH_LONG).show();
int[] magnitude = new int[]{0};
Arrays.sort(magnitude);
int max = magnitude[magnitude.length - 1];
for(int i =0; i < magnitude.length; i++){
if(magnitude[i] > max){
max = magnitude[i];
// Toast.makeText(getBaseContext(), element.getString("hello World") + max, Toast.LENGTH_LONG).show();
String value;
value = "Country Name: " + element.getString("src")
+ ("\n") + "Date & Time: " + element.getString("datetime")
+ ("\n") + "Magnitude: " + element.getString("magnitude");
TextView text = new TextView (this);
text.setText(value);
setContentView(text);
Log.d ("String Value >>>>>", value);
}
}
}
}
logcat的點擊了
01-09 00:09:45.868: D/Button Click ok(1383): http://api.geonames.org/earthquakesJSON?north=44.1&south=-9.9&east=-22.4&west=55.2&username=demo
01-09 00:09:47.928: D/dalvikvm(1383): GC_FOR_ALLOC freed 203K, 13% free 2799K/3200K, paused 35ms, total 38ms
01-09 00:10:05.738: E/SoundPool(278): error loading /system/media/audio/ui/Effect_Tick.ogg
01-09 00:10:05.738: W/AudioService(278): Soundpool could not load file: /system/media/audio/ui/Effect_Tick.ogg
01-09 00:10:05.738: E/SoundPool(278): error loading /system/media/audio/ui/Effect_Tick.ogg
01-09 00:10:05.738: W/AudioService(278): Soundpool could not load file: /system/media/audio/ui/Effect_Tick.ogg
01-09 00:10:05.738: E/SoundPool(278): error loading /system/media/audio/ui/Effect_Tick.ogg
01-09 00:10:05.748: W/AudioService(278): Soundpool could not load file: /system/media/audio/ui/Effect_Tick.ogg
01-09 00:10:05.758: E/SoundPool(278): error loading /system/media/audio/ui/Effect_Tick.ogg
01-09 00:10:05.758: W/AudioService(278): Soundpool could not load file: /system/media/audio/ui/Effect_Tick.ogg
01-09 00:10:05.758: E/SoundPool(278): error loading /system/media/audio/ui/Effect_Tick.ogg
01-09 00:10:05.768: D/Button Click ok(1383): http://api.geonames.org/earthquakesJSON?north=44.1&south=-9.9&east=-22.4&west=55.2&username=demo
01-09 00:10:05.778: W/AudioService(278): Soundpool could not load file: /system/media/audio/ui/Effect_Tick.ogg
01-09 00:10:05.778: E/SoundPool(278): error loading /system/media/audio/ui/KeypressStandard.ogg
01-09 00:10:05.778: W/AudioService(278): Soundpool could not load file: /system/media/audio/ui/KeypressStandard.ogg
01-09 00:10:05.778: E/SoundPool(278): error loading /system/media/audio/ui/KeypressSpacebar.ogg
01-09 00:10:05.808: W/AudioService(278): Soundpool could not load file: /system/media/audio/ui/KeypressSpacebar.ogg
01-09 00:10:05.808: E/SoundPool(278): error loading /system/media/audio/ui/KeypressDelete.ogg
01-09 00:10:05.808: W/AudioService(278): Soundpool could not load file: /system/media/audio/ui/KeypressDelete.ogg
01-09 00:10:05.808: E/SoundPool(278): error loading /system/media/audio/ui/KeypressReturn.ogg
01-09 00:10:05.838: W/AudioService(278): Soundpool could not load file: /system/media/audio/ui/KeypressReturn.ogg
01-09 00:10:05.848: W/AudioService(278): onLoadSoundEffects(), Error -1 while loading samples
你可以複製LogCat數據與帖子 – Alok