原因:java.lang.NullPointerException:空对象引用上的FirebaseInstanceId

时间:2018-11-16 12:33:00

标签: java android firebase

使用Firebase获取令牌时出错

const { Command } = require('discord.js-commando');
const { oneLine } = require('common-tags');
const { RichEmbed } = require('discord.js');
const config = require('../../config.json');
var quotes = config.quotes;


module.exports = class EchoCommand extends Command {
    constructor(client) {
        super(client, {
            name: 'quote',
            group: 'quote',
            memberName: 'quote',
            description: 'Echoes a random Quote.',
            details: oneLine`,
            I'll say out a quote`,
            examples: ['quote']
        });
    }

    const avatarURL = message.author.avatar ? message.author.avatarURL: 'https://discordapp.com/assets/0e291f67c9274a1abdddeb3fd919cbaa.png';
    const embed = new Discord.RichEmbed()
      .setAuthor(`${message.author.tag}`, `${avatarURL}`);
      .setColor(0x0000FF);
      .setDescription(quotes[Math.floor(Math.random() * quotes.length)]);
      .setTimestamp();
    await message.channel.send({
      embed
    });
};

在我的活动中

 Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'com.google.android.gms.tasks.Task 
 com.google.firebase.iid.FirebaseInstanceId.getInstanceId()'
 on a null object reference

app build.gradle

 FirebaseInstanceId.getInstance().getInstanceId()
            .addOnCompleteListener(task -> {
                if (!task.isSuccessful()) {

                    return;
                }

                // Get new Instance ID token
                String token = task.getResult().getToken();
                Log.e("ID", "Firebase reg id: " + token);



            });

项目gradle

//顶层构建文件,您可以在其中添加所有子项目/模块共有的配置选项。

apply plugin: 'com.android.application'

android {
compileSdkVersion 28
//  buildToolsVersion '28.0.3'
defaultConfig {
    applicationId 'com.jlf.webcontxt'
    minSdkVersion 19
    targetSdkVersion 28
    versionCode 1
    versionName "1.0"
    multiDexEnabled true
    testInstrumentationRunner 
   "android.support.test.runner.AndroidJUnitRunner"
}

dataBinding {
    enabled = true
}

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }

    debug {

    }
    innerTest {

        matchingFallbacks = ['debug', 'release']
    }
    productFlavors {
    }
    lintOptions {
        abortOnError false
        checkReleaseBuilds false
    }


}
dependencies {
    implementation fileTree(include: ['*.jar66'], dir: 'libs')

    //noinspection GradleCompatible
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:design:28.0.0'


    implementation 'com.android.support.constraint:constraint-layout:2.0.0-alpha1'

    implementation 'com.pnikosis:materialish-progress:1.0'


    implementation files('libs/universal-image-loader-1.9.5.jar')

    implementation files('libs/orgwordutils.jar')

    implementation 'com.squareup.okhttp3:okhttp:3.10.0'
    implementation 'com.squareup.retrofit2:retrofit:2.4.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
    implementation 'com.squareup.retrofit2:converter-scalars:2.4.0'
    implementation 'com.github.bumptech.glide:glide:4.7.1'
    implementation 'com.github.bumptech.glide:okhttp3-integration:4.7.1'
    implementation 'com.github.d-max:spots-dialog:0.7@aar'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.7.1'
    implementation 'com.jakewharton:butterknife:8.8.1'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
    implementation 'me.himanshusoni.quantityview:quantity-view:1.2.0'
    implementation 'de.hdodenhof:circleimageview:2.2.0'
    implementation files('libs/core-3.0.1.jar')
    implementation 'com.android.support:cardview-v7:28.0.0'


    implementation 'com.github.tajchert:nammu:1.1.1'

    implementation 'com.android.support:multidex:1.0.1'

    implementation 'com.google.firebase:firebase-core:16.0.1'
    implementation 'com.google.firebase:firebase-messaging:17.3.4'

    implementation('com.github.qingmei2:QrCodeScannerView-Android:1.1.2')
     {
                transitive = false;
                exclude group: "com.android.support"
    }
    implementation 'com.github.ybq:Android-SpinKit:1.1.0'



}
productFlavors {
}
compileOptions {
    sourceCompatibility = '1.8'
    targetCompatibility = '1.8'
}
}

apply plugin: 'com.google.gms.google-services'

0 个答案:

没有答案