我在这里看到了很多像这样的问题,他们都有相同的答案,确保你有
编译'com.android.support:cardview-v7:26.0.0'
在build.gradle文件中,并确保在xml中使用完全限定名称...
<android.support.v7.widget.CardView
我在我的xml文件中使用它,并且我的build.gradle文件中有编译行。应用程序编译,但每当我在模拟器上运行应用程序时,我单击按钮启动ShowImagesActivity,它会在路径上找到“未找到类'android.support.v7.widget.CardView'消息崩溃... “
这是我的layout_images.xml文件......
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<adroid.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:padding="8dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="100dp">
<TextView
android:id="@+id/textViewName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Name"
android:textAlignment="center" />
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/textViewName" />
</RelativeLayout>
</adroid.support.v7.widget.CardView>
</LinearLayout>
这是我的build.gradle文件,应用程序一个......
apply plugin: 'com.android.application'
check.dependsOn 'assembleMinSdkJellybeanDebugAndroidTest', 'assembleMinSdkIcsDebugAndroidTest'
android {
compileSdkVersion 26
buildToolsVersion '26.0.0'
flavorDimensions "minSdkVersion"
defaultConfig {
applicationId "com.google.firebase.quickstart.auth"
minSdkVersion 26
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
lintOptions {
abortOnError false
}
productFlavors {
// Build variant with minSdk 16 to include Facebook and FirebaseUI libraries.
minSdkJellybean {
dimension "minSdkVersion"
minSdkVersion 16
}
// Build variant with minSdk 14, excludes Facebook and FirebaseUI libraries.
minSdkIcs {
dimension "minSdkVersion"
minSdkVersion 16
}
}
}
configurations.all {
resolutionStrategy.force 'com.android.support:support-annotations:26.0.0'
}
dependencies {
// Firebase Authentication
// Google Sign In SDK (only required for Google Sign In)
// Firebase UI
// Used in FirebaseUIActivity. The FirebaseUI-Android library has a minSdk level of 16
// so this library is only included in the minSdkJellybean variant.
// Facebook Android SDK (only required for Facebook Login)
// Used in FacebookLoginActivity. This is only compiled into the minSdkJellybean variant of this
// app. You can build a 'minSdkGingerbread' variant to test on devices with 9 <= SDK <= 15.
// Twitter Android SDK (only required for Twitter Login)
compile('com.twitter.sdk.android:twitter-core:1.6.6@aar') {
transitive = true
}
compile('com.twitter.sdk.android:twitter:1.13.1@aar') {
transitive = true
}
compile 'com.google.firebase:firebase-storage:11.2.0'
compile 'com.google.firebase:firebase-storage:11.2.0'
compile 'com.android.support:appcompat-v7:26.0.0'
compile 'com.android.support:animated-vector-drawable:26.0.0'
compile 'com.android.support:cardview-v7:26.0.0'
compile 'com.android.support:recyclerview-v7:26.0.0'
compile 'com.android.support:design:26.0.0'
compile 'com.firebaseui:firebase-ui:2.3.0'
compile 'com.google.firebase:firebase-auth:11.2.0'
compile 'com.google.android.gms:play-services-auth:11.2.0'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.google.firebase:firebase-database:11.2.0'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
androidTestCompile 'com.android.support.test:runner:0.5'
minSdkJellybeanCompile 'com.facebook.android:facebook-android-sdk:4.9.0'
minSdkJellybeanCompile 'com.android.support:customtabs:26.0.0'
}
apply plugin: 'com.google.gms.google-services'
在我的代码中我正在使用
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_images, parent, false);
ViewHolder viewHolder = new ViewHolder(v);
return viewHolder;
}
我拥有所有其他帖子我需要的所有内容,build.gradle中的编译行以及xml视图中的完全限定名称,应用程序编译完美,只要我尝试运行它就会崩溃单击启动ShowImagesActivity的按钮后的模拟器。如果它找不到类,它不应该编译失败吗?有没有其他解决方案,或者任何人都可以看到任何错误导致应用程序崩溃而无法找到该类?谢谢。
答案 0 :(得分:3)
检查您的输入,您错过了一个&#39; n&#39;在XML
中<adroid.support.v7.widget.CardView ...
答案 1 :(得分:3)
我遇到了同样的问题,但是我的库已更新为androidX
implementation 'androidx.cardview:cardview:1.0.0'
因此,我的问题通过使用标记解决了
<androidx.cardview.widget.CardView/>
答案 2 :(得分:1)