-1

私はアンドロイド用のマップベースのアプリを開発しており、現在の場所を検出する最終段階にあります。しかし、今私のアプリは動作していません。エミュレータにも実機にもインストールできません。試しているときはいつでも、コンソールに次のようなメッセージが表示されます。

アプリケーション (map.apk) をインストールできません。

これは私のlogcatです:

01-14 18:08:20.576: D/dalvikvm(342): GC_FOR_MALLOC freed 4859 objects / 301296 bytes in 100ms
01-14 18:08:20.916: D/dalvikvm(342): GC_FOR_MALLOC freed 10156 objects / 616976 bytes in 96ms
01-14 18:08:21.216: D/dalvikvm(342): GC_FOR_MALLOC freed 4664 objects / 306384 bytes in 88ms
01-14 18:08:21.576: D/dalvikvm(342): GC_FOR_MALLOC freed 6137 objects / 374304 bytes in 152ms
01-14 18:08:21.956: D/dalvikvm(342): GC_FOR_MALLOC freed 8481 objects / 648904 bytes in 98ms
01-14 18:08:22.266: D/dalvikvm(342): GC_FOR_MALLOC freed 6080 objects / 370008 bytes in 98ms
01-14 18:08:22.407: D/AndroidRuntime(342): Shutting down VM
01-14 18:08:22.407: W/dalvikvm(342): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
01-14 18:08:22.427: E/AndroidRuntime(342): FATAL EXCEPTION: main
01-14 18:08:22.427: E/AndroidRuntime(342): java.lang.RuntimeException: Unable to start activity ComponentInfo{g.g.g/g.g.g.GPSLocatorActivity}: java.lang.NullPointerException
01-14 18:08:22.427: E/AndroidRuntime(342):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
01-14 18:08:22.427: E/AndroidRuntime(342):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
01-14 18:08:22.427: E/AndroidRuntime(342):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
01-14 18:08:22.427: E/AndroidRuntime(342):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
01-14 18:08:22.427: E/AndroidRuntime(342):  at android.os.Handler.dispatchMessage(Handler.java:99)
01-14 18:08:22.427: E/AndroidRuntime(342):  at android.os.Looper.loop(Looper.java:123)
01-14 18:08:22.427: E/AndroidRuntime(342):  at android.app.ActivityThread.main(ActivityThread.java:4627)
01-14 18:08:22.427: E/AndroidRuntime(342):  at java.lang.reflect.Method.invokeNative(Native Method)
01-14 18:08:22.427: E/AndroidRuntime(342):  at java.lang.reflect.Method.invoke(Method.java:521)
01-14 18:08:22.427: E/AndroidRuntime(342):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
01-14 18:08:22.427: E/AndroidRuntime(342):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
01-14 18:08:22.427: E/AndroidRuntime(342):  at dalvik.system.NativeStart.main(Native Method)
01-14 18:08:22.427: E/AndroidRuntime(342): Caused by: java.lang.NullPointerException
01-14 18:08:22.427: E/AndroidRuntime(342):  at g.g.g.GPSLocatorActivity.onCreate(GPSLocatorActivity.java:50)
01-14 18:08:22.427: E/AndroidRuntime(342):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-14 18:08:22.427: E/AndroidRuntime(342):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
01-14 18:08:22.427: E/AndroidRuntime(342):  ... 11 more

これは私のコードです:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

      mapView = (MapView) findViewById(R.id.mapView);
      mapView.setTraffic(true);
      mapView.setBuiltInZoomControls(true);



      List<Overlay> mapOverlays = mapView.getOverlays();
      Drawable drawable = this.getResources().getDrawable(R.drawable.icon);
      HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay(drawable,this);
      GeoPoint point = new GeoPoint(
              (int) (location.getLatitude() * 1E6), 
              (int) (location.getLongitude() * 1E6));

          OverlayItem overlayitem = new OverlayItem(point,"","" );
      itemizedoverlay.addOverlay(overlayitem);
      mapOverlays.add(itemizedoverlay);
      }

      @Override
      protected boolean isRouteDisplayed()
      {
      return false;
      }
4

1 に答える 1

3

位置検出器が原因で問題が発生する可能性があります。「場所」がnullかどうかを知るためにこれを試してください

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

      mapView = (MapView) findViewById(R.id.mapView);
      mapView.setTraffic(true);
      mapView.setBuiltInZoomControls(true);



      List<Overlay> mapOverlays = mapView.getOverlays();
      Drawable drawable = this.getResources().getDrawable(R.drawable.icon);
      HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay(drawable,this);

       //see here;
      location = getGpsLocation();
      if(location!=null){
          GeoPoint point = new GeoPoint(
              (int) (location.getLatitude() * 1E6), 
              (int) (location.getLongitude() * 1E6));

          OverlayItem overlayitem = new OverlayItem(point,"","" );
          itemizedoverlay.addOverlay(overlayitem);
          mapOverlays.add(itemizedoverlay);
      }else{
         Toast.makeText(getApplicationContext(), "GPS error", Toast.LENGTH_LONG).show();
      }
  }

  //see here;
  public Location getGpsLocation()
  {
          Location res = new Location("");
          res.setLatitude(0);
      res.setLongitude(0);

          // res = ; try some code to find you your current location

          return res;
  }
  @Override
  protected boolean isRouteDisplayed()
  {
  return false;
  }
于 2013-01-14T13:36:19.130 に答える