Я получаю эту ошибку в проекте, над которым я не работал некоторое время:
Это сообщение об ошибке (я правильно понимаю, когда начинается действие):
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.app, PID: 12798
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.app/com.example.app.GettingStarted}: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.google.firebase.auth.internal.zzab.zzf(int)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2450)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
at android.app.ActivityThread.access$1200(ActivityThread.java:165)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1373)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5593)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.google.firebase.auth.internal.zzab.zzf(int)' on a null object reference
at com.google.firebase.auth.FirebaseAuth.addIdTokenListener(Unknown Source)
at com.google.firebase.firestore.auth.FirebaseAuthCredentialsProvider.<init>(com.google.firebase:firebase-firestore@@17.1.5:76)
at com.google.firebase.firestore.FirebaseFirestore.newInstance(com.google.firebase:firebase-firestore@@17.1.5:111)
at com.google.firebase.firestore.FirestoreMultiDbComponent.get(com.google.firebase:firebase-firestore@@17.1.5:51)
at com.google.firebase.firestore.FirebaseFirestore.getInstance(com.google.firebase:firebase-firestore@@17.1.5:89)
at com.google.firebase.firestore.FirebaseFirestore.getInstance(com.google.firebase:firebase-firestore@@17.1.5:74)
at com.example.app.GettingStarted.onCreate(GettingStarted.java:92)
at android.app.Activity.performCreate(Activity.java:6102)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2403)
А это часть деятельности:
public class GettingStarted extends AppCompatActivity implements View.OnClickListener {
public static String RESUME_MATCH_KEY = "resumeMatch";
public static String TAG = "GettingStarted.java";
private FirebaseFirestore firestore;
private FirebaseUser user;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_getting_started);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivity(new Intent(GettingStarted.this, NewMatchActivity.class));
}
});
user = FirebaseAuth.getInstance().getCurrentUser();
//FIREBASE FIRESTORE
firestore = FirebaseFirestore.getInstance(); //this is where the error keeps happening
FirebaseFirestoreSettings firestoreSettings = new FirebaseFirestoreSettings.Builder()
.setTimestampsInSnapshotsEnabled(true)
.build();
firestore.setFirestoreSettings(firestoreSettings);
(closing tags and rest of the code)
Я пытался исправить проблему путем обновления зависимостей, но это не изменило ошибку. Я также попытался обновить файл google-services.json.
Спасибо за вашу помощь!
Обновление:
Это мои файлы build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
buildToolsVersion '28.0.3'
defaultConfig {
multiDexEnabled true
applicationId "com.example.app"
minSdkVersion 19
targetSdkVersion 28
versionCode 59
versionName "3.6.259"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dexOptions {
}
lintOptions {
checkReleaseBuilds false
}
}
dependencies {
api 'com.android.support:design:28.0.0'
api 'com.android.support:support-v4:28.0.0'
api 'com.android.support:support-vector-drawable:28.0.0'
api 'com.android.support:recyclerview-v7:28.0.0'
api 'com.android.support:cardview-v7:28.0.0'
api 'com.android.support:appcompat-v7:28.0.0'
api 'com.android.support.constraint:constraint-layout:1.1.3'
api "com.android.support:customtabs:28.0.0"
api "com.google.android.gms:play-services-base:16.1.0"
api "com.google.android.gms:play-services-auth:16.0.1"
api "com.google.android.gms:play-services-flags:16.0.1"
api 'com.crashlytics.sdk.android:crashlytics:2.9.8'
api 'com.google.firebase:firebase-core:16.0.6'
api 'com.google.firebase:firebase-messaging:17.3.4'
api 'com.google.firebase:firebase-appindexing:17.1.0'
api 'com.google.firebase:firebase-invites:16.0.6'
api "com.firebaseui:firebase-ui-auth:4.1.0"
api 'com.google.firebase:firebase-firestore:17.1.5'
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation fileTree(include: ['*.jar'], dir: 'libs')
}
// Add to the bottom of the file - this is for Google Firebase
apply plugin: 'com.google.gms.google-services'
А вот и второй:
// 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.3.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
// Add this line
classpath 'com.google.gms:google-services:4.2.0'
}
}
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
google()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}