android.support.v4.widget.DrawerLayout无法实例化 [英] android.support.v4.widget.DrawerLayout Cannot be instantiated

查看:112
本文介绍了android.support.v4.widget.DrawerLayout无法实例化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试预览我的MainActivity XML文件,但出现此错误:

I'm trying to preview my MainActivity XML file and I'm getting this error:

java.lang.ClassNotFoundException:android.support.v4.widget.DrawerLayoutImpl

java.lang.ClassNotFoundException: android.support.v4.widget.DrawerLayoutImpl

我的主片段和导航抽屉片段工作正常.

My Main Fragment and Navigation Drawer Fragment are working just fine.

在所有这些论坛中进行搜索,并尝试了很多方法,但无济于事.我知道这一定是库和gradle构建的问题,但是我不确定自己做错了什么:

Searched all over these forums and tried a bunch of things to no avail. I know it must be an issue with the library and my gradle build but I'm not sure what I'm doing wrong:

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')
}    

自从我使用导航抽屉以来,

v4是由android studio自动添加的.v13我加入了自己(通过进入项目结构->依赖关系并将其添加到其中),认为这会有所帮助.我将两个.jar文件都复制到了我的libs文件夹中,以为这也会有所帮助.清理过的项目/同步gradle完成了所有这些操作,不确定是否还有其他操作.

v4 was added automatically by android studio since I was using a navigation drawer. v13 I included myself (by going to project structure-->dependencies and adding it there) thinking it would help. I copied both .jar files to my libs folder thinking that would help as well. Cleaned project/synced gradle did all of that, not sure what else to do.

以防万一,这是Android Studio为我为activity_main.xml创建的内容

Just in case, here is what Android Studio created for me for 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.)    

推荐答案

重新安装Android Studio(v.2.2.2)(Ubuntu系统)后,我遇到了插件(文件->设置->插件)的问题,例如:

After re-installing Android Studio(v.2.2.2) (Ubuntu system) I had problems with plugins (File->Settings->Plugins) like in:

发现在Android Studio中加载插件的问题

所以我关闭了插件,却忘了打开它们.之后,发生了许多构建错误.其中之一:

So I switched off plugins and forgot to switch on them. After that many build errors occurred. One of them:

android.support.v4.widget.DrawerLayout无法实例化

当我重新注视Android Studio并再次打开所有插件时,所有错误都消失了.

When I restared Android Studio and switched on all plugins again all errors are disappeared.

这篇关于android.support.v4.widget.DrawerLayout无法实例化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆