私は何をしようとしているのかというとかなりシンプルですが、PHPのバックグラウンドから来ています(あなたが知っているのは、 。基本的に私のリストに追加できない、NullPointerExceptionをスローする
、HERESに私のログ:
12-06 15:45:18.282: D/MAPVIEW(32047): Matching Providers are: [network, gps]
12-06 15:45:18.282: D/MAPVIEW(32047): Um, whats the best provder? Well its obviously 'network'
12-06 15:45:18.753: D/MAPVIEW(32047): Location Data: Lat:49, Long: -116
12-06 15:45:18.753: D/MAPVIEW(32047): Could not add coordinate array to List, Error: java.lang.NullPointerException
12-06 15:45:18.753: D/MAPVIEW(32047): Location Data: Lat:50, Long: -116
12-06 15:45:18.753: D/MAPVIEW(32047): Could not add coordinate array to List, Error: java.lang.NullPointerException
12-06 15:45:18.753: D/MAPVIEW(32047): Location Data: Lat:49, Long: -117
12-06 15:45:18.753: D/MAPVIEW(32047): Could not add coordinate array to List, Error: java.lang.NullPointerException
12-06 15:45:18.753: D/MAPVIEW(32047): Location Data: Lat:49, Long: -115
12-06 15:45:18.753: D/MAPVIEW(32047): Could not add coordinate array to List, Error: java.lang.NullPointerException
12-06 15:45:18.753: D/MAPVIEW(32047): Location Data: Lat:49, Long: -117
12-06 15:45:18.753: D/MAPVIEW(32047): Could not add coordinate array to List, Error: java.lang.NullPointerException
12-06 15:45:18.753: D/MAPVIEW(32047): Location Data: Lat:49, Long: -117
12-06 15:45:18.763: D/MAPVIEW(32047): Could not add coordinate array to List, Error: java.lang.NullPointerException
12-06 15:45:18.763: D/MAPVIEW(32047): Location Data: Lat:50, Long: -115
12-06 15:45:18.763: D/MAPVIEW(32047): Could not add coordinate array to List, Error: java.lang.NullPointerException
12-06 15:45:18.763: D/MAPVIEW(32047): Location Data: Lat:49, Long: -116
12-06 15:45:18.763: D/MAPVIEW(32047): Could not add coordinate array to List, Error: java.lang.NullPointerException
12-06 15:45:18.763: D/MAPVIEW(32047): Location Data: Lat:50, Long: -118
12-06 15:45:18.763: D/MAPVIEW(32047): Could not add coordinate array to List, Error: java.lang.NullPointerException
12-06 15:45:18.763: D/MAPVIEW(32047): Location Data: Lat:49, Long: -114
12-06 15:45:18.783: D/MAPVIEW(32047): Could not add coordinate array to List, Error: java.lang.NullPointerException
12-06 15:45:18.783: D/AndroidRuntime(32047): Shutting down VM
12-06 15:45:18.783: W/dalvikvm(32047): threadid=1: thread exiting with uncaught exception (group=0x4001d5a0)
私は座標のリストに追加しようとしている、とトライキャッチが例外をキャッチされていることがわかります。 は(!私はそれを取得しますカントー今のクラッシュを心配しないでください。)
をあまりにも多く、さらにadeuせず、HERESに私の関連するコード:
package com.private.clientndablocked;
// ... imports
public class ShowMapView extends MapActivity {
// ... some initializers
List<int[]> allLocations;
@Override
protected boolean isRouteDisplayed() {
return false;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// .. whole bunch of other unreleated stuff
// A single json object, this gets populated with cherry picked json array items
JSONObject obj = null;
// go through each of the items in the json array
for(int i = 0; i < json.length(); i++) {
try {
// We must try to get the object first
obj = (JSONObject) json.get(i);
} catch (JSONException e) {
e.printStackTrace();
}
// Initialize temp data with defaults
int Latitude = 0;
int Longitude = 0;
String Title = "";
String ID = "";
int[] coords = new int[2];
// So we actually have a picked item?
if(obj != null)
try {
// Lets try to assign the temp vars with their real data
Latitude = (int) (obj.getDouble("lat") * 1e6);
Longitude = (int) (obj.getDouble("long") * 1e6);
Title = (String) (obj.getString("title"));
ID = (String) (obj.getString("id"));
// Save the lat and long of the new location data (non micro)
// This stuff goes into allLocations List
coords[0] = obj.getInt("lat");
coords[1] = obj.getInt("long");
} catch (JSONException e) {
e.printStackTrace();
}
// Create a new GeoPoint to store the microdegrees into
GeoPoint point = new GeoPoint(
Latitude,
Longitude
);
// Create a new OverlayItem with the GeoPoint and a title and snippet
OverlayItem overlayitem = new OverlayItem(
point,
Title,
ID
);
itemizedoverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedoverlay);
Log.d("MAPVIEW", "Location Data: Lat:" + coords[0] + ", Long: " + coords[1]);
try{
allLocations.add(coords); // ************* this is whats failing ******************
} catch(Exception e) {
Log.d("MAPVIEW", "Could not add coordinate array to List, Error: " + e.toString());
}
}
// ... whole bunch more unrelated stuff
}
今
取得する唯一のものを私が追加したときに少し違うのは、大きなforループjson抽出プログラムの上に
allLocations = Arrays.asList();
です。これにより、プログラムはUnsupportedOperationExceptionをスローします。
正直なところ、私は何をすべきか分かりません。 ..
私はリストを考え出したと思ったが、明らかに私は
(PSを:(ません:私は
int minLat = Integer.MAX_VALUE;
int maxLat = Integer.MIN_VALUE;
int minLon = Integer.MAX_VALUE;
int maxLon = Integer.MIN_VALUE;
for (int[] l : allLocations) {
int lat = (int) l[0];
int lon = (int) l[1];
maxLat = Math.max(lat, maxLat);
minLat = Math.min(lat, minLat);
maxLon = Math.max(lon, maxLon);
minLon = Math.min(lon, minLon);
}
AH !!そこに行く!私はそれをやろうとしましたが、かなり新しくなっています。私は最終的に型を入力したときにEclipse全体がこのオーバーライドメソッドを作成していたので、どこかで構文が乱れているはずです。間違ったパス:( 超高速応答ありがとう! – RedactedProfile
私はちょうど1時間のキャスティングやその他の必須ではないものをやっていました.Phpはとても簡単ですが、私は認めなければなりません。甘い。 – frostymarvelous