应用启动时崩溃,我的代码没有任何错误

时间:2019-02-09 20:59:09

标签: java android-studio

我是Firebase的新手,我试图创建此博客应用程序,但该应用程序在启动时崩溃,并且代码中没有错误

这是我的MainActivity代码:     包com.example.myblog;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.FirebaseDatabase;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}

@Override
protected void onStart() {
    super.onStart();
    FirebaseUser currentUser = FirebaseAuth.getInstance().getCurrentUser();
    if (currentUser == null) {
        Intent intent = new Intent(MainActivity.this, LoginActivity.class);
        startActivity(intent);
        finish();
    }
}

}

这也显示在logcat中,不知道是否有帮助 at com.example.myblog.MainActivity.onStart(MainActivity.java:22)

这些是我的依赖项

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
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'

implementation 'com.google.firebase:firebase-core:9.4.0'
implementation 'com.google.firebase:firebase-database:9.4.0'
implementation 'com.google.firebase:firebase-auth:9.4.0'
implementation 'com.google.firebase:firebase-storage:9.4.0'
implementation 'com.google.android.gms:play-services-auth:9.4.0'
implementation 'com.firebase:firebase-client-android:2.3.1'
implementation 'com.firebaseui:firebase-ui-database:0.4.0'
implementation 'com.squareup.picasso:picasso:2.5.2'}

应用插件:“ com.google.gms.google-services”

这是androidManifest:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myblog">

<uses-permission android:name="android.permission.INTERNET" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".LoginActivity"
        android:screenOrientation="portrait"></activity>
    <activity android:name=".MainActivity"
        android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

2 个答案:

答案 0 :(得分:0)

在Project gradle中,使用Google服务:4.0.0,而不是4.1.0。

答案 1 :(得分:0)

好的,所以我能够解决它。我忘记设置Firebase数据库和身份验证规则!