问题描述
我想尝试新的玩具,谷歌给了我们,我碰到一些麻烦。
I wanted to try out the new toys that google gave us and I've run into some trouble.
下面是我的build.gradle:
Here is my build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 'android-L'
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "com.tod.android.lpreviewtest"
minSdkVersion 'L'
targetSdkVersion 'L'
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:cardview-v7:+'
}
现在我的布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MyActivity">
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view"
android:layout_gravity="center"
android:layout_width="200dp"
android:layout_height="200dp"
card_view:cardCornerRadius="4dp">
<TextView
android:id="@+id/info_text"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.v7.widget.CardView>
</RelativeLayout>
当我切换到屏幕preVIEW在Android的工作室,我得到一个渲染错误:
When I switch to screen preview in android studio, I get a render error:
Rendering Problems The following classes could not be instantiated:
- android.support.v7.widget.CardView (Open Class, Show Exception)
Exception Details java.lang.ClassFormatError: Illegal field name "CardView.Dark"
in class android/support/v7/cardview/R$style at
java.lang.ClassLoader.defineClass1(ClassLoader.java:-2) at
java.lang.ClassLoader.defineClass(ClassLoader.java:792) at
java.lang.ClassLoader.defineClass(ClassLoader.java:635) at
java.lang.ClassLoader.loadClass(ClassLoader.java:424) at
java.lang.ClassLoader.loadClass(ClassLoader.java:411) at
java.lang.ClassLoader.loadClass(ClassLoader.java:357) at
android.support.v7.widget.CardView.initialize(CardView.java:69) at
android.support.v7.widget.CardView.<init>(CardView.java:60) at
java.lang.reflect.Constructor.newInstance(Constructor.java:526) 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)
我试着忽略错误并运行在AVD的应用程序,而一切编译罚款,没有cardview出现在布局。请帮帮忙!
I tried ignoring the error and running the app in an avd and while everything compiles fine, no cardview appears in the layout. Please help!
P.S。我使用的是最新的Android工作室公测0.8.0
P.s. I'm using the new Android Studio beta 0.8.0
推荐答案
这是Android的Studio中的一个错误,看到的
This is a bug in Android Studio, see https://code.google.com/p/android/issues/detail?id=79071
一个补丁的评论写道:这是造成卡片视图渲染失败CardView宣布风格的形式CardView.Dark由于该阵列生成的R类加载失败的
One of the comments of the patch reads: "This was causing card view rendering to fail. CardView declared styles of the form CardView.Dark due to which the generated R class failed to load."
下一个版本应该根据错误报告这个固定的(这个补丁分支工作室-1.0-dev的)。他们说,作为一种变通方法来构建项目一次,但这并不能帮我(即使我有完全相同的错误和堆栈跟踪)。
Next version should have this fixed according to the bug report (the patch is on branch studio-1.0-dev). They say to build the project once as a workaround, but this does not fix it for me (even though I have exactly the same error and stack trace).
这篇关于错误添加CardView到布局时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!