簡體   English   中英

無法實例化以下類:android.support.design.widget.CoordinatorLayout

[英]The following classes could not be instantiated: android.support.design.widget.CoordinatorLayout

有人知道這是關於什么的嗎?

這是我的依賴項:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:design:22.2.0'
    compile 'com.android.support:appcompat-v7:22.2.0'
    compile 'com.android.support:cardview-v7:22.0.0'
    compile 'com.android.support:gridlayout-v7:22.0.0'
    compile 'com.android.support:palette-v7:22.0.0'
    compile 'com.android.support:recyclerview-v7:22.0.0'
}

我從 Android 支持庫中導入了所有內容並同步了 Gradle。 有人知道為什么我在布局中遇到渲染問題嗎?

這是錯誤日志:


java.lang.NoClassDefFoundError: Could not initialize class android.support.design.widget.CoordinatorLayout
    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:413)
    at org.jetbrains.android.uipreview.ViewLoader.loadView(ViewLoader.java:105)
    at com.android.tools.idea.rendering.LayoutlibCallback.loadView(LayoutlibCallback.java:177)
    at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:214)
    at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:142)
    at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:806)
    at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:782)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:385)
    at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:413)
    at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:321)
    at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:350)
    at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:497)
    at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:485)
    at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:894)
    at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:485)
    at com.android.tools.idea.rendering.RenderTask.render(RenderTask.java:590)
    at com.intellij.android.designer.designSurface.AndroidDesignerEditorPanel$6.run(AndroidDesignerEditorPanel.java:480)
    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: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)

在導入支持庫並同步 Gradles 需要重建您的項目后,我也面臨與您的場景相同的問題。

在我完成此程序后,它對我有用,我希望這會有所幫助。

無法實例化以下類:android.support.design.widget.CoordinatorLayout

這僅僅是因為android.support.design.widget.CoordinatorLayout在 24.1.0 版本中添加的 所以,支持庫依賴是不正確的。 依賴項至少應更新到版本24.1.0或使用最新的支持庫 (28.0.0)。 像這樣的東西:

dependencies {

    compile 'com.android.support:design:28.0.0'
    compile 'com.android.support:appcompat-v7:28.0.0'
    compile 'com.android.support:cardview-v7:28.0.0'
    compile 'com.android.support:gridlayout-v7:28.0.0'
    compile 'com.android.support:palette-v7:28.0.0'
    compile 'com.android.support:recyclerview-v7:28.0.0'
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM