Android由:java.lang.RuntimeException

时间:2018-12-16 14:08:34

标签: java android runtimeexception

我得到了一条错误消息,就像标题中一样,但是没有上下文,仅由以下原因引起:java.lang.RuntimeException如果我不知道是什么原因引起的,我应该如何解决。代码在这里:https://bitbucket.org/Hellscythe94/meet-up/src/master/

当我将此行添加到登录片段时显示错误: alertDialog.show();

但是即使我发表评论,它也不起作用...

请帮助我,我只是从android开始。

好的,我做了一个新的空白项目,只是添加了依赖项并尝试构建它,但是遇到了同样的问题。

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
}

这是我的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'

所以现在有人可以告诉我我在做什么错吗?

The problem

3 个答案:

答案 0 :(得分:3)

好的,我解决了。

结果是因为我得到了这是我的project / app / build.gradle

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

但是将其卸下后,它可以正常工作。 所以问题可能出在我做的事情在JAVA 1.7中是可以接受的,但在JAVA 1.8中是不可接受的。

答案 1 :(得分:1)

enter image description here从gradle中删除此内容:

  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
  }

并在您的gradle中添加configurations。

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'
        }
    }
}
}

enter image description here

答案 2 :(得分:0)

如果您有这笔礼物:

 compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

然后您要告诉android使用Java 8。

然后,如果您使用的是不支持Java 8的库(即使用Java 7中不允许的Java 8中的某些内容),则会发生问题

对我来说,发生问题的原因是我的gradle中有以下内容

implementation 'com.google.code.gson:gson:2.8.6'

似乎不支持Java 8,我解决了删除Gson库并使用moshi代替JSON进行JSON解析的问题

相关问题