从Android Studio运行时,Android应用程序停止在模拟器上运行

时间:2017-05-01 20:43:57

标签: android android-studio

我按照YouTube上的Firebase Android Studio教程指导的代码,https://www.youtube.com/watch?v=tJVBXCNtUuk

然而,当我尝试在我的Android Studio上运行(几乎)相同的代码时,在按下“登录”按钮后不久,应用程序突然停止工作。

以下是我的登录活动的java代码:LoginActivity.java

package com.example.user.compounderapp;

import android.app.ProgressDialog;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;

import android.content.Intent;
import android.view.View;
import android.widget.Button;
//import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;

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 butterknife.ButterKnife;
import butterknife.InjectView;

public class LoginActivity extends AppCompatActivity implements View.OnClickListener {
    private static final String TAG = "LoginActivity";
    private static final int REQUEST_SIGNUP = 0;
    private boolean checked = false;
    private boolean patientChecked = false;
    private boolean doctorChecked = false;
    private boolean adminChecked = false;
    //private RadioGroup radioGroupLogin;
    private FirebaseAuth firebaseAuth;
    private ProgressDialog progressDialog;

    @InjectView(R.id.input_email) EditText _emailText;
    @InjectView(R.id.input_password) EditText _passwordText;
    @InjectView(R.id.btn_login) Button _loginButton;
    @InjectView(R.id.btnToSignup) Button _btnToSignup;
    //@InjectView(R.id.link_signup) TextView _signupLink;
    @InjectView(R.id.loginRadioGroup) RadioGroup radioGroupLogin;
    @InjectView(R.id.radioButtonPatient) RadioButton radioPatient;
    @InjectView(R.id.radioButtonDoctor) RadioButton radioDoctor;
    @InjectView(R.id.radioButtonAdmin) RadioButton radioAdmin;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        ButterKnife.inject(this);

        firebaseAuth = FirebaseAuth.getInstance();
        /*
        if(firebaseAuth.getCurrentUser()!=null)
        {
            startActivity(new Intent(this, P2.class));
        }
        */

        radioGroupLogin.setOnCheckedChangeListener(new OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(RadioGroup radioGroupLogin, int checkedId) {

                // find which radio button is selected

                if(checkedId == R.id.radioButtonPatient)
                    patientChecked = true;

                else if(checkedId == R.id.radioButtonDoctor)
                    doctorChecked = true;
                else if (checkedId == R.id.radioButtonAdmin)
                    adminChecked = true;



            }
        });


        progressDialog = new ProgressDialog(this);
        _loginButton.setOnClickListener(this);
        _btnToSignup.setOnClickListener(this);
    }

    private void userLogin()
    {
        String email = _emailText.getText().toString().trim();
        String password = _passwordText.getText().toString().trim();

        if (email.isEmpty() || !android.util.Patterns.EMAIL_ADDRESS.matcher(email).matches()) {
            _emailText.setError("enter a valid email address");
            return;
        } else {
            _emailText.setError(null);
            }
        if (password.isEmpty() || password.length() < 4 || password.length() > 10) {
            _passwordText.setError("between 4 and 10 alphanumeric characters");
            return;
        } else {
            _passwordText.setError(null);
        }
        if (radioGroupLogin.getCheckedRadioButtonId() == -1)
        {
            // no radio buttons are checked
            Toast.makeText(getApplicationContext(), "Please select whether Patient, Doctor or Admin", Toast.LENGTH_SHORT).show();
            return;
        }

        progressDialog.setMessage("Logging in...");
        progressDialog.show();

        firebaseAuth.signInWithEmailAndPassword(email, password).addOnCompleteListener(this, new OnCompleteListener<AuthResult>(){
            @Override
            public void onComplete(@NonNull Task<AuthResult> task)
            {
                progressDialog.dismiss();
                if(task.isSuccessful())
                {
                    finish();
                    startActivity(new Intent(getApplicationContext(), P2.class));
                }
            }
        });
    }

    @Override
    public void onClick(View view)
    {
        if(view == _loginButton)
            userLogin();
        if(view == _btnToSignup)
        {
            if(patientChecked==true)
            {finish();
             startActivity(new Intent(this,SignupActivity.class));
            }
            else if(doctorChecked==true)
            {finish();
                startActivity(new Intent(this,SignupDoctorActivity.class));

            }
        }
    }
}

登录的XML代码是:activity_login.xml

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fitsSystemWindows="true">

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="56dp"
        android:paddingLeft="24dp"
        android:paddingRight="24dp">

        <ImageView
            android:id="@+id/imageView"
            android:layout_width="wrap_content"
            android:layout_height="72dp"
            android:layout_gravity="center_horizontal"
            android:layout_marginBottom="24dp"
            android:src="@drawable/logo" />

        <!-- Email Label -->
        <TableRow
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">
            <RadioGroup
                android:orientation="horizontal"
                android:id="@+id/loginRadioGroup"
                >
        <RadioButton
            android:id="@+id/radioButtonPatient"
            android:layout_width="120dp"
            android:layout_height="wrap_content"
            android:text="Patient"
            />
        <RadioButton
            android:id="@+id/radioButtonDoctor"
            android:layout_width="120dp"
            android:layout_height="wrap_content"
            android:text="Doctor"
            />
        <RadioButton
            android:id="@+id/radioButtonAdmin"
            android:layout_width="120dp"
            android:layout_height="wrap_content"
            android:text="Admin"
            />
            </RadioGroup>
        </TableRow>

        <!--Email label-->
        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="8dp"
            android:layout_marginBottom="8dp">

            <EditText android:id="@+id/input_email"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="textEmailAddress"
                android:hint="Email" />
        </android.support.design.widget.TextInputLayout>

        <!-- Password Label -->
        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="8dp"
            android:layout_marginBottom="8dp">
            <EditText android:id="@+id/input_password"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="textPassword"
                android:hint="Password"/>
        </android.support.design.widget.TextInputLayout>

        <android.support.v7.widget.AppCompatButton
            android:id="@+id/btn_login"
            android:layout_width="fill_parent"
            android:layout_height="37dp"
            android:layout_marginTop="24dp"
            android:layout_marginBottom="24dp"
            android:padding="10dp"
            android:text="Login"/>

        <TextView
            android:id="@+id/link_signup"
            android:layout_width="334dp"
            android:layout_height="wrap_content"
            android:layout_marginBottom="24dp"
            android:gravity="center"
            android:text="No account yet?"
            android:textSize="16dip" />

        <Button
            android:id="@+id/btnToSignup"
            style="@style/Widget.AppCompat.Button.Borderless.Colored"
            android:layout_width="343dp"
            android:layout_height="wrap_content"
            android:text="Create one Here." />


    </LinearLayout>
</ScrollView>

错误日志:

05-02 02:31:37.958 3257-3257/com.example.user.compounderapp I/InstantRun: Starting Instant Run Server for com.example.user.compounderapp
05-02 02:31:37.958 1565-2012/system_process W/ActivityManager: getRunningAppProcesses: caller 10060 does not hold REAL_GET_TASKS; limiting output
05-02 02:31:37.962 3257-3277/com.example.user.compounderapp V/FA: Using measurement service
05-02 02:31:37.962 3257-3277/com.example.user.compounderapp V/FA: Connecting to remote service
05-02 02:31:37.970 3257-3257/com.example.user.compounderapp D/FirebaseApp: Notifying auth state listeners.
05-02 02:31:37.971 3257-3257/com.example.user.compounderapp D/FirebaseApp: Notified 0 auth state listeners.
05-02 02:31:37.971 3257-3257/com.example.user.compounderapp D/FirebaseApp: Notifying auth state listeners.
05-02 02:31:37.971 3257-3257/com.example.user.compounderapp D/FirebaseApp: Notified 0 auth state listeners.
05-02 02:31:37.997 3257-3279/com.example.user.compounderapp D/FirebaseInstanceId: topic sync succeeded
05-02 02:31:38.001 3257-3277/com.example.user.compounderapp D/FA: Connected to remote service
05-02 02:31:38.001 3257-3277/com.example.user.compounderapp V/FA: Processing queued up service tasks: 1
05-02 02:31:38.541 1172-1529/? W/AudioFlinger: write blocked for 1475 msecs, 1 delayed writes, thread 0xb5cac000
05-02 02:31:39.791 1565-1672/system_process D/TaskPersister: removeObsoleteFile: deleting file=47_task.xml
05-02 02:31:39.791 1565-1672/system_process D/TaskPersister: removeObsoleteFile: deleting file=47_task_thumbnail.png
05-02 02:31:42.249 2229-3256/com.google.android.gms W/PlatformStatsUtil: Could not retrieve Usage & Diagnostics setting. Giving up.
05-02 02:31:43.037 3257-3277/com.example.user.compounderapp V/FA: Inactivity, disconnecting from the service
05-02 02:31:48.097 3257-3273/com.example.user.compounderapp W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.

1 个答案:

答案 0 :(得分:0)

在崩溃日志中,存在导致问题的特定行:

05-02 02:31:48.097 3257-3273/com.example.user.compounderapp W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.

为了在Android上完全使用Firebase,以下是先决条件

  
      
  • 运行Google Play服务9.0.0或更高版本的Android设备
  •   
  • Android SDK Manager中的Google Play服务SDK
  •   
  • Android Studio 1.5或更高版本
  •   
  • Android Studio项目及其包名称。
  •   

您可以在此处查看更多信息:Android Firebase DynamiteModule: Failed to load module descriptor