无法实例化类“android.support.v4.view.ViewPager”

时间:2014-10-19 09:10:24

标签: java android gradle

我遇到了一些麻烦,包括Android支持库。 我已经安装了支持库和支持库,并在app文件夹内的build.gradle文件中包含了“compile”指令(如https://developer.android.com/tools/support-library/setup.html中所述)。 虽然Gradle构建没有错误,但我发现XML代码的Render Preview给出了以下错误:

Rendering Problems The following classes could not be instantiated:
- android.support.v4.view.ViewPager (Open Class, Show Exception)

异常堆栈:

java.lang.ClassNotFoundException: android.support.v4.view.ViewConfigurationCompat$HoneycombViewConfigurationVersionImpl
    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.java:306)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(ClassLoader.java:637)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:471)
    at com.android.tools.idea.rendering.RenderClassLoader.loadClassFromJar(RenderClassLoader.java:93)
    at org.jetbrains.android.uipreview.ProjectClassLoader.loadClassFromModuleOrDependency(ProjectClassLoader.java:108)
    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.java:306)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    at android.support.v4.view.ViewConfigurationCompat.<clinit>(ViewConfigurationCompat.java:87)
    at android.support.v4.view.ViewPager.initViewPager(ViewPager.java:367)
    at android.support.v4.view.ViewPager.<init>(ViewPager.java:355)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at org.jetbrains.android.uipreview.ViewLoader.createNewInstance(ViewLoader.java:375)
    at org.jetbrains.android.uipreview.ViewLoader.loadView(ViewLoader.java:100)
    at com.android.tools.idea.rendering.LayoutlibCallback.loadView(LayoutlibCallback.java:172)
    at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:207)
    at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:132)
    at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:802)
    at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:778)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:500)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:381)
    at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:400)
    at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:329)
    at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:332)
    at com.android.tools.idea.rendering.RenderService$3.compute(RenderService.java:575)
    at com.android.tools.idea.rendering.RenderService$3.compute(RenderService.java:564)
    at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:932)
    at com.android.tools.idea.rendering.RenderService.createRenderSession(RenderService.java:564)
    at com.android.tools.idea.rendering.RenderService.render(RenderService.java:691)
    at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager.doRender(AndroidLayoutPreviewToolWindowManager.java:604)
    at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager.access$1900(AndroidLayoutPreviewToolWindowManager.java:80)
    at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager$7$1.run(AndroidLayoutPreviewToolWindowManager.java:546)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl$2.run(ProgressManagerImpl.java:178)
    at com.intellij.openapi.progress.ProgressManager.executeProcessUnderProgress(ProgressManager.java:209)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:212)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl.runProcess(ProgressManagerImpl.java:171)
    at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager$7.run(AndroidLayoutPreviewToolWindowManager.java:541)
    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:327)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:439)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
    at java.lang.Thread.run(Thread.java:695)

奇怪的是,看起来HoneyComb库有问题,但我使用的是Android L APK,所以它根本不应该给我那种错误

1 个答案:

答案 0 :(得分:4)

如果您使用的是android studio:

Right click App folder
Open Module settings -> Dependencies and Add "com.android.support:support-v4:20.0.0.

Android Studio