我尝试在我的一个应用程序中使用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
我希望这会对你有所帮助。
mapscreen.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()和其他代码。我认为这个问题与布局文件有关......
EDIT1:
问题解决了...... :)
从libs / osmdroid复制osmdroid和其他jar 到libs / ^ _ ^
无论如何,谢谢你的帮助!!!!
帮助
答案 0 :(得分:1)
问题是eclipse需要重启才能正确加载外部库。
感谢您的帮助!!!
答案 1 :(得分:1)
我遇到了同样的问题。 我解决了它:
立即运行该应用程序。我应该工作。 注意:我已经通过选择project-&gt; properties-&gt; Java Built path-&gt; Libraries将它添加到项目路径中。
所需的库是:
答案 2 :(得分:0)
您是否在Android Manifest文件中添加了适当的权限?
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
虽然ACCESS_FINE_LOCATION
ACCESS_COARSE_LOCATION
可以替换为MapView
,但缺少其中任何一项,通常会导致任何类型的{{1}}失败。