问题
I got an error message just like in the title but there is no context to it its just Caused by: java.lang.RuntimeException how am I supposed to know what to fix if I don't know what caused it. The code is here: https://bitbucket.org/Hellscythe94/meet-up/src/master/
The error showed when I added this line to the Login Fragment: alertDialog.show();
But it doesn't work even after I comment it...
Please help I'm just starting with android.
OK I made a new blank project and just added the dependencies and tried to build it but got the same problem.
This is my project/build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.google.gms:google-services:4.2.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
and this is my project/app/build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
multiDexEnabled true
applicationId "com.example.michalwolowiec.meetup"
minSdkVersion 19
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
def lifecycle_version = "1.1.1"
implementation fileTree(include: ['*.jar'], dir: 'libs')
//MultiDex
implementation 'com.android.support:multidex:1.0.3'
//App compat
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:support-media-compat:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
//ViewModel and LiveData
implementation "android.arch.lifecycle:extensions:$lifecycle_version"
//Lifecycles only (no ViewModel or LiveData).
//Support library depends on this lightweight import
implementation "android.arch.lifecycle:runtime:$lifecycle_version"
//firebase Authentication
implementation 'com.google.firebase:firebase-core:16.0.6'
implementation 'com.google.firebase:firebase-auth:16.1.0'
//firebase cloud Firebase
implementation 'com.google.firebase:firebase-firestore:17.1.4'
//butterknife and lombok
implementation 'com.jakewharton:butterknife:9.0.0-rc1'
annotationProcessor 'com.jakewharton:butterknife-compiler:9.0.0-rc1'
compileOnly 'org.projectlombok:lombok:1.18.4'
annotationProcessor 'org.projectlombok:lombok:1.18.4'
//google shit
implementation 'com.google.android.gms:play-services-maps:16.0.0'
implementation 'com.google.android.gms:play-services-location:16.0.0'
//RX
implementation 'io.reactivex.rxjava2:rxandroid:2.1.0'
implementation 'io.reactivex.rxjava2:rxjava:2.2.3'
//libraries
implementation 'io.nlopez.smartlocation:library:3.3.3'
implementation 'io.nlopez.smartlocation:rx:3.3.1'
implementation 'com.google.code.gson:gson:2.8.5'
//tests
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
apply
plugin: 'com.google.gms.google-services'
So now can someone tell what am I doing wrong ?
回答1:
Delete this from your gradle:
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
and add the configurations.all in your gradle:
configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
def requested = details.requested
if (requested.group == 'com.android.support') {
if (!requested.name.startsWith("multidex")) {
details.useVersion '28.0.0'
}
}
}
}
回答2:
OK, so I solved it.
Turns out because I got this is my project/app/build.gradle
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
But when removed it it works normally. So the problem probably was that I was doing something that was acceptable in JAVA 1.7 but not acceptable in JAVA 1.8.
回答3:
If you have this in your gradle :
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
then you are telling android to use java 8.
then the problem happens if you are using a library that does not support java 8 (i.e it uses something from java 7 that is not allowed in java 8)
for me the problem happens because I had the following in my gradle
implementation 'com.google.code.gson:gson:2.8.6'
which seems not to support java 8 , I have solved it be removing the Gson library and used moshi instead of it for json to model parsing
来源:https://stackoverflow.com/questions/53802932/android-caused-by-java-lang-runtimeexception