我试图预览我的MainActivity XML文件,但我收到此错误:
java.lang.ClassNotFoundException:android.support.v4.widget.DrawerLayoutImpl
我的主片段和导航抽屉片段工作得很好。
在这些论坛上搜索并尝试了一些无济于事的事情。我知道这应该是图书馆和我的gradle构建的一个问题,但我不确定我做错了什么:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion '21.0.0'
defaultConfig {
applicationId "com.example.example"
minSdkVersion 17
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:21.0.0'
compile 'com.parse.bolts:bolts-android:1.1.2'
compile 'com.android.support:support-v13:21.0.0'
compile fileTree(dir: 'libs', include: 'Parse-*.jar')
compile project(':facebook')
}
自从我使用导航抽屉以来,android工作室自动添加了v4。 v13我自己(通过转到项目结构 - >依赖关系并在那里添加它)认为它会有所帮助。我将两个.jar文件复制到我的libs文件夹中,认为这也有帮助。清理过的项目/同步的gradle做了所有这些,不知道还能做什么。
以防万一,这是Android Studio为我创建的activity_main.xml
<!-- A DrawerLayout is intended to be used as the top-level content view using match_parent for both width and height to consume the full space available. -->
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<!-- As the main content view, the view below consumes the entire
space available using match_parent in both dimensions. -->
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- android:layout_gravity="start" tells DrawerLayout to treat
this as a sliding drawer on the left side for left-to-right
languages and on the right side for right-to-left languages.
If you're not building against API 17 or higher, use
android:layout_gravity="left" instead. -->
<!-- The drawer is given a fixed width in dp and extends the full height of
the container. -->
<fragment android:id="@+id/navigation_drawer"
android:layout_width="@dimen/navigation_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start"
android:name="com.example.example.NavigationDrawerFragment"
tools:layout="@layout/fragment_navigation_drawer" />
</android.support.v4.widget.DrawerLayout>
整个堆栈痕迹
java.lang.ClassNotFoundException: android.support.v4.widget.DrawerLayoutImpl
at com.android.tools.idea.rendering.RenderClassLoader.findClass(RenderClassLoader.java:53)
at org.jetbrains.android.uipreview.ProjectClassLoader.findClass(ProjectClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.)
at java.lang.ClassLoader.loadClass(ClassLoader.)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.)
at java.lang.ClassLoader.defineClass(ClassLoader.)
at java.lang.ClassLoader.defineClass(ClassLoader.)
at com.android.tools.idea.rendering.RenderClassLoader.loadClassFromJar(RenderClassLoader.java:93)
at org.jetbrains.android.uipreview.ProjectClassLoader.loadClassFromModuleOrDependency(ProjectClassLoader.)
at org.jetbrains.android.uipreview.ProjectClassLoader.load(ProjectClassLoader.java:89)
at com.android.tools.idea.rendering.RenderClassLoader.findClass(RenderClassLoader.java:56)
at org.jetbrains.android.uipreview.ProjectClassLoader.findClass(ProjectClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.)
at java.lang.ClassLoader.loadClass(ClassLoader.)
at org.jetbrains.android.uipreview.ViewLoader.loadClass(ViewLoader.)
at org.jetbrains.android.uipreview.ViewLoader.loadView(ViewLoader.java:96)
at com.android.tools.idea.rendering.LayoutlibCallback.loadView(LayoutlibCallback.)
at android.view.BridgeInflater.loadCustomView(BridgeInflater.)
at android.view.BridgeInflater.createViewFromTag(BridgeInflater.)
at android.view.LayoutInflater.inflate(LayoutInflater.)
at android.view.LayoutInflater.inflate(LayoutInflater.)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.)
at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.)
at com.android.tools.idea.rendering.RenderService$3.compute(RenderService.)
at com.android.tools.idea.rendering.RenderService$3.compute(RenderService.)
at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.)
at com.android.tools.idea.rendering.RenderService.createRenderSession(RenderService.)
at com.android.tools.idea.rendering.RenderService.render(RenderService.)
at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager.doRender(AndroidLayoutPreviewToolWindowManager.)
at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager.access$1900(AndroidLayoutPreviewToolWindowManager.java:80)
at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager$7$1.run(AndroidLayoutPreviewToolWindowManager.)
at com.intellij.openapi.progress.impl.ProgressManagerImpl$2.run(ProgressManagerImpl.)
at com.intellij.openapi.progress.ProgressManager.executeProcessUnderProgress(ProgressManager.)
at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.)
at com.intellij.openapi.progress.impl.ProgressManagerImpl.runProcess(ProgressManagerImpl.)
at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager$7.run(AndroidLayoutPreviewToolWindowManager.)
at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.)
at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.)
at com.intellij.util.ui.update.MergingUpdateQueue$2.run(MergingUpdateQueue.)
at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.)
at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.)
at com.intellij.util.ui.update.MergingUpdateQueue.run(MergingUpdateQueue.)
at com.intellij.util.concurrency.QueueProcessor.runSafely(QueueProcessor.)
at com.intellij.util.Alarm$Request$1.run(Alarm.)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.)
at java.util.concurrent.FutureTask.run(FutureTask.)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.)
at java.lang.Thread.run(Thread.)
答案 0 :(得分:0)
重新安装Android Studio(v.2.2.2)(Ubuntu系统)后,我遇到了插件问题(File-&gt; Settings-&gt; Plugins),如:
Problems found loading Plugins in Android Studio
所以我关闭了插件并忘了打开它们。之后发生了许多构建错误。其中之一:
android.support.v4.widget.DrawerLayout无法实例化
当我重新安装Android Studio并再次打开所有插件时,所有错误都消失了。