Android 谷歌地图不工作:Classnotfound异常
我已经使用GoogleSDK Eclipse创建了GoogleMapMarker示例项目。说到执行,bin文件似乎无法帮助我正确地安装到设备上并使其工作。详细而言,Logcat显示以下消息: 找不到类异常错误日志Android 谷歌地图不工作:Classnotfound异常,android,google-maps-markers,classnotfoundexception,Android,Google Maps Markers,Classnotfoundexception,我已经使用GoogleSDK Eclipse创建了GoogleMapMarker示例项目。说到执行,bin文件似乎无法帮助我正确地安装到设备上并使其工作。详细而言,Logcat显示以下消息: 找不到类异常错误日志 05-16 11:25:50.742: E/AndroidRuntime(25267): Process: com.example.testgpsmarker, PID: 25267 05-16 11:25:50.742: E/AndroidRuntime(25267): java.l
05-16 11:25:50.742: E/AndroidRuntime(25267): Process: com.example.testgpsmarker, PID: 25267
05-16 11:25:50.742: E/AndroidRuntime(25267): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.testgpsmarker/com.example.testgpsmarker.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.example.testgpsmarker.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.testgpsmarker-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.testgpsmarker-2, /vendor/lib, /system/lib]]
05-16 11:25:50.742: E/AndroidRuntime(25267): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2121)
05-16 11:25:50.742: E/AndroidRuntime(25267): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
05-16 11:25:50.742: E/AndroidRuntime(25267): at android.app.ActivityThread.access$800(ActivityThread.java:135)
05-16 11:25:50.742: E/AndroidRuntime(25267): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
05-16 11:25:50.742: E/AndroidRuntime(25267): at android.os.Handler.dispatchMessage(Handler.java:102)
05-16 11:25:50.742: E/AndroidRuntime(25267): at android.os.Looper.loop(Looper.java:136)
05-16 11:25:50.742: E/AndroidRuntime(25267): at android.app.ActivityThread.main(ActivityThread.java:5017)
05-16 11:25:50.742: E/AndroidRuntime(25267): at java.lang.reflect.Method.invokeNative(Native Method)
05-16 11:25:50.742: E/AndroidRuntime(25267): at java.lang.reflect.Method.invoke(Method.java:515)
05-16 11:25:50.742: E/AndroidRuntime(25267): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
05-16 11:25:50.742: E/AndroidRuntime(25267): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
05-16 11:25:50.742: E/AndroidRuntime(25267): at dalvik.system.NativeStart.main(Native Method)
05-16 11:25:50.742: E/AndroidRuntime(25267): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.testgpsmarker.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.testgpsmarker-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.testgpsmarker-2, /vendor/lib, /system/lib]]
05-16 11:25:50.742: E/AndroidRuntime(25267): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
05-16 11:25:50.742: E/AndroidRuntime(25267): at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
05-16 11:25:50.742: E/AndroidRuntime(25267): at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
05-16 11:25:50.742: E/AndroidRuntime(25267): at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
05-16 11:25:50.742: E/AndroidRuntime(25267): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2112)
下面是我的代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mapView = (MapView) findViewById(R.id.mapview);
mc = mapView.getController();
int latitude = 22285520 ;
int longitude = 114157690;
showLocation(latitude,longitude);
}
private Handler h = new Handler(){
// Invoked by the method onTap()
// in the class CurrentLocationOverlay
@Override
public void handleMessage(Message msg) {
Bundle data = msg.getData();
// Getting the Latitude of the location
int latitude = data.getInt("latitude");
// Getting the Longitude of the location
int longitude = data.getInt("longitude");
// Show the location in the Google Map
showLocation(latitude,longitude);
}
};
protected void showLocation(int latitude, int longitude) {
// TODO Auto-generated method stub
mapView.setBuiltInZoomControls(true);
// Getting the MapController
MapController mapController = mapView.getController();
// Getting Overlays of the map
List<Overlay> overlays = mapView.getOverlays();
// Getting Drawable object corresponding to a resource image
Drawable drawable = getResources().getDrawable(R.drawable.marker);
// Creating an ItemizedOverlay
TouchedLocationOverlay locationOverlay = new TouchedLocationOverlay(drawable,h);
// Getting the MapController
MapController mc = mapView.getController();
// Creating an instance of GeoPoint, to display in Google Map
GeoPoint p = new GeoPoint(
latitude,
longitude
);
// Locating the point in the Google Map
mc.animateTo(p);
// Creating an OverlayItem to mark the point
OverlayItem overlayItem = new OverlayItem(p, "Item", "Item");
// Adding the OverlayItem in the LocationOverlay
locationOverlay.addOverlay(overlayItem);
// Clearing the overlays
overlays.clear();
// Adding locationOverlay to the overlay
overlays.add(locationOverlay);
// Redraws the map
mapView.invalidate();
}
@覆盖
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mapView=(mapView)findViewById(R.id.mapView);
mc=mapView.getController();
国际纬度=22285520;
国际经度=114157690;
展示地点(纬度、经度);
}
私有处理程序h=新处理程序(){
//由方法onTap()调用
//在类CurrentLocationOverlay中
@凌驾
公共无效handleMessage(消息消息消息){
Bundle data=msg.getData();
//获取位置的纬度
int纬度=data.getInt(“纬度”);
//获取位置的经度
int longitude=data.getInt(“经度”);
//在谷歌地图中显示位置
展示地点(纬度、经度);
}
};
受保护的空显示位置(整数纬度、整数经度){
//TODO自动生成的方法存根
mapView.SetBuilTinZoomControl(真);
//获取MapController
MapController MapController=mapView.getController();
//获取地图的覆盖图
List overlays=mapView.getOverlays();
//获取与资源映像对应的可绘制对象
Drawable Drawable=getResources().getDrawable(R.Drawable.marker);
//创建ItemizedOverlay
TouchedLocationOverlay locationOverlay=新的TouchedLocationOverlay(可绘制,h);
//获取MapController
MapController mc=mapView.getController();
//创建要在Google地图中显示的GeoPoint实例
地质点p=新的地质点(
纬度,
经度
);
//在谷歌地图中定位该点
司马迁(p),;
//创建覆盖项以标记点
OverlayItem OverlayItem=新的OverlayItem(p,“项目”,“项目”);
//在LocationOverlay中添加OverlayItem
locationOverlay.addOverlay(overlayItem);
//清除覆盖物
覆盖。清除();
//将locationOverlay添加到覆盖中
叠加。添加(locationOverlay);
//重新绘制地图
mapView.invalidate();
}
\
布局
<com.google.android.maps.MapView
android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:enabled="true"
android:apiKey="sdsdfsdfscdsfsdf" />
显示
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.testgpsmarker"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="18"
android:targetSdkVersion="19" />
<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="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.testgpsmarker.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>
</application>
</manifest>
我应该更正哪个配置 也粘贴xml和清单。需要布局文件和清单。请将其发布,以便更容易确定问题。此外,请提供活动的完整代码,包括导入。若要解决此问题,请右键单击
项目、属性、生成路径,然后转到“导出”选项卡。在那里,确保选中了“Android私有库”
。清理和重建应该让您走上正轨……或者右键单击项目并选择“属性”。“属性”面板将打开。从左侧菜单进入Java构建路径->订购并导出
。从下面的列表中,取消选中“Android依赖项”
旁边的框。最后清理项目并运行。