【问题标题】:I am get this error when i on touch of search location icon当我触摸搜索位置图标时出现此错误
【发布时间】:2012-08-27 13:06:08
【问题描述】:

我在触摸地图中的搜索位置图标时收到此错误...我有 3 个位置。 2 位置 r 我的位置和客户位置 & 我有搜索编辑框。当我搜索该位置时,它在正确的位置显示 d 图标,但我触摸该图标将强制关闭...我必须获得对话框。 这是我的代码 Can anyone guide me how to get Google Directions between two locations using JSON

请帮助我提前感谢任何人

08-27 17:52:52.708: D/AndroidRuntime(3721): Shutting down VM
08-27 17:52:52.708: W/dalvikvm(3721): threadid=1: thread exiting with uncaught exception (group=0x40be71f8)
08-27 17:52:52.723: E/AndroidRuntime(3721): FATAL EXCEPTION: main
08-27 17:52:52.723: E/AndroidRuntime(3721): java.lang.NullPointerException
08-27 17:52:52.723: E/AndroidRuntime(3721):     at android.app.AlertDialog.resolveDialogTheme(AlertDialog.java:142)
08-27 17:52:52.723: E/AndroidRuntime(3721):     at android.app.AlertDialog$Builder.<init>(AlertDialog.java:359)
08-27 17:52:52.723: E/AndroidRuntime(3721):     at com.androidhive.googleplacesandmaps.AddItemizedOverlay.onTap(AddItemizedOverlay.java:74)
08-27 17:52:52.723: E/AndroidRuntime(3721):     at com.google.android.maps.ItemizedOverlay.onTap(ItemizedOverlay.java:453)
08-27 17:52:52.723: E/AndroidRuntime(3721):     at com.google.android.maps.OverlayBundle.onTap(OverlayBundle.java:83)
08-27 17:52:52.723: E/AndroidRuntime(3721):     at com.google.android.maps.MapView$1.onSingleTapUp(MapView.java:356)
08-27 17:52:52.723: E/AndroidRuntime(3721):     at com.google.android.maps.GestureDetector.onTouchEvent(GestureDetector.java:533)
08-27 17:52:52.723: E/AndroidRuntime(3721):     at com.google.android.maps.MapView.onTouchEvent(MapView.java:683)
08-27 17:52:52.723: E/AndroidRuntime(3721):     at android.view.View.dispatchTouchEvent(View.java:5588)
08-27 17:52:52.723: E/AndroidRuntime(3721):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1951)
08-27 17:52:52.723: E/AndroidRuntime(3721):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1712)
08-27 17:52:52.723: E/AndroidRuntime(3721):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1957)
08-27 17:52:52.723: E/AndroidRuntime(3721):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1726)
08-27 17:52:52.723: E/AndroidRuntime(3721):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1957)
08-27 17:52:52.723: E/AndroidRuntime(3721):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1726)
08-27 17:52:52.723: E/AndroidRuntime(3721):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1957)
08-27 17:52:52.723: E/AndroidRuntime(3721):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1726)
08-27 17:52:52.723: E/AndroidRuntime(3721):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1957)
08-27 17:52:52.723: E/AndroidRuntime(3721):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1726)
08-27 17:52:52.723: E/AndroidRuntime(3721):     at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2060)
08-27 17:52:52.723: E/AndroidRuntime(3721):     at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1398)
08-27 17:52:52.723: E/AndroidRuntime(3721):     at android.app.Activity.dispatchTouchEvent(Activity.java:2364)
08-27 17:52:52.723: E/AndroidRuntime(3721):     at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2008)
08-27 17:52:52.723: E/AndroidRuntime(3721):     at android.view.View.dispatchPointerEvent(View.java:5768)
08-27 17:52:52.723: E/AndroidRuntime(3721):     at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:2911)
08-27 17:52:52.723: E/AndroidRuntime(3721):     at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2485)
08-27 17:52:52.723: E/AndroidRuntime(3721):     at android.view.ViewRootImpl.processInputEvents(ViewRootImpl.java:852)
08-27 17:52:52.723: E/AndroidRuntime(3721):     at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2494)
08-27 17:52:52.723: E/AndroidRuntime(3721):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-27 17:52:52.723: E/AndroidRuntime(3721):     at android.os.Looper.loop(Looper.java:137)
08-27 17:52:52.723: E/AndroidRuntime(3721):     at android.app.ActivityThread.main(ActivityThread.java:4514)
08-27 17:52:52.723: E/AndroidRuntime(3721):     at java.lang.reflect.Method.invokeNative(Native Method)
08-27 17:52:52.723: E/AndroidRuntime(3721):     at java.lang.reflect.Method.invoke(Method.java:511)
08-27 17:52:52.723: E/AndroidRuntime(3721):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
08-27 17:52:52.723: E/AndroidRuntime(3721):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
08-27 17:52:52.723: E/AndroidRuntime(3721):     at dalvik.system.NativeStart.main(Native Method)
08-27 17:52:59.911: I/Process(3721): Sending signal. PID: 3721 SIG: 9

Placesmapactivity.java

tr 上方是我的 ful 代码的链接 只是去这个方法快速参考..

       @Override
            public void onClick(View v) {           
                String usrLoc = autoCompletetextView.getText().toString();
                Geocoder gc = new Geocoder(PlacesMapActivity.this);

                try {
                    addr=gc.getFromLocationName(usrLoc, 3);//maximum 2 results
                    if(addr.size()>0){
                        address=addr.get(0);//get the first result
                        convertLongi=address.getLongitude();
                        convertLati=address.getLatitude();
                        geopointsearch = new GeoPoint((int)(convertLati * 1E6), (int)(convertLongi * 1E6));                                     

                     // Map geopointsearch overlay item
                        itemizedOverlay2 = new AddItemizedOverlay(drawable_client);     
                        overlayitem = new OverlayItem(geopointsearch, "Your Location2", "I am ur client!");
                        itemizedOverlay2.addOverlay(overlayitem);       
                        mapOverlays.add(itemizedOverlay2);
                        itemizedOverlay2.populateNow();
                        mc.animateTo(geopointsearch);   
                     //   mc.zoomIn();
                    }

                } catch (IOException e) {                   
                    e.printStackTrace();
                }
            }                                   
        });

    // Map overlay item
    itemizedOverlay = new AddItemizedOverlay(drawable_user, this);
    overlayitem = new OverlayItem(geoPoint, "Your Location","That is you!");
    itemizedOverlay.addOverlay(overlayitem);        
    mapOverlays.add(itemizedOverlay);
    itemizedOverlay.populateNow();      
    // Map client overlay item
    itemizedOverlay1 = new AddItemizedOverlay(drawable_client, this);       
    overlayitem1 = new OverlayItem(geoPoint1, "Your Location2", "I am ur client!");
    itemizedOverlay1.addOverlay(overlayitem1);              
    mapOverlays.add(itemizedOverlay1);
    itemizedOverlay1.populateNow();
    // Map near overlay item    
    itemizedOverlay = new AddItemizedOverlay(drawable, this);
    // Map geopointsearch overlay item
   /* itemizedOverlay2 = new AddItemizedOverlay(drawable_client, this);     
    overlayitem2 = new OverlayItem(geopointsearch, "Your Location3", "ur searching for me!");
    itemizedOverlay2.addOverlay(overlayitem2);      
    mapOverlays.add(itemizedOverlay2);
    itemizedOverlay2.populateNow();*/

AddItemizedOverlay.java

公共类 AddItemizedOverlay 扩展 ItemizedOverlay {

   private ArrayList<OverlayItem> mapOverlays = new ArrayList<OverlayItem>();

   private Context context;
   MapController mc;
Drawable drawable;

private GeoPoint geopoint;



public AddItemizedOverlay(Drawable defaultMarker) {
        super(boundCenterBottom(defaultMarker));
   }

   public AddItemizedOverlay(Drawable defaultMarker, Context context) {
        this(defaultMarker);
        this.context = context;
   }

   @Override
   public boolean onTouchEvent(MotionEvent event, MapView mapView)
   {   
       if (event.getAction() == 1) {
           GeoPoint geopoint = mapView.getProjection().fromPixels(
               (int) event.getX(),
               (int) event.getY());
           // latitude
           double lat = geopoint.getLatitudeE6() / 1E6;
           // longitude
           double lon = geopoint.getLongitudeE6() / 1E6;

       //  Toast.makeText(context, "Lat: " + lat + ", Lon: "+lon, Toast.LENGTH_SHORT).show();
       }     
       return false;
   } 


@Override
   protected OverlayItem createItem(int i) {
      return mapOverlays.get(i);
   }

   @Override
   public int size() {
      return mapOverlays.size();
   }

   @Override
   protected boolean onTap(int index) {
     OverlayItem item = mapOverlays.get(index);
     AlertDialog.Builder dialog = new AlertDialog.Builder(this.context);
     dialog.setTitle(item.getTitle());
     dialog.setMessage(item.getSnippet());
     dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
        }
    });
     dialog.show();
     return true;
   }

   public void addOverlay(OverlayItem overlay) {
      mapOverlays.add(overlay);
   }

   public void populateNow(){
       this.populate();
   }

}

【问题讨论】:

    标签: android android-layout android-mapview android-dialog


    【解决方案1】:

    尝试将受保护的布尔 onTap(int index) 更改如下:

    @Override
    protected boolean onTap(int index) {
     OverlayItem item = mapOverlays.get(index);
     AlertDialog.Builder dialog = new AlertDialog.Builder(this.context);
     dialog.setTitle(item.getTitle());
     dialog.setMessage(item.getSnippet());
     dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
        }
    });
     AlertDialog alertDialog=dialog.create();
     alertDialog.show();
     return true;
    

    }

    您需要从 DialogBu​​ilder 创建 AlertDialog。

    【讨论】:

    • 嗨 Eldhose M Babu,我遇到了错误。 AlertDialog.Builder 对话框 = new AlertDialog.Builder(this.context);我仍然遇到同样的错误...请帮助我..
    • 嗨,我得到了上述错误任何人都可以帮助我..警报对话框显示正确为 1.// 地图叠加项 2.// 地图客户端叠加项您可以参考上面的代码。 . 它在 3.// 地图 geopointsearch 覆盖项中显示错误...它正在搜索正确的位置,图像也正在显示,但当我触摸图像时,警报对话框中出现错误,它显示在错误上方。请告诉我错误的家伙..提前谢谢。
    • 更改代码:itemizedOverlay2 = new AddItemizedOverlay(drawable_client); to itemizedOverlay2 = new AddItemizedOverlay(drawable_client, ActivityName.this);其中 ActivityName 指的是活动的名称。
    • 如果正确请标记为答案,以便帮助其他人。
    • wr is d option boss..我是这个网站的新手。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-19
    • 1970-01-01
    相关资源
    最近更新 更多