我尝试在我的一个应用程序中使用 OSMdroid,但我得到了这个:
在硬件设备 Android 4.0.3 (CM9) 上运行
从 logcat 记录:
06-25 16:56:07.389: E/AndroidRuntime(17760): java.lang.RuntimeException: Unable to start activity ComponentInfo{app.OSMMapViewActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class org.osmdroid.views.MapView
06-25 16:56:07.389: E/AndroidRuntime(17760): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2079)
06-25 16:56:07.389: E/AndroidRuntime(17760): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2104)
06-25 16:56:07.389: E/AndroidRuntime(17760): at android.app.ActivityThread.access$600(ActivityThread.java:132)
06-25 16:56:07.389: E/AndroidRuntime(17760): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1157)
06-25 16:56:07.389: E/AndroidRuntime(17760): at android.os.Handler.dispatchMessage(Handler.java:99)
06-25 16:56:07.389: E/AndroidRuntime(17760): at android.os.Looper.loop(Looper.java:137)
06-25 16:56:07.389: E/AndroidRuntime(17760): at android.app.ActivityThread.main(ActivityThread.java:4575)
06-25 16:56:07.389: E/AndroidRuntime(17760): at java.lang.reflect.Method.invokeNative(Native Method)
06-25 16:56:07.389: E/AndroidRuntime(17760): at java.lang.reflect.Method.invoke(Method.java:511)
06-25 16:56:07.389: E/AndroidRuntime(17760): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
06-25 16:56:07.389: E/AndroidRuntime(17760): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
06-25 16:56:07.389: E/AndroidRuntime(17760): at dalvik.system.NativeStart.main(Native Method)
06-25 16:56:07.389: E/AndroidRuntime(17760): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class org.osmdroid.views.MapView
06-25 16:56:07.389: E/AndroidRuntime(17760): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:691)
06-25 16:56:07.389: E/AndroidRuntime(17760): at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
06-25 16:56:07.389: E/AndroidRuntime(17760): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
06-25 16:56:07.389: E/AndroidRuntime(17760): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
06-25 16:56:07.389: E/AndroidRuntime(17760): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
06-25 16:56:07.389: E/AndroidRuntime(17760): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251)
06-25 16:56:07.389: E/AndroidRuntime(17760): at android.app.Activity.setContentView(Activity.java:1835)
06-25 16:56:07.389: E/AndroidRuntime(17760): at app.OSMMapViewActivity.onCreate(OSMMapViewActivity.java:16)
06-25 16:56:07.389: E/AndroidRuntime(17760): at android.app.Activity.performCreate(Activity.java:4465)
06-25 16:56:07.389: E/AndroidRuntime(17760): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
06-25 16:56:07.389: E/AndroidRuntime(17760): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2033)
06-25 16:56:07.389: E/AndroidRuntime(17760): ... 11 more
06-25 16:56:07.389: E/AndroidRuntime(17760): Caused by: java.lang.ClassNotFoundException: org.osmdroid.views.MapView
06-25 16:56:07.389: E/AndroidRuntime(17760): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
06-25 16:56:07.389: E/AndroidRuntime(17760): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
06-25 16:56:07.389: E/AndroidRuntime(17760): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
06-25 16:56:07.389: E/AndroidRuntime(17760): at android.view.LayoutInflater.createView(LayoutInflater.java:552)
06-25 16:56:07.389: E/AndroidRuntime(17760): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
06-25 16:56:07.389: E/AndroidRuntime(17760): ... 21 more
我希望这会对你有更多帮助。
地图屏幕.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<org.osmdroid.views.MapView
android:id="@+id/mapview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:clickable="true" />
</LinearLayout>
这是我的活动:
import org.osmdroid.tileprovider.tilesource.TileSourceFactory;
import org.osmdroid.util.GeoPoint;
import org.osmdroid.views.MapController;
import org.osmdroid.views.MapView;
import android.app.Activity;
import android.os.Bundle;
public class OSMMapViewActivity extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mapscreen);
MapView mMapView = (MapView) findViewById(R.id.mapview);
mMapView.setTileSource(TileSourceFactory.MAPNIK);
mMapView.setBuiltInZoomControls(true);
MapController mMapController = mMapView.getController();
mMapController.setZoom(13);
GeoPoint gPt = new GeoPoint(51500000, -150000);
//Centre map near to Hyde Park Corner, London
mMapController.setCenter(gPt);
}
}
我正在使用 OSMDroid 3.0.8 和 slf4j-1.5.8 和 eclipse。
编辑:
我注释掉了 setContentView() 和其他代码。我认为问题出在布局文件上...
编辑1:
问题已经解决了... :)
将 osmdroid 和其他 jar 从 libs/osmdroid 复制到 libs/ ^_^
无论如何感谢您的帮助!!!!
谢谢帮助