我想从我的Android应用程序将数据上传到火力基地。当我尝试验证我的注册表单时,会出现此错误。我已经尝试了解决方案,但对我没有用。
我在下面共享了错误和注册Java类。
这是我的错误
E/AndroidRuntime: FATAL EXCEPTION: main
Process: official96.yohan.lms, PID: 4434
java.lang.IllegalStateException: Could not execute method for android:onClick
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:389)
at android.view.View.performClick(View.java:5610)
at android.view.View$PerformClick.run(View.java:22265)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:384)
at android.view.View.performClick(View.java:5610)
at android.view.View$PerformClick.run(View.java:22265)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
Caused by: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process official96.yohan.lms. Make sure to call FirebaseApp.initializeApp(Context) first.
at com.google.firebase.FirebaseApp.getInstance(com.google.firebase:firebase-common@@16.0.1:219)
at com.google.firebase.auth.FirebaseAuth.getInstance(Unknown Source)
at official96.yohan.lms.signup.signupButtonClicked(signup.java:58)
at java.lang.reflect.Method.invoke(Native Method)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:384)
at android.view.View.performClick(View.java:5610)
at android.view.View$PerformClick.run(View.java:22265)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
还有我的java类:
package official96.yohan.lms;
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.view.View;
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.FirebaseApp;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
public class signup extends AppCompatActivity
{
EditText mail,mophone,pswd,usrusr;
TextView lin,sup;
private FirebaseAuth mAuth;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_signup);
FirebaseApp.initializeApp(this);
mAuth = FirebaseAuth.getInstance();
getSupportActionBar().setTitle("Sign Up"); // for set actionbar title
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
sup = (TextView) findViewById(R.id.sup);
lin = (TextView) findViewById(R.id.lin);
usrusr = (EditText) findViewById(R.id.usrusr);
pswd = (EditText) findViewById(R.id.pswrdd);
mail = (EditText) findViewById(R.id.mail);
mophone = (EditText) findViewById(R.id.mobphone);
Typeface custom_font = Typeface.createFromAsset(getAssets(), "fonts/LatoLight.ttf");
Typeface custom_font1 = Typeface.createFromAsset(getAssets(), "fonts/LatoRegular.ttf");
mophone.setTypeface(custom_font);
sup.setTypeface(custom_font1);
pswd.setTypeface(custom_font);
lin.setTypeface(custom_font);
usrusr.setTypeface(custom_font);
mail.setTypeface(custom_font);
}
public void signupButtonClicked(View view) {
mAuth.createUserWithEmailAndPassword(mail.getText().toString(), pswd.getText().toString())
.addOnCompleteListener(signup.this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
Toast.makeText(signup.this, "New User Created successfully!", Toast.LENGTH_SHORT).show();
FirebaseUser user = mAuth.getCurrentUser();
Intent it = new Intent(signup.this,Login.class);
startActivity(it);
} else {
Toast.makeText(signup.this, "Authentication failed.",
Toast.LENGTH_SHORT).show();
}
}
});
}
}
答案 0 :(得分:1)
我遇到了类似的问题,这个post帮助我解决了问题。我忘了安装Google Play服务。
如果您正在模拟器上运行它,请检查您是否已在
中启用了Google Play服务。Tools -> Android -> SDK Manager -> SDK Tools -> Google play services
安装后,重新启动Android Studio和模拟器
我必须将com.google.gms:google-services:从4.1.0降级到4.0.0的另一个重要点,它对我来说就像魅力。帖子here对此有所帮助
dependencies {
classpath 'com.android.tools.build:gradle:3.3.0'
classpath 'com.google.gms:google-services:4.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}