onTap使itemizedOverlay和活动因糟糕的构造函数而崩溃

时间:2012-03-16 15:43:14

标签: java android google-maps

我有我的Mapactivity,它会叠加来自叠加项目的一些项目,但每当我点击一个项目时,它会给我空指针异常,当然还有崩溃。我做了很多研究,所有结果都说这是由于不好的顾问和上下文,但问题是他们的解决方案对我不起作用。这里有一些相关的主题

  1. link 1
  2. link2
  3. link3 我试过,这个,this.getApplicationContext但stil,我有一个空指针ewception
  4. 这里是我在mapActivity类中调用overlayItems的地方:

     marker1 =getResources().getDrawable(R.drawable.maps_position_marker);
            marker1.setBounds( (int) (-marker1.getIntrinsicWidth()/2),
            -marker1.getIntrinsicHeight(),
            (int) (marker1.getIntrinsicWidth()/2),
            0);
            overlay4 notFunPlaces =  new overlay4(marker1, this.getBaseContext());
            mapView.getOverlays().add(notFunPlaces);
           // GeoPoint pt1 = notFunPlaces.getCenterPt();
            int latSpan1 = notFunPlaces.getLatSpanE6();
            int lonSpan1 = notFunPlaces.getLonSpanE6();
            Log.v("Overlays", "Lat span is " + latSpan1);
            Log.v("Overlays", "Lon span is " + lonSpan1);
    
    
    my itmizedOverlay class class:
    
    @SuppressWarnings("rawtypes")
        class overlay4 extends ItemizedOverlay {
    
            private ArrayList<OverlayItem> locations =
            new ArrayList<OverlayItem>();
            private Context mContext;
            private PopupPanel panel=new PopupPanel(R.layout.popup);
    
    
    
            public <getBaseContext> overlay4(Drawable marker, getBaseContext context )
            {
    
                super(boundCenterBottom(marker));
                mContext = (Context) context;
      //  my items
    .........
    populates();}
    
     @Override
                    protected boolean onTap(int i) {
    
                      OverlayItem item=getItem(i);
                      GeoPoint geo=item.getPoint();
                      Bitmap bitmap = null;
    
                  Point pro=    mapView.getProjection().toPixels(geo, null);
                      if (pro!=null)
                      {   View view=panel.getView();
    
                  String capteur=   getType (locations.get(i).getSnippet()); 
                      ((TextView)view.findViewById(R.id.poptext))
                        .setText(String.valueOf("image captured by : " + capteur + "\n" + "Latitude = " + locations.get(i).getPoint().getLatitudeE6()/1E6 +" " + "Longitude = "+ locations.get(i).getPoint().getLongitudeE6()/1E6 +" " + 
                                 "\n" + "Image can be found at the following directory :" + locations.get(i).getTitle()
    
                                ));
                      ImageView image= (ImageView) findViewById(R.id.ImageV);
            ........         
    

    我的logcat:

     FATAL EXCEPTION: main
     java.lang.NullPointerException
         at tfe.rma.ciss.be.TheMap$overlay4.onTap(TheMap.java:3705)
         at com.google.android.maps.ItemizedOverlay.onTap(ItemizedOverlay.java:453)
         at com.google.android.maps.OverlayBundle.onTap(OverlayBundle.java:83)
         at com.google.android.maps.MapView$1.onSingleTapUp(MapView.java:356)
         at com.google.android.maps.GestureDetector.onTouchEvent(GestureDetector.java:533)
         at com.google.android.maps.MapView.onTouchEvent(MapView.java:683)
         at android.view.View.dispatchTouchEvent(View.java:3885)
         at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:903)
         at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
         at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
         at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
         at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1750)
         at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1135)
         at android.app.Activity.dispatchTouchEvent(Activity.java:2096)
         at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1734)
         at android.view.ViewRoot.deliverPointerEvent(ViewRoot.java:2216)
         at android.view.ViewRoot.handleMessage(ViewRoot.java:1887)
         at android.os.Handler.dispatchMessage(Handler.java:99)
         at android.os.Looper.loop(Looper.java:123)
         at android.app.ActivityThread.main(ActivityThread.java:3687)
         at java.lang.reflect.Method.invokeNative(Native Method)
         at java.lang.reflect.Method.invoke(Method.java:507)
         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
         at dalvik.system.NativeStart.main(Native Method)
    :   Force finishing activity tfe.rma.ciss.be/.TheMap
    tate > /data/log/dumpstate_app_error
    :   Force finishing activity tfe.rma.ciss.be/.menu
    

0 个答案:

没有答案