1

好吧,我已經搜索並搜索了,我正在獲取此示例項目的最後一道關卡,但現在它仍然無法在我的手機上啓動(Galaxy S4),當我試圖執行android-maps-extensions 2.0(我有加載到標記添加到地圖,但需要它們動態)Android地圖擴展程序出錯了

我有庫的所有設置和工作,因爲他們應該,但每當我將MapFragment代碼更改爲SupportMapFragment應用程序崩潰並且不會打開。如果我離開的一切,是我的電話罰款的應用程序加載

logcat的

01-20 12:24:53.382: E/AndroidRuntime(21636): FATAL EXCEPTION: main 
01-20 12:24:53.382: E/AndroidRuntime(21636): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.me.mypackage/com.me.mypackage.MainActivity}: java.lang.NullPointerException 
01-20 12:24:53.382: E/AndroidRuntime(21636): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2295) 
01-20 12:24:53.382: E/AndroidRuntime(21636): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2349) 
01-20 12:24:53.382: E/AndroidRuntime(21636): at android.app.ActivityThread.access$700(ActivityThread.java:159) 
01-20 12:24:53.382: E/AndroidRuntime(21636): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316) 
01-20 12:24:53.382: E/AndroidRuntime(21636): at android.os.Handler.dispatchMessage(Handler.java:99) 
01-20 12:24:53.382: E/AndroidRuntime(21636): at android.os.Looper.loop(Looper.java:137) 
01-20 12:24:53.382: E/AndroidRuntime(21636): at android.app.ActivityThread.main(ActivityThread.java:5419) 
01-20 12:24:53.382: E/AndroidRuntime(21636): at java.lang.reflect.Method.invokeNative(Native Method) 
01-20 12:24:53.382: E/AndroidRuntime(21636): at java.lang.reflect.Method.invoke(Method.java:525) 
01-20 12:24:53.382: E/AndroidRuntime(21636): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187) 
01-20 12:24:53.382: E/AndroidRuntime(21636): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003) 
01-20 12:24:53.382: E/AndroidRuntime(21636): at dalvik.system.NativeStart.main(Native Method) 
01-20 12:24:53.382: E/AndroidRuntime(21636): Caused by: java.lang.NullPointerException 
01-20 12:24:53.382: E/AndroidRuntime(21636): at com.me.mypackage.MainActivity.setUpMapIfNeeded(MainActivity.java:102) 
01-20 12:24:53.382: E/AndroidRuntime(21636): at com.me.mypackage.MainActivity.onCreate(MainActivity.java:76) 
01-20 12:24:53.382: E/AndroidRuntime(21636): at android.app.Activity.performCreate(Activity.java:5372) 
01-20 12:24:53.382: E/AndroidRuntime(21636): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104) 
01-20 12:24:53.382: E/AndroidRuntime(21636): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2257) 

清單XML

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
package="com.me.mypackage" 
android:id="@+id/theMap" 
android:name="com.androidmapsextensions.SupportMapFragment" 
android:versionCode="1" 
android:versionName="1.0" > 


<permission 
android:name="com.me.mypackage.permission.MAPS_RECEIVE" 
android:protectionLevel="signature" /> 
<uses-permission android:name="com.mhmedia.fuelfinder.permission.MAPS_RECEIVE"/> 
<uses-permission android:name="android.permission.INTERNET" /> 
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" /> 
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> 
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 

<uses-feature 
android:glEsVersion="0x00020000" 
android:required="true"/> 

<uses-sdk 
android:minSdkVersion="8" 
android:targetSdkVersion="19" /> 

<application 
android:allowBackup="true" 
android:icon="@drawable/logo" 
android:label="@string/app_name" 
android:theme="@style/AppTheme" > 
<meta-data 
android:name="com.google.android.maps.v2.API_KEY" 
android:value="myAPI_KEY" /> 
<activity 
android:name="com.me.mypackage.MainActivity" 
android:label="@string/app_name" > 
<intent-filter> 
<action android:name="android.intent.action.MAIN" /> 

<category android:name="android.intent.category.LAUNCHER" /> 
</intent-filter> 
</activity> 
<meta-data android:name="com.google.android.gms.version" 
android:value="@integer/google_play_services_version"></meta-data> 
</application> 

</manifest> 

MainActivity類別

public class MainActivity extends FragmentActivity implements LocationListener, 
GooglePlayServicesClient.ConnectionCallbacks, 
GooglePlayServicesClient.OnConnectionFailedListener, LocationSource { 

private GoogleMap mMap; 
private OnLocationChangedListener mListener; 
private LocationManager locationmanager; 
GoogleMap googlemap; 
LatLng myposition; 
ArrayList<Entry> entries = new ArrayList<Entry>(); 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
super.onCreate(savedInstanceState); 
setContentView(R.layout.activity_main);  
locationmanager = (LocationManager) getSystemService(LOCATION_SERVICE); 

if(locationmanager != null){ 
boolean gpsIsEnabled = locationmanager.isProviderEnabled(LocationManager.GPS_PROVIDER); 
boolean networkIsEnabled = locationmanager.isProviderEnabled(LocationManager.NETWORK_PROVIDER); 

if(gpsIsEnabled){ 
locationmanager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5000L, 10F, this); 
} 
else if(networkIsEnabled) 
{ 
locationmanager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 5000L, 10F, this); 
} 
else 
{ 
Toast.makeText(this, "GPS is not enabled", Toast.LENGTH_SHORT).show(); 
} 

setUpMapIfNeeded(); 
showmypoi(); 
} 

} 

@Override 
public void onPause() 
{ 
if(locationmanager != null){ 
locationmanager.removeUpdates(this); 
} 
super.onPause(); 
} 

@Override 
public void onResume(){ 
super.onResume(); 
setUpMapIfNeeded(); 
if(locationmanager != null){ 
mMap.setMyLocationEnabled(true); 
} 
} 

private void setUpMapIfNeeded() { 
if (mMap == null){ 
mMap = ((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.the_map)).getExtendedMap(); 

if (mMap != null){ 
setUpMap(); 
} 
mMap.setLocationSource(this); 
} 

} 

private void showmypoi() { 
InputStream is = null; 
is = this.getResources().openRawResource(R.raw.markers); 

ArrayList<Entry> entries = (ArrayList<Entry>) new ParserParsing().parse(is); 
for (int i = 0; i < entries.size(); i++){ 
mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.the_map)).getExtendedMap(); 
mMap.setClustering(new ClusteringSettings().enabled(false).addMarkersDynamically(true)); 
/* mMap.addMarker(new MarkerOptions() 
.position(lng) 
.icon(BitmapDescriptorFactory.fromResource(getResources().getIdentifier(icon, "drawable", getPackageName()) 
} 
} 

private void setUpMap() { 
mMap.setMyLocationEnabled(true); 

} 

@Override 
public void activate(OnLocationChangedListener listener) { 
mListener = listener; 


} 

@Override 
public void deactivate() { 
mListener = null; 

} 

@Override 
public void onConnectionFailed(ConnectionResult result) {} 

@Override 
public void onConnected(Bundle connectionHint) {} 

@Override 
public void onDisconnected() {} 

public void onCameraChange(CameraPosition cameraPosition){ 

} 

@Override 
public void onLocationChanged(Location location) { 
if(mListener != null){ 
mListener.onLocationChanged(location); 

LatLngBounds bounds = this.mMap.getProjection().getVisibleRegion().latLngBounds; 

if(!bounds.contains(new LatLng(location.getAltitude(), location.getLongitude())));{ 
mMap.animateCamera(CameraUpdateFactory.newLatLng(new LatLng(location.getLatitude(), location.getLongitude()))); 

} 

} 

} 

@Override 
public void onProviderDisabled(String provider) { 
Toast.makeText(this, "Provider Disabled", Toast.LENGTH_SHORT).show(); 

} 

@Override 
public void onProviderEnabled(String provider) { 
Toast.makeText(this, "Provider Enabled", Toast.LENGTH_SHORT).show(); 

} 

@Override 
public void onStatusChanged(String provider, int status, Bundle extras) { 
Toast.makeText(this, "Status Changed", Toast.LENGTH_SHORT).show(); 

} 


} 

我在做什麼錯?我正在絞盡腦汁想要解決這個問題。我有這麼多的標記添加到地圖我需要的地圖擴展

的集羣能力謝謝

+0

'mMap'很可能爲空。 – Raghunandan

+0

以什麼方式?因爲如果使用MapFragment,應用程序將啓動,因此在使用SupportMapFragment時會崩潰 –

回答

1

我已經想通了。我沒有在佈局文件中導入com.androidmapsextensions.SupportMapFragment,我導入了com.google.android.gms.maps.SupportMapFragment,因此地圖未加載。