Android Maps Extensions出错了

时间:2014-01-20 15:35:37

标签: android google-maps google-maps-markers android-maps-extensions

好的,所以我进行了搜索和搜索,我正处于让这个示例项目工作的最后障碍,但是当我尝试实现android-maps-extensions时,它仍然无法在我的手机上启动(Galaxy S4) 2.0(我有加载到标记添加到地图,但需要动态)

我所有的库都设置好并且正常工作,但每当我将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 Class

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();

}


}

我做错了什么?我正在绞尽脑汁试图解决这个问题。我有很多标记要添加到地图中我需要地图扩展的聚类功能

谢谢

1 个答案:

答案 0 :(得分:1)

我已经弄清楚了。我没有在我的布局文件中导入com.androidmapsextensions.SupportMapFragment,我导入了com.google.android.gms.maps.SupportMapFragment,因此没有加载地图。