Android项目don';调用googleMaps时,请不要在设备中运行

Android项目don';调用googleMaps时,请不要在设备中运行,android,eclipse,android-support-library,Android,Eclipse,Android Support Library,我在设备上运行当前的android项目时遇到了一些问题。项目是在没有错误的情况下构建的(使用ecplise),但是当我运行此错误时: 12-22 11:31:18.064: E/AndroidRuntime(10283): FATAL EXCEPTION: main 12-22 11:31:18.064: E/AndroidRuntime(10283): java.lang.RuntimeException: Unable to start activity ComponentInfo{br.t

我在设备上运行当前的android项目时遇到了一些问题。项目是在没有错误的情况下构建的(使用ecplise),但是当我运行此错误时:

12-22 11:31:18.064: E/AndroidRuntime(10283): FATAL EXCEPTION: main
12-22 11:31:18.064: E/AndroidRuntime(10283): java.lang.RuntimeException: Unable to start activity ComponentInfo{br.trocatela.com/br.trocatela.com.GoogleMapsActivity}: java.lang.NullPointerException
12-22 11:31:18.064: E/AndroidRuntime(10283):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2295)
12-22 11:31:18.064: E/AndroidRuntime(10283):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2349)
12-22 11:31:18.064: E/AndroidRuntime(10283):    at android.app.ActivityThread.access$700(ActivityThread.java:159)
12-22 11:31:18.064: E/AndroidRuntime(10283):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
12-22 11:31:18.064: E/AndroidRuntime(10283):    at android.os.Handler.dispatchMessage(Handler.java:99)
12-22 11:31:18.064: E/AndroidRuntime(10283):    at android.os.Looper.loop(Looper.java:176)
12-22 11:31:18.064: E/AndroidRuntime(10283):    at android.app.ActivityThread.main(ActivityThread.java:5419)
12-22 11:31:18.064: E/AndroidRuntime(10283):    at java.lang.reflect.Method.invokeNative(Native Method)
12-22 11:31:18.064: E/AndroidRuntime(10283):    at java.lang.reflect.Method.invoke(Method.java:525)
12-22 11:31:18.064: E/AndroidRuntime(10283):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)
12-22 11:31:18.064: E/AndroidRuntime(10283):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
12-22 11:31:18.064: E/AndroidRuntime(10283):    at dalvik.system.NativeStart.main(Native Method)
12-22 11:31:18.064: E/AndroidRuntime(10283): Caused by: java.lang.NullPointerException
12-22 11:31:18.064: E/AndroidRuntime(10283):    at br.trocatela.com.GoogleMapsActivity.onCreate(GoogleMapsActivity.java:68)
12-22 11:31:18.064: E/AndroidRuntime(10283):    at android.app.Activity.performCreate(Activity.java:5372)
12-22 11:31:18.064: E/AndroidRuntime(10283):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104)
12-22 11:31:18.064: E/AndroidRuntime(10283):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2257)
12-22 11:31:18.064: E/AndroidRuntime(10283):    ... 11 more
我的班级是:

package br.trocatela.com;

import java.util.List;

import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.Toast;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;

public class GoogleMapsActivity extends MapActivity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.map);

        Intent intent = getIntent();
     String lat1 = intent.getStringExtra("lat");
    String longt = intent.getStringExtra("longt");

    LocationManager LM = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
String bestProvider = LM.getBestProvider(new Criteria(),true);
    //System.out.println("*************"+LM.getBestProvider(new Criteria(),true));
    Location l = LM.getLastKnownLocation(bestProvider);






    //Toast.makeText(this, "lat"+lat1, Toast.LENGTH_SHORT).show(); 
    //Toast.makeText(this, "longt"+longt, Toast.LENGTH_SHORT).show(); 


        // Displaying Zooming controls
        MapView mapView = (MapView) findViewById(R.id.map_view);
        mapView.setBuiltInZoomControls(true);

        /**
         * Changing Map Type
         * */
         mapView.setSatellite(true); // Satellite View
        // mapView.setStreetView(true); // Street View
        // mapView.setTraffic(true); // Traffic view

        /**
         * showing location by Latitude and Longitude
         * */        
        MapController mc = mapView.getController();




        double lat = Double.parseDouble(lat1);
        double lon = Double.parseDouble(longt);


        double lat2=l.getLatitude();
        double long2=l.getLongitude();

        Toast.makeText(this, "Encontra se a  "+ lat2+ "º de latitude", Toast.LENGTH_SHORT).show();
        Toast.makeText(this, "Encontra se a "+ long2+ "º de longitude", Toast.LENGTH_SHORT).show();

        GeoUtils g = new GeoUtils();
        GeoCoordinate g1 = new GeoCoordinate(lat, lon);
        GeoCoordinate g2 = new GeoCoordinate(lat2, long2);
      double dist=  g.geoDistanceInKm(g1, g2);

      Toast.makeText(this, "Voce Encontra se a  "+ dist+ "km do local pretendido", Toast.LENGTH_SHORT).show();




        GeoPoint geoPoint = new GeoPoint((int)(lat * 1E6), (int)(lon * 1E6));
        mc.animateTo(geoPoint);
        mc.setZoom(15);
        mapView.invalidate(); 


        /**
         * Placing Marker
         * */
        List<Overlay> mapOverlays = mapView.getOverlays();
        Drawable drawable = this.getResources().getDrawable(R.drawable.mark_red);
        AddItemizedOverlay itemizedOverlay = 
             new AddItemizedOverlay(drawable, this);


        OverlayItem overlayitem = new OverlayItem(geoPoint, "Hello", "Sample Overlay item");

        itemizedOverlay.addOverlay(overlayitem);
        mapOverlays.add(itemizedOverlay);

    }

    @Override
    protected boolean isRouteDisplayed() {
        return false;
    }
}
package br.trocatela.com;
导入java.util.List;
导入android.content.Context;
导入android.content.Intent;
导入android.graphics.drawable.drawable;
导入android.location.Criteria;
导入android.location.location;
导入android.location.LocationManager;
导入android.os.Bundle;
导入android.widget.Toast;
导入com.google.android.maps.GeoPoint;
导入com.google.android.maps.MapActivity;
导入com.google.android.maps.MapController;
导入com.google.android.maps.MapView;
导入com.google.android.maps.Overlay;
导入com.google.android.maps.OverlayItem;
公共类GoogleMapsActivity扩展了MapActivity{
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.map);
Intent=getIntent();
字符串lat1=intent.getStringExtra(“lat”);
stringlongt=intent.getStringExtra(“longt”);
LocationManager LM=(LocationManager)getSystemService(Context.LOCATION\u服务);
字符串bestProvider=LM.getBestProvider(新条件(),true);
//System.out.println(“***********”+LM.getBestProvider(new Criteria(),true));
位置l=LM.getLastKnownLocation(最佳提供者);
//Toast.makeText(这个“lat”+lat1,Toast.LENGTH_SHORT).show();
//Toast.makeText(这个“long”+long,Toast.LENGTH_SHORT).show();
//显示缩放控件
MapView MapView=(MapView)findViewById(R.id.map\u视图);
mapView.SetBuilTinZoomControl(真);
/**
*更改地图类型
* */
mapView.setSatellite(true);//卫星视图
//mapView.setStreetView(true);//街景
//setTraffic(true);//流量视图
/**
*通过纬度和经度显示位置
* */        
MapController mc=mapView.getController();
double lat=double.parseDouble(lat1);
双lon=double.parseDouble(lont);
双lat2=l.getLatitude();
double long2=l.getLongitude();
Toast.makeText(这个“Encontra se a”+lat2+“纬度”,Toast.LENGTH_SHORT).show();
Toast.makeText(这是“Encontra se a”+long2+“经度º”,Toast.LENGTH_SHORT).show();
geootils g=新的geootils();
地理坐标g1=新的地理坐标(纬度、经度);
地理坐标g2=新的地理坐标(lat2,long2);
双距离=g.geoDistanceInKm(g1,g2);
Toast.makeText(这是“Voce Encontra se a”+dist+“km do local假装”,Toast.LENGTH_SHORT).show();
地质点地质点=新的地质点((int)(lat*1E6),(int)(lon*1E6));
司仪(地点);;
mc.setZoom(15);
mapView.invalidate();
/**
*放置标记
* */
List mapOverlays=mapView.getOverlays();
Drawable Drawable=this.getResources().getDrawable(R.Drawable.mark_red);
AddItemizedOverlay项IzedOverlay=
新添加物(可拉伸,本);
OverlayItem OverlayItem=新的OverlayItem(地质点,“你好”,“样本覆盖项”);
itemizedOverlay.addOverlay(overlayitem);
添加(itemizedOverlay);
}
@凌驾
受保护的布尔值isRouteDisplayed(){
返回false;
}
}
map.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=
   "http://schemas.android.com/apk/res/android"
     android:orientation="vertical"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
>
<com.google.android.maps.MapView
     android:id="@+id/map_view"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:enabled="true"
     android:clickable="true"
     android:apiKey="0CZ0aW7qB1Q__jlO6qkhl3IfFJTwGvwYUv7VDTQ"
/>
</LinearLayout>

类MainActivity被放置在我的项目中的正确目录中(与其他项目相同,它们运行时没有问题)


任何人都可以看到我在这里遗漏了什么?

检查
LM.getLastKnownLocation(bestProvider)
是否未返回null

使用FragmentActivity在哪一行获得异常??显示您的xml文件。嗨,我添加了我的xml文件。我找不到错误行。为什么是负面帖子0代码正常,几个月前工作正常。我格式化我的电脑并重新安装ecplise,我使用的是不同的电话。三星S3我可能错过了什么?你安装了合适的android工具吗?从SDK管理者的角度来看,这可能是问题所在,因此,通过问这个问题,作者可能会认识到他缺少了什么,问题就会得到解决。我想我的问题包括建议他安装一个丢失的工具,以防他忘记。问题解决了,我更新了我的谷歌地图应用程序。清除缓存和所有数据。而应用程序start 5*问题出在谷歌地图三星S3应用程序中