我最近使用Refactor将项目迁移到了androidX。所有实现均自动更改为androidx。 但是我无法使用支持设计布局示例:协调器布局 它在整个预览中仅显示灰色。
我用Google搜索并尝试了一些修复程序,例如更改了taregtSKDversion,但没有任何帮助。 我不知道我在做什么错。
这是build.gradle [app]
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.pratham.sitapuriya"
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0-beta01'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.1.0-alpha07'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.3.0-alpha01'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0-alpha01'
implementation 'com.android.volley:volley:1.1.1'
implementation 'com.google.android.material:material:1.1.0-alpha07'
repositories {
mavenCentral()
google()
}
dependencies {
implementation 'com.github.bumptech.glide:glide:4.9.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
}
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.squareup.retrofit2:retrofit:2.3.0'
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
dependencies {
implementation 'com.facebook.shimmer:shimmer:0.1.0@aar'
}
implementation 'com.github.marlonlom:timeago:4.0.1'
}
我尝试使用协调器布局
<androidx.coordinatorlayout.widget.CoordinatorLayout >
// Other Childs
</<androidx.coordinatorlayout.widget.CoordinatorLayout>
那是行不通的! [也将所有插件更新为最新版本] 请帮忙。
更新 添加后
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
布局正在工作,并且gradle已构建,没有任何错误。 但是当我运行该应用程序时,它仍然崩溃并给出此错误
06-24 12:11:34.212 18074-18074/com.pratham.sitapuriya E/dalvikvm: Could not find class 'androidx.core.view.ViewCompat$OnUnhandledKeyEventListenerWrapper', referenced from method androidx.core.view.ViewCompat.addOnUnhandledKeyEventListener
06-24 12:11:34.216 18074-18074/com.pratham.sitapuriya E/dalvikvm: Could not find class 'android.view.WindowInsets', referenced from method androidx.core.view.ViewCompat.dispatchApplyWindowInsets
06-24 12:11:34.228 18074-18074/com.pratham.sitapuriya E/dalvikvm: Could not find class 'android.view.WindowInsets', referenced from method androidx.core.view.ViewCompat.onApplyWindowInsets
06-24 12:11:34.229 18074-18074/com.pratham.sitapuriya E/dalvikvm: Could not find class 'android.view.View$OnUnhandledKeyEventListener', referenced from method androidx.core.view.ViewCompat.removeOnUnhandledKeyEventListener
06-24 12:11:34.239 18074-18074/com.pratham.sitapuriya E/dalvikvm: Could not find class 'androidx.core.view.ViewCompat$1', referenced from method androidx.core.view.ViewCompat.setOnApplyWindowInsetsListener
06-24 12:11:37.983 18074-18074/com.pratham.sitapuriya E/dalvikvm: Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method com.google.android.material.button.MaterialButtonHelper.unwrapBackgroundDrawable
06-24 12:11:37.989 18074-18074/com.pratham.sitapuriya E/dalvikvm: Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method com.google.android.material.button.MaterialButtonHelper.unwrapStrokeDrawable
06-24 12:11:37.992 18074-18074/com.pratham.sitapuriya E/dalvikvm: Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method com.google.android.material.button.MaterialButtonHelper.setRippleColor
06-24 12:11:38.022 18074-18074/com.pratham.sitapuriya E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.pratham.sitapuriya, PID: 18074
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.pratham.sitapuriya/com.pratham.sitapuriya.AccountActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2433)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2484)
at android.app.ActivityThread.access$800(ActivityThread.java:158)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1391)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5486)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:829)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:645)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.pratham.sitapuriya.AppunctionsKt.beautifyLayout(appunctions.kt:76)
at com.pratham.sitapuriya.AccountActivity.onCreate(AccountActivity.kt:14)
由于我的应用在迁移之前没有任何错误,因此我认为这些错误是由于androidx引起的。请弄清楚。谢谢
答案 0 :(得分:2)
您可以尝试使用稳定版
String[] arr = new String[] { "velo", "low", "vole", "lovee",
"volvell", "lowly", "lower", "lover", "levo", "loved", "love",
"lovee", "lowe", "lowes", "lovey", "lowan", "lowa", "evolve",
"loves", "volvelle", "lowed", "love" };
String s = "love";
Predicate<Character> p = x -> s.indexOf(x) > -1 ? true : false;
List<String> asList = Arrays.asList(arr);
asList.stream().forEach(x -> {
List<Character> chars = new ArrayList<>();
for (int i = 0; i < x.length(); i++) {
chars.add(x.charAt(i));
}
boolean anyMatch = chars.stream().allMatch(p);
if (anyMatch)
count++;
});
System.out.println(count);
然后执行Clean-Rebuild-Run。
仅供参考
当应用程序尝试使用具有空值的对象引用时,抛出