2014-12-22 4 views
-1

내 Android 기기를 내 기기에서 실행하는 데 문제가 있습니다. 이 프로젝트는 (ecplise와) 아무하는 오류로 구축,하지만 난 실행할 때이 오류가 발생한다 :googleMaps를 호출 할 때 Android 프로젝트가 기기에서 실행되지 않습니다.

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; 
    } 
} 

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 클래스는 내 프로젝트 내의 올바른 디렉토리에 배치됩니다 (문제없이 실행되는 다른 프로젝트와 동일).

누구나 내가 여기에서 놓친 것을 볼 수 있습니까?

+0

사용 FragmentActivity –

+0

어떤 줄에서 예외가 발생합니까 ?? XML 파일을 표시하십시오. – RockStar

+0

안녕하세요, 내 xml 파일을 추가합니다. 나는 오류 라인을 찾지 못했다. 왜 부정적인 게시물인가? : 0 – user3644929

답변

1

LM.getLastKnownLocation(bestProvider)이 null을 반환하지 않는지 확인하십시오.

+0

코드는 몇 달 전부터 정상적으로 작동했습니다. 컴퓨터를 포맷하고 ecplise를 다시 설치하면 다른 전화기를 사용하고 있습니다. 삼성 S3 나는 무엇이든 놓칠 수 있습니까? – user3644929

+0

당신은 그것에 대한 적절한 안드로이드 도구를 설치 했습니까? SDK 관리자 –

+0

실제로 그게 문제 일 수 있으므로 그 질문을 작성자는 그가 누락 된 것을 인식하고 문제가 해결 될 것이라고 물어 봄으로써. 내 질문에 그가 잊어 버린 경우를 대비하여 누락 된 도구를 설치하라는 제안이 포함되어 있다고 생각합니다. –

관련 문제