错误: java.lang.RuntimeException:无法在loader dalvik.system中实例化活动ComponentInfo {com.example.my_map / com.example.my_map.activities.MainActivity}:java.lang.ClassNotFoundException:com.example.my_map.activities.MainActivity。 PathClassLoader [/data/app/com.example.my_map-1.apk]
主要活动
package com.example.my_map;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import android.os.Bundle;
import android.widget.FrameLayout;
public class MainActivity extends SherlockFragmentActivity {
private FrameLayout frameMap;
private GoogleMap myMap;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
frameMap = (FrameLayout) findViewById(R.id.frame_map);
SupportMapFragment mapFragment = SupportMapFragment.newInstance();
getSupportFragmentManager().beginTransaction().add(R.id.frame_map , mapFragment , "MAP").commit();
}
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
myMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentByTag("MAP")).getMap();
myMap.setMyLocationEnabled(true);
myMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
}
}
清单
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.my_map"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15"/>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"></uses-permission>
<permission android:name="com.example.my_map.permission.MAPS_RECEIVE" android:protectionLevel="signature"></permission>
<uses-feature android:glEsVersion="0x00020000" android:required="true">
</uses-feature>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main" >
<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.maps.v2.API_KEY" android:value="BLABLABLA" />
</application>
</manifest>
XML活动
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<framelayout
android:id="@+id/frame_map"
android:layout_height="match_parent"
android:layout_width="match_parent">
</framelayout>
</RelativeLayout>