2016-02-21 112 views
0

我什至不能創建一個簡單的地圖。我正在使用osmdroid-android-5.1庫,並且據我所知,我不需要添加5.0版和更高版本中的slf4j庫。Osmdroid 5.1 java.lang.NoClassDefFoundError

activity_main.xml如下:

<include 
    layout="@layout/app_bar_main" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" /> 

<android.support.design.widget.NavigationView 
    android:id="@+id/nav_view" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:layout_gravity="start" 
    android:fitsSystemWindows="true" 
    app:headerLayout="@layout/nav_header_main" 
    app:menu="@menu/activity_main_drawer" /> 

content_main.xml包含圖如下:

<org.osmdroid.views.MapView android:id="@+id/map" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    tilesource="Mapnik" /> 

AndroidManifest.xml如下:

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> 
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> 
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> 
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 
<uses-permission android:name="android.permission.INTERNET" /> 
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 

<application 
    android:allowBackup="true" 
    android:icon="@mipmap/ic_launcher" 
    android:label="@string/app_name" 
    android:supportsRtl="true" 
    android:theme="@style/AppTheme"> 
    <activity 
     android:name=".MainActivity" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme.NoActionBar"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
</application> 

當我打的activity_main預覽,我得到一個錯誤:

java.lang.NoClassDefFoundError: Could not initialize class org.osmdroid.tileprovider.constants.OpenStreetMapTileProviderConstants 
    at org.osmdroid.tileprovider.MapTileProviderArray.getMapTile(MapTileProviderArray.java:93) 
    at org.osmdroid.views.overlay.TilesOverlay$1.handleTile(TilesOverlay.java:185) 
    at org.osmdroid.util.TileLooper.loop(TileLooper.java:34) 
    at org.osmdroid.views.overlay.TilesOverlay.drawTiles(TilesOverlay.java:164) 
    at org.osmdroid.views.overlay.TilesOverlay.draw(TilesOverlay.java:151) 
    at org.osmdroid.views.overlay.DefaultOverlayManager.onDraw(DefaultOverlayManager.java:107) 
    at org.osmdroid.views.MapView.dispatchDraw(MapView.java:1008) 
    at android.view.View.draw(View.java:16088) 
    at android.view.ViewGroup.drawChild_Original(ViewGroup.java:3609) 
    at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:61) 
    at android.view.ViewGroup.drawChild(ViewGroup.java:3609) 
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3399) 
    at android.view.View.draw(View.java:16088) 
    at android.view.ViewGroup.drawChild_Original(ViewGroup.java:3609) 
    at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:61) 
    at android.view.ViewGroup.drawChild(ViewGroup.java:3609) 
    at android.support.design.widget.CoordinatorLayout.drawChild(CoordinatorLayout.java:1077) 
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3399) 
    at android.view.View.draw(View.java:16181) 
    at android.view.View.draw(View.java:16090) 
    at android.view.ViewGroup.drawChild_Original(ViewGroup.java:3609) 
    at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:61) 
    at android.view.ViewGroup.drawChild(ViewGroup.java:3609) 
    at android.support.v4.widget.DrawerLayout.drawChild(DrawerLayout.java:1229) 
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3399) 
    at android.view.View.draw(View.java:16181) 
    at android.view.View.draw(View.java:16090) 
    at android.view.ViewGroup.drawChild_Original(ViewGroup.java:3609) 
    at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:61) 
    at android.view.ViewGroup.drawChild(ViewGroup.java:3609) 
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3399) 
    at android.view.View.draw(View.java:16088) 
    at android.view.ViewGroup.drawChild_Original(ViewGroup.java:3609) 
    at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:61) 
    at android.view.ViewGroup.drawChild(ViewGroup.java:3609) 
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3399) 
    at android.view.View.draw(View.java:16088) 
    at android.view.ViewGroup.drawChild_Original(ViewGroup.java:3609) 
    at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:61) 
    at android.view.ViewGroup.drawChild(ViewGroup.java:3609) 
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3399) 
    at android.view.View.draw(View.java:16181) 
    at com.android.layoutlib.bridge.impl.RenderSessionImpl.render(RenderSessionImpl.java:431) 
    at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:428) 
    at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:350) 
    at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:510) 
    at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:498) 
    at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:888) 
    at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:498) 
    at com.android.tools.idea.rendering.RenderTask.access$600(RenderTask.java:72) 
    at com.android.tools.idea.rendering.RenderTask$3.call(RenderTask.java:610) 
    at com.android.tools.idea.rendering.RenderTask$3.call(RenderTask.java:607) 
    at com.android.tools.idea.rendering.RenderService.runRenderAction(RenderService.java:362) 
    at com.android.tools.idea.rendering.RenderTask.render(RenderTask.java:607) 
    at com.android.tools.idea.rendering.RenderTask.render(RenderTask.java:629) 
    at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager.doRender(AndroidLayoutPreviewToolWindowManager.java:652) 
    at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager.access$1700(AndroidLayoutPreviewToolWindowManager.java:80) 
    at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager$7$1.run(AndroidLayoutPreviewToolWindowManager.java:594) 
    at com.intellij.openapi.progress.impl.CoreProgressManager$2.run(CoreProgressManager.java:152) 
    at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:452) 
    at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:402) 
    at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:54) 
    at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:137) 
    at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager$7.run(AndroidLayoutPreviewToolWindowManager.java:589) 
    at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:320) 
    at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:310) 
    at com.intellij.util.ui.update.MergingUpdateQueue$2.run(MergingUpdateQueue.java:254) 
    at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:269) 
    at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:227) 
    at com.intellij.util.ui.update.MergingUpdateQueue.run(MergingUpdateQueue.java:217) 
    at com.intellij.util.concurrency.QueueProcessor.runSafely(QueueProcessor.java:238) 
    at com.intellij.util.Alarm$Request$1.run(Alarm.java:351) 
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) 
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) 
    at java.lang.Thread.run(Thread.java:745) 

任何想法,那麼該錯誤可能與不能實現這麼簡單的事情(除非我沒有看到任何明顯的東西)?

回答

2

osmdroid不提供intellij試圖呈現的「預覽」。該常量類嘗試掃描本地存儲以用作下載緩存。它可以更好地處理。

無論如何,要解決您的問題,只需點擊播放按鈕並運行應用程序。它應該在Android設備或模擬器上工作得很好