すべての行に gps 座標を含むファイルがあります。
9.34669876098644,48.2405319213867
9.36384963989269,48.2296714782715
9.3639497756958,48.2259712219238
9.36956977844238,48.2260589599609
9.36404991149908,48.2222709655763
9.36975955963135,48.2186508178712
今、ファイルを解析してジオポイントを作成したいと思います。まず、ファイルを開いて行を読み取り、行を分割して文字列をintにします。しかし、 Log.d("4:",point_t[0] + " - " + point_t[1]); の後に NullPointerException が発生しました。
try{
InputStream koord = getAssets().open("bib.txt");
if (koord != null) {
InputStreamReader input = new InputStreamReader(koord);
BufferedReader buffreader = new BufferedReader(input);
Log.d("2: ", "Read File");
String line;
while (( line = buffreader.readLine()) != null) {
Log.d("3: ", line);
String[] point_t = line.split(",");
Log.d("4:",point_t[0] + " - " + point_t[1]);
int x = Integer.parseInt(point_t[0]);
int y = Integer.parseInt(point_t[1]);
Log.d("Geopoint:",x + " - " + y);
points.add(new GeoPoint((int)(x*1e6), (int)(y*1e6)));
Log.d("5:","saved");
}
koord.close();
polygon = new Polygon(points);
}
}catch (Exception e) {
// TODO: handle exception
}
06-20 08:45:21.701: E/ActivityThread(231): Failed to find provider info for com.google.settings
06-20 08:45:21.711: E/ActivityThread(231): Failed to find provider info for com.google.settings
06-20 08:45:21.721: E/ActivityThread(231): Failed to find provider info for com.google.settings
06-20 08:45:21.971: D/dalvikvm(231): GC freed 3008 objects / 190136 bytes in 60ms
06-20 08:45:22.071: D/Checkpoint:(231): Start ArrayList
06-20 08:45:22.081: I/global(231): Default buffer size used in BufferedReader constructor. It would be better to be explicit if an 8k-char buffer is required.
06-20 08:45:22.081: D/Checkpoint:(231): Read File
06-20 08:45:22.081: D/Checkpoint:(231): 9.34669876098644,48.2405319213867
06-20 08:45:22.081: D/Point:(231): 9.34669876098644 - 48.2405319213867
06-20 08:45:22.161: I/MapActivity(231): Handling network change notification:CONNECTED
06-20 08:45:22.171: E/MapActivity(231): Couldn't get connection factory client
06-20 08:45:22.381: D/dalvikvm(231): GC freed 983 objects / 342808 bytes in 62ms
06-20 08:45:22.391: D/AndroidRuntime(231): Shutting down VM
06-20 08:45:22.401: W/dalvikvm(231): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
06-20 08:45:22.401: E/AndroidRuntime(231): Uncaught handler: thread main exiting due to uncaught exception
06-20 08:45:22.425: E/AndroidRuntime(231): java.lang.NullPointerException
06-20 08:45:22.425: E/AndroidRuntime(231): at com.google.android.maps.OverlayBundle.draw(OverlayBundle.java:42)
06-20 08:45:22.425: E/AndroidRuntime(231): at com.google.android.maps.MapView.onDraw(MapView.java:476)
06-20 08:45:22.425: E/AndroidRuntime(231): at android.view.View.draw(View.java:6535)
06-20 08:45:22.425: E/AndroidRuntime(231): at android.view.ViewGroup.drawChild(ViewGroup.java:1531)
06-20 08:45:22.425: E/AndroidRuntime(231): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
06-20 08:45:22.425: E/AndroidRuntime(231): at android.view.ViewGroup.drawChild(ViewGroup.java:1529)
06-20 08:45:22.425: E/AndroidRuntime(231): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
06-20 08:45:22.425: E/AndroidRuntime(231): at android.view.View.draw(View.java:6641)
06-20 08:45:22.425: E/AndroidRuntime(231): at android.widget.FrameLayout.draw(FrameLayout.java:352)
06-20 08:45:22.425: E/AndroidRuntime(231): at android.view.ViewGroup.drawChild(ViewGroup.java:1531)
06-20 08:45:22.425: E/AndroidRuntime(231): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
06-20 08:45:22.425: E/AndroidRuntime(231): at android.view.View.draw(View.java:6538)
06-20 08:45:22.425: E/AndroidRuntime(231): at android.widget.FrameLayout.draw(FrameLayout.java:352)
06-20 08:45:22.425: E/AndroidRuntime(231): at android.view.ViewGroup.drawChild(ViewGroup.java:1531)
06-20 08:45:22.425: E/AndroidRuntime(231): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
06-20 08:45:22.425: E/AndroidRuntime(231): at android.view.ViewGroup.drawChild(ViewGroup.java:1529)
06-20 08:45:22.425: E/AndroidRuntime(231): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
06-20 08:45:22.425: E/AndroidRuntime(231): at android.view.View.draw(View.java:6538)
06-20 08:45:22.425: E/AndroidRuntime(231): at android.widget.FrameLayout.draw(FrameLayout.java:352)
06-20 08:45:22.425: E/AndroidRuntime(231): at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1830)
06-20 08:45:22.425: E/AndroidRuntime(231): at android.view.ViewRoot.draw(ViewRoot.java:1349)
06-20 08:45:22.425: E/AndroidRuntime(231): at android.view.ViewRoot.performTraversals(ViewRoot.java:1114)
06-20 08:45:22.425: E/AndroidRuntime(231): at android.view.ViewRoot.handleMessage(ViewRoot.java:1633)
06-20 08:45:22.425: E/AndroidRuntime(231): at android.os.Handler.dispatchMessage(Handler.java:99)
06-20 08:45:22.425: E/AndroidRuntime(231): at android.os.Looper.loop(Looper.java:123)
06-20 08:45:22.425: E/AndroidRuntime(231): at android.app.ActivityThread.main(ActivityThread.java:4363)
06-20 08:45:22.425: E/AndroidRuntime(231): at java.lang.reflect.Method.invokeNative(Native Method)
06-20 08:45:22.425: E/AndroidRuntime(231): at java.lang.reflect.Method.invoke(Method.java:521)
06-20 08:45:22.425: E/AndroidRuntime(231): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
06-20 08:45:22.425: E/AndroidRuntime(231): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
06-20 08:45:22.425: E/AndroidRuntime(231): at dalvik.system.NativeStart.main(Native Method)
06-20 08:45:22.442: I/dalvikvm(231): threadid=7: reacting to signal 3
06-20 08:45:22.461: I/dalvikvm(231): Wrote stack trace to '/data/anr/traces.txt'
06-20 08:45:24.701: I/Process(231): Sending signal. PID: 231 SIG: 9
@スタックレス
Log.d("1: ", "Start ArrayList");
ArrayList<GeoPoint> points = new ArrayList<GeoPoint>();
try{
InputStream koord = getAssets().open("bib.txt");
if (koord != null) {
InputStreamReader input = new InputStreamReader(koord);
BufferedReader buffreader = new BufferedReader(input);
Log.d("2: ", "Read File");
String line;
while (( line = buffreader.readLine()) != null) {
Log.d("3: ", line);
String[] point_t = line.split(",");
Log.d("4:",point_t[0] + " - " + point_t[1]);
double x = Double.parseDouble(point_t[0]);
double y = Double.parseDouble(point_t[1]);
Log.d("Geopoint:",x + " - " + y);
points.add(new GeoPoint((int)(x*1e6), (int)(y*1e6)));
Log.d("5:","saved");
}
koord.close();
polygon = new Polygon(points);
}
}catch (Exception e) {
Log.e("APP","Failed", e);
}
mapView.getOverlays().clear();
mapView.getOverlays().add(polygon);
mapView.invalidate();
}
エラー:
06-20 09:47:27.382: E/ActivityThread(324): Failed to find provider info for com.google.settings
06-20 09:47:27.382: E/ActivityThread(324): Failed to find provider info for com.google.settings
06-20 09:47:27.392: E/ActivityThread(324): Failed to find provider info for com.google.settings
06-20 09:47:27.702: D/dalvikvm(324): GC freed 3148 objects / 195472 bytes in 68ms
06-20 09:47:27.822: D/1:(324): Start ArrayList
06-20 09:47:27.822: I/global(324): Default buffer size used in BufferedReader constructor. It would be better to be explicit if an 8k-char buffer is required.
06-20 09:47:27.822: D/2:(324): Read File
06-20 09:47:27.822: D/3:(324): 9.34669876098644,48.2405319213867
06-20 09:47:27.822: D/4:(324): 9.34669876098644 - 48.2405319213867
06-20 09:47:27.952: E/APP(324): Failed
06-20 09:47:27.952: E/APP(324): java.lang.NumberFormatException:
06-20 09:47:27.952: E/APP(324): at org.apache.harmony.luni.util.FloatingPointParser.parseDblImpl(Native Method)
06-20 09:47:27.952: E/APP(324): at org.apache.harmony.luni.util.FloatingPointParser.parseDouble(FloatingPointParser.java:283)
06-20 09:47:27.952: E/APP(324): at java.lang.Double.parseDouble(Double.java:285)
06-20 09:47:27.952: E/APP(324): at de.bodprod.rettinfo.BOSLstItemDetail.onCreate(BOSLstItemDetail.java:93)
06-20 09:47:27.952: E/APP(324): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
06-20 09:47:27.952: E/APP(324): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
06-20 09:47:27.952: E/APP(324): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
06-20 09:47:27.952: E/APP(324): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
06-20 09:47:27.952: E/APP(324): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
06-20 09:47:27.952: E/APP(324): at android.os.Handler.dispatchMessage(Handler.java:99)
06-20 09:47:27.952: E/APP(324): at android.os.Looper.loop(Looper.java:123)
06-20 09:47:27.952: E/APP(324): at android.app.ActivityThread.main(ActivityThread.java:4363)
06-20 09:47:27.952: E/APP(324): at java.lang.reflect.Method.invokeNative(Native Method)
06-20 09:47:27.952: E/APP(324): at java.lang.reflect.Method.invoke(Method.java:521)
06-20 09:47:27.952: E/APP(324): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
06-20 09:47:27.952: E/APP(324): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
06-20 09:47:27.952: E/APP(324): at dalvik.system.NativeStart.main(Native Method)
06-20 09:47:28.043: I/MapActivity(324): Handling network change notification:CONNECTED
06-20 09:47:28.052: E/MapActivity(324): Couldn't get connection factory client
06-20 09:47:28.272: D/dalvikvm(324): GC freed 1440 objects / 382480 bytes in 66ms
06-20 09:47:28.292: D/AndroidRuntime(324): Shutting down VM
06-20 09:47:28.292: W/dalvikvm(324): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
06-20 09:47:28.292: E/AndroidRuntime(324): Uncaught handler: thread main exiting due to uncaught exception
06-20 09:47:28.302: E/AndroidRuntime(324): java.lang.NullPointerException
06-20 09:47:28.302: E/AndroidRuntime(324): at com.google.android.maps.OverlayBundle.draw(OverlayBundle.java:42)
06-20 09:47:28.302: E/AndroidRuntime(324): at com.google.android.maps.MapView.onDraw(MapView.java:476)
06-20 09:47:28.302: E/AndroidRuntime(324): at android.view.View.draw(View.java:6535)
06-20 09:47:28.302: E/AndroidRuntime(324): at android.view.ViewGroup.drawChild(ViewGroup.java:1531)
06-20 09:47:28.302: E/AndroidRuntime(324): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
06-20 09:47:28.302: E/AndroidRuntime(324): at android.view.ViewGroup.drawChild(ViewGroup.java:1529)
06-20 09:47:28.302: E/AndroidRuntime(324): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
06-20 09:47:28.302: E/AndroidRuntime(324): at android.view.View.draw(View.java:6641)
06-20 09:47:28.302: E/AndroidRuntime(324): at android.widget.FrameLayout.draw(FrameLayout.java:352)
06-20 09:47:28.302: E/AndroidRuntime(324): at android.view.ViewGroup.drawChild(ViewGroup.java:1531)
06-20 09:47:28.302: E/AndroidRuntime(324): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
06-20 09:47:28.302: E/AndroidRuntime(324): at android.view.View.draw(View.java:6538)
06-20 09:47:28.302: E/AndroidRuntime(324): at android.widget.FrameLayout.draw(FrameLayout.java:352)
06-20 09:47:28.302: E/AndroidRuntime(324): at android.view.ViewGroup.drawChild(ViewGroup.java:1531)
06-20 09:47:28.302: E/AndroidRuntime(324): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
06-20 09:47:28.302: E/AndroidRuntime(324): at android.view.ViewGroup.drawChild(ViewGroup.java:1529)
06-20 09:47:28.302: E/AndroidRuntime(324): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
06-20 09:47:28.302: E/AndroidRuntime(324): at android.view.View.draw(View.java:6538)
06-20 09:47:28.302: E/AndroidRuntime(324): at android.widget.FrameLayout.draw(FrameLayout.java:352)
06-20 09:47:28.302: E/AndroidRuntime(324): at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1830)
06-20 09:47:28.302: E/AndroidRuntime(324): at android.view.ViewRoot.draw(ViewRoot.java:1349)
06-20 09:47:28.302: E/AndroidRuntime(324): at android.view.ViewRoot.performTraversals(ViewRoot.java:1114)
06-20 09:47:28.302: E/AndroidRuntime(324): at android.view.ViewRoot.handleMessage(ViewRoot.java:1633)
06-20 09:47:28.302: E/AndroidRuntime(324): at android.os.Handler.dispatchMessage(Handler.java:99)
06-20 09:47:28.302: E/AndroidRuntime(324): at android.os.Looper.loop(Looper.java:123)
06-20 09:47:28.302: E/AndroidRuntime(324): at android.app.ActivityThread.main(ActivityThread.java:4363)
06-20 09:47:28.302: E/AndroidRuntime(324): at java.lang.reflect.Method.invokeNative(Native Method)
06-20 09:47:28.302: E/AndroidRuntime(324): at java.lang.reflect.Method.invoke(Method.java:521)
06-20 09:47:28.302: E/AndroidRuntime(324): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
06-20 09:47:28.302: E/AndroidRuntime(324): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
06-20 09:47:28.302: E/AndroidRuntime(324): at dalvik.system.NativeStart.main(Native Method)
06-20 09:47:28.323: I/dalvikvm(324): threadid=7: reacting to signal 3
解決:
これで動作します。eclipse new で座標を使用してファイルを作成し、これを使用します。
ArrayList<GeoPoint> points = new ArrayList<GeoPoint>();
try{
InputStream koord = getAssets().open("biberach");
if (koord != null) {
InputStreamReader input = new InputStreamReader(koord);
BufferedReader buffreader = new BufferedReader(input);
String line;
while (( line = buffreader.readLine()) != null) {
String[] point_t = line.split(",");
double y = Double.parseDouble(point_t[0]);
double x = Double.parseDouble(point_t[1]);
points.add(new GeoPoint((int)(x*1e6), (int)(y*1e6)));
}
koord.close();
polygon = new Polygon(points);
}
}catch (Exception e) {
Log.e("APP","Failed", e);
}
ファイルにエラーがありました