尝试运行新活动时,Android应用程序意外崩溃

时间:2016-07-15 18:30:55

标签: android

当我尝试切换到我的应用中的某个活动时,它会崩溃。这是我在手机上运行时的logcat。

以下是我开始的活动:

package com.epicodus.parkr;

import android.app.ProgressDialog;
import android.content.Intent;
import android.graphics.Typeface;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;

import butterknife.Bind;
import butterknife.ButterKnife;

public class MainActivity extends AppCompatActivity implements V   View.OnClickListener {

private FirebaseAuth mAuth;

private ProgressDialog mSignInProgressDialog;

@Bind(R.id.headline)TextView mHeadline;
@Bind(R.id.headline2) TextView mHeadline2;
@Bind(R.id.signUpButton)Button mSignUpButton;
@Bind(R.id.loginButton) Button mLoginButton;
@Bind(R.id.emailInput) EditText mEmailInput;
@Bind(R.id.passwordInput) EditText mPasswordInput;

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

//        createSignInProgressDialog();
        mAuth = FirebaseAuth.getInstance();
        ButterKnife.bind(this);

    Typeface newFont = Typeface.createFromAsset(getAssets(), "fonts/Lobster-Regular.ttf");
    mHeadline.setTypeface(newFont);
    mHeadline2.setTypeface(newFont);

    mSignUpButton.setOnClickListener(this);
    mLoginButton.setOnClickListener(this);

}

@Override
public void onClick(View v){
    if(v == mSignUpButton){
        Intent signUpIntent = new Intent (MainActivity.this, SignUpActivity.class);
        startActivity(signUpIntent);
    }else if(v == mLoginButton){
//            mSignInProgressDialog.show();
        login();
        finish();
    }
}

private void login(){

    final String email = mEmailInput.getText().toString();
    final String pass = mPasswordInput.getText().toString();

    if(!isNotEmpty(email) || !isNotEmpty(pass)) return;

    mAuth.signInWithEmailAndPassword(email, mPasswordInput.getText().toString())
            .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {

                    if (task.isSuccessful()) {
//                            mSignInProgressDialog.dismiss();
                        Intent loginIntent = new Intent (MainActivity.this, AccountActivity.class);
                        startActivity(loginIntent);
                        finish();
                    } else if (!task.isSuccessful()){
                        Toast.makeText(MainActivity.this, "Please Try Again", Toast.LENGTH_SHORT).show();
                        finish();
                    }
                }
            });
}

private void createSignInProgressDialog() {
    mSignInProgressDialog = new ProgressDialog(this);
    mSignInProgressDialog.setTitle("Loading...");
    mSignInProgressDialog.setMessage("Signing In...");
    mSignInProgressDialog.setCancelable(false);
}

private Boolean isNotEmpty(String email){
    if(email.equals("")){
        mEmailInput.setError("Blank Field");
        return false;
    }
 return true;
}

}

以下是我想要进行的活动:

package com.epicodus.parkr;

import android.content.Intent;
import android.graphics.Typeface;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;

import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;

import butterknife.Bind;
import butterknife.ButterKnife;

public class AccountActivity extends AppCompatActivity implements View.OnClickListener {

private FirebaseAuth mAuth;
private String uid;
private DatabaseReference mSpecificUserReference;

@Bind(R.id.userNameDisplay) TextView mUserNameDisplay;
@Bind(R.id.headline) TextView mHeadline;
@Bind(R.id.logOutButton) Button mLogOutButton;
@Bind(R.id.findSpotsButton) Button mFindSpotsButton;

@Override
protected void onCreate(Bundle savedInstanceState) {

    mAuth = FirebaseAuth.getInstance();
    uid = mAuth.getCurrentUser().getUid();
    mSpecificUserReference = FirebaseDatabase.getInstance().getReference().child(Constants.FIREBASE_CHILD_USER).child(uid);

    mSpecificUserReference.addValueEventListener(new ValueEventListener() {

        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            String userName = dataSnapshot.child("fullName").getValue().toString();
             mUserNameDisplay.setText(userName);
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    });


    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_account);
    ButterKnife.bind(this);

    Typeface newFont = Typeface.createFromAsset(getAssets(), "fonts/Lobster-Regular.ttf");
    mHeadline.setTypeface(newFont);

    Intent infoIntent = getIntent();
    String userName = infoIntent.getStringExtra("user");
    mUserNameDisplay.setText(userName);

    mFindSpotsButton.setOnClickListener(this);
    mLogOutButton.setOnClickListener(this);
}

private void logout() {
    FirebaseAuth.getInstance().signOut();
    Intent intent = new Intent(AccountActivity.this, MainActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    startActivity(intent);
    finish();
}

@Override
public void onClick(View view) {
    if(view == mLogOutButton){
        logout();
    } else if (view == mFindSpotsButton){
        Intent findSpotIntent = new Intent (AccountActivity.this, MapsActivity.class);
        startActivity(findSpotIntent);
    }
}
}

以下是从我的手机上运行的logcat:

    07-15 11:08:29.800 16082-16082/com.epicodus.parkr E/Zygote: MountEmulatedStorage()
    07-15 11:08:29.800 16082-16082/com.epicodus.parkr E/Zygote: v2
    07-15 11:08:29.800 16082-16082/com.epicodus.parkr E/SELinux: [DEBUG]     get_category: variable seinfo: default sensitivity: NULL, cateogry: NULL
    07-15 11:08:34.574 16082-16312/com.epicodus.parkr E/DynamiteModule: Failed to load module descriptor class: Didn't find class "com.google.android.gms.dynamite.descriptors.com.google.firebase.auth.ModuleDescriptor" on path: DexPathList[[zip file "/data/app/com.epicodus.parkr-2/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
    07-15 11:08:34.604 16082-16312/com.epicodus.parkr E/DynamiteModule: Failed to load module descriptor class: Didn't find class "com.google.android.gms.dynamite.descriptors.com.google.firebase.auth.ModuleDescriptor" on path: DexPathList[[zip file "/data/app/com.epicodus.parkr-2/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
    07-15 11:08:35.365 16082-16082/com.epicodus.parkr E/DynamiteModule: Failed to load module descriptor class: Didn't find class "com.google.android.gms.dynamite.descriptors.com.google.android.gms.crash.ModuleDescriptor" on path: DexPathList[[zip file "/data/app/com.epicodus.parkr-2/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
    07-15 11:08:47.557 16082-16312/com.epicodus.parkr E/DynamiteModule: Failed to load module descriptor class: Didn't find class "com.google.android.gms.dynamite.descriptors.com.google.firebase.auth.ModuleDescriptor" on path: DexPathList[[zip file "/data/app/com.epicodus.parkr-2/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]

这是模拟器的logcat:

    07-15 11:28:07.449 2941-3074/com.epicodus.parkr E/DynamiteModule: Failed to load module descriptor class: Didn't find class "com.google.android.gms.dynamite.descriptors.com.google.firebase.auth.ModuleDescriptor" on path: DexPathList[[zip file "/data/app/com.epicodus.parkr-2/base.apk"],nativeLibraryDirectories=[/data/app/com.epicodus.parkr-2/lib/x86, /vendor/lib, /system/lib]]
    07-15 11:28:07.462 2941-3074/com.epicodus.parkr E/DynamiteModule: Failed to load module descriptor class: Didn't find class "com.google.android.gms.dynamite.descriptors.com.google.firebase.auth.ModuleDescriptor" on path: DexPathList[[zip file "/data/app/com.epicodus.parkr-2/base.apk"],nativeLibraryDirectories=[/data/app/com.epicodus.parkr-2/lib/x86, /vendor/lib, /system/lib]]
    07-15 11:28:07.550 2941-2941/com.epicodus.parkr E/DynamiteModule: Failed to load module descriptor class: Didn't find class "com.google.android.gms.dynamite.descriptors.com.google.android.gms.crash.ModuleDescriptor" on path: DexPathList[[zip file "/data/app/com.epicodus.parkr-2/base.apk"],nativeLibraryDirectories=[/data/app/com.epicodus.parkr-2/lib/x86, /vendor/lib, /system/lib]]
    07-15 11:28:17.925 2941-3074/com.epicodus.parkr E/DynamiteModule: Failed to load module descriptor class: Didn't find class "com.google.android.gms.dynamite.descriptors.com.google.firebase.auth.ModuleDescriptor" on path: DexPathList[[zip file "/data/app/com.epicodus.parkr-2/base.apk"],nativeLibraryDirectories=[/data/app/com.epicodus.parkr-2/lib/x86, /vendor/lib, /system/lib]]
    07-15 11:28:22.893 2941-3074/com.epicodus.parkr E/DynamiteModule: Failed to load module descriptor class: Didn't find class "com.google.android.gms.dynamite.descriptors.com.google.firebase.auth.ModuleDescriptor" on path: DexPathList[[zip file "/data/app/com.epicodus.parkr-2/base.apk"],nativeLibraryDirectories=[/data/app/com.epicodus.parkr-2/lib/x86, /vendor/lib, /system/lib]]
    07-15 11:28:22.895 2941-3074/com.epicodus.parkr E/DynamiteModule: Failed to load module descriptor class: Didn't find class "com.google.android.gms.dynamite.descriptors.com.google.firebase.auth.ModuleDescriptor" on path: DexPathList[[zip file "/data/app/com.epicodus.parkr-2/base.apk"],nativeLibraryDirectories=[/data/app/com.epicodus.parkr-2/lib/x86, /vendor/lib, /system/lib]]
    07-15 11:28:23.036 2941-3090/com.epicodus.parkr E/Surface: getSlotFromBufferLocked: unknown buffer: 0xaa959c80
    07-15 11:28:23.271 3286-3286/com.epicodus.parkr:background_crash E/DynamiteModule: Failed to load module descriptor class: Didn't find class "com.google.android.gms.dynamite.descriptors.com.google.android.gms.crash.ModuleDescriptor" on path: DexPathList[[zip file "/data/app/com.epicodus.parkr-2/base.apk"],nativeLibraryDirectories=[/data/app/com.epicodus.parkr-2/lib/x86, /vendor/lib, /system/lib]]
    07-15 11:28:32.963 2941-3074/com.epicodus.parkr E/DynamiteModule: Failed to load module descriptor class: Didn't find class "com.google.android.gms.dynamite.descriptors.com.google.firebase.auth.ModuleDescriptor" on path: DexPathList[[zip file "/data/app/com.epicodus.parkr-2/base.apk"],nativeLibraryDirectories=[/data/app/com.epicodus.parkr-2/lib/x86, /vendor/lib, /system/lib]]

以下是app level build.gradle文件:

apply plugin: 'com.android.application'

android {
compileSdkVersion 24
buildToolsVersion "24.0.0"

defaultConfig {
    applicationId "com.epicodus.parkr"
    minSdkVersion 15
    targetSdkVersion 24
    versionCode 1
    versionName "1.0"
}
packagingOptions {
    exclude 'META-INF/DEPENDENCIES.txt'
    exclude 'META-INF/DEPENDENCIES'
    exclude 'META-INF/dependencies.txt'
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/license.txt'
    exclude 'META-INF/LGPL2.1'
    exclude 'META-INF/NOTICE.txt'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/notice.txt'
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
  }
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.0.0'
compile 'com.jakewharton:butterknife:7.0.1'
compile 'com.google.firebase:firebase-database:9.0.0'
compile 'com.google.firebase:firebase-auth:9.0.0'
compile 'com.google.android.gms:play-services:9.0.0'

compile 'com.firebaseui:firebase-ui-database:0.4.1'
compile 'com.android.support:recyclerview-v7:+'
compile 'com.google.android.gms:play-services-appindexing:9.0.0'
}

configurations.all {
   resolutionStrategy {
      force 'com.android.support:design:23.4.0'
      force 'com.android.support:support-v4:23.4.0'
      force 'com.android.support:appcompat-v7:23.4.0'
 }
}


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

和项目一级:

 buildscript {
    repositories {
        jcenter()
    }
   dependencies {
        classpath 'com.android.tools.build:gradle:2.1.2'
        classpath 'com.google.gms:google-services:3.0.0'
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
    }
}

   allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

1 个答案:

答案 0 :(得分:0)

首先检查您是否拥有将Firebase添加到Android项目的所有prerequisites

  1. 运行Android 2.3(Gingerbread)或更新版本的设备, Google Play服务9.2.1或更高版本
  2. Android SDK Manager中的Google Play服务SDK(
  3. Android Studio 1.5或更高版本
  4. Android Studio项目及其包名称
  5. 如果它不起作用,请检查Firebase内的登录方法&gt; Auth Dashboard 已禁用。启用它,你应该很高兴。