私はこの素晴らしい例を参照しています:こちらをご覧ください
次のエラーが発生し、解決策が見つかりません。助けてください!NoSuchElementException が発生します。MainActivity では、説明どおりに実行しています。Android-Manifest にも含めます
<uses-library android:name="com.google.android.maps" />
アプリケーションを起動すると、mapview がすぐに表示され (灰色のパターン)、突然強制終了ダイアログが表示されます。
私のMainActivity :
public class MainActivity extends MapActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MapView mapView = (MapView) findViewById(R.id.mapview); //or you can declare it directly with the API key
Route route = directions(new GeoPoint((int)(26.2*1E6),(int)(50.6*1E6)), new GeoPoint((int)(26.3*1E6),(int)(50.7*1E6)));
RouteOverlay routeOverlay = new RouteOverlay(route, Color.BLUE);
mapView.getOverlays().add(routeOverlay);
}
private Route directions(final GeoPoint start, final GeoPoint dest) {
Parser parser;
String jsonURL = "http://maps.google.com/maps/api/directions/json?";
final StringBuffer sBuf = new StringBuffer(jsonURL);
sBuf.append("origin=");
sBuf.append(start.getLatitudeE6()/1E6);
sBuf.append(',');
sBuf.append(start.getLongitudeE6()/1E6);
sBuf.append("&destination=");
sBuf.append(dest.getLatitudeE6()/1E6);
sBuf.append(',');
sBuf.append(dest.getLongitudeE6()/1E6);
sBuf.append("&sensor=true&mode=driving");
parser = new GoogleParser(sBuf.toString());
Route r = parser.parse();
return r;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
私の activity_main.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<com.google.android.maps.MapView
android:id="@+id/mapview" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:clickable="true"
android:apiKey="..........................................." />
</RelativeLayout>
エラーログ:
11-19 11:22:17.782: I/MapActivity(10703): Handling network change notification:CONNECTED
11-19 11:22:17.782: E/MapActivity(10703): Couldn't get connection factory client
11-19 11:22:17.822: D/AndroidRuntime(10703): Shutting down VM
11-19 11:22:17.822: W/dalvikvm(10703): threadid=1: thread exiting with uncaught exception (group=0x4001d5a0)
11-19 11:22:17.872: E/AndroidRuntime(10703): FATAL EXCEPTION: main
11-19 11:22:17.872: E/AndroidRuntime(10703): java.util.NoSuchElementException
11-19 11:22:17.872: E/AndroidRuntime(10703): at java.util.ArrayList$ArrayListIterator.next(ArrayList.java:579)
11-19 11:22:17.872: E/AndroidRuntime(10703): at com.example.testjsongooglemap.RouteOverlay.redrawPath(RouteOverlay.java:90)
11-19 11:22:17.872: E/AndroidRuntime(10703): at com.example.testjsongooglemap.RouteOverlay.draw(RouteOverlay.java:60)
11-19 11:22:17.872: E/AndroidRuntime(10703): at com.google.android.maps.Overlay.draw(Overlay.java:179)
11-19 11:22:17.872: E/AndroidRuntime(10703): at com.google.android.maps.OverlayBundle.draw(OverlayBundle.java:42)
11-19 11:22:17.872: E/AndroidRuntime(10703): at com.google.android.maps.MapView.onDraw(MapView.java:530)
11-19 11:22:17.872: E/AndroidRuntime(10703): at android.view.View.draw(View.java:7014)
11-19 11:22:17.872: E/AndroidRuntime(10703): at android.view.ViewGroup.drawChild(ViewGroup.java:1732)
11-19 11:22:17.872: E/AndroidRuntime(10703): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1459)
11-19 11:22:17.872: E/AndroidRuntime(10703): at android.view.ViewGroup.drawChild(ViewGroup.java:1730)
11-19 11:22:17.872: E/AndroidRuntime(10703): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1459)
11-19 11:22:17.872: E/AndroidRuntime(10703): at android.view.View.draw(View.java:7017)
11-19 11:22:17.872: E/AndroidRuntime(10703): at android.widget.FrameLayout.draw(FrameLayout.java:357)
11-19 11:22:17.872: E/AndroidRuntime(10703): at android.view.ViewGroup.drawChild(ViewGroup.java:1732)
11-19 11:22:17.872: E/AndroidRuntime(10703): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1459)
11-19 11:22:17.872: E/AndroidRuntime(10703): at android.view.ViewGroup.drawChild(ViewGroup.java:1730)
11-19 11:22:17.872: E/AndroidRuntime(10703): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1459)
11-19 11:22:17.872: E/AndroidRuntime(10703): at android.view.View.draw(View.java:7017)
11-19 11:22:17.872: E/AndroidRuntime(10703): at android.widget.FrameLayout.draw(FrameLayout.java:357)
11-19 11:22:17.872: E/AndroidRuntime(10703): at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:2054)
11-19 11:22:17.872: E/AndroidRuntime(10703): at android.view.ViewRoot.draw(ViewRoot.java:1632)
11-19 11:22:17.872: E/AndroidRuntime(10703): at android.view.ViewRoot.performTraversals(ViewRoot.java:1335)
11-19 11:22:17.872: E/AndroidRuntime(10703): at android.view.ViewRoot.handleMessage(ViewRoot.java:1991)
11-19 11:22:17.872: E/AndroidRuntime(10703): at android.os.Handler.dispatchMessage(Handler.java:99)
11-19 11:22:17.872: E/AndroidRuntime(10703): at android.os.Looper.loop(Looper.java:150)
11-19 11:22:17.872: E/AndroidRuntime(10703): at android.app.ActivityThread.main(ActivityThread.java:4385)
11-19 11:22:17.872: E/AndroidRuntime(10703): at java.lang.reflect.Method.invokeNative(Native Method)
11-19 11:22:17.872: E/AndroidRuntime(10703): at java.lang.reflect.Method.invoke(Method.java:507)
11-19 11:22:17.872: E/AndroidRuntime(10703): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:849)
11-19 11:22:17.872: E/AndroidRuntime(10703): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:607)
11-19 11:22:17.872: E/AndroidRuntime(10703): at dalvik.system.NativeStart.main(Native Method)