我正在向youtube学习如何使用android studio从firebase创建用户。我正确地遵循了istruction,但我遇到了问题。问题是,.createUserWithEmailAndPassword语法。似乎创建用户的任务不起作用,但在日志中没有显示任何错误。我已经在stackoverflow.com上提供了什么建议,但问题仍然存在。请帮我解决这个问题。谢谢
的AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.ahmadfaza.newfoodorderclient">
<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=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
content_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.example.ahmadfaza.newfoodorderclient.MainActivity"
tools:showIn="@layout/activity_main">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Sign Up"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter email"
android:id="@+id/editEmail"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter password"
android:id="@+id/editPass"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Sign Up"
android:onClick="signupButtonClicked"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Already have an account ?"
android:layout_marginTop="250dp"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Sign In"
android:onClick="signinButtonClicked"
/>
</LinearLayout>
MainActivity.java
package com.example.ahmadfaza.newfoodorderclient;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.EditText;
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.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
public class MainActivity extends AppCompatActivity {
private EditText email,pass;
private DatabaseReference mDatabase;
private FirebaseAuth mAuth;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
email = (EditText) findViewById(R.id.editEmail);
pass = (EditText) findViewById(R.id.editPass);
mAuth = FirebaseAuth.getInstance();
mDatabase = FirebaseDatabase.getInstance().getReference().child("users");
}
public void signupButtonClicked(View view)
{
final String email_text = email.getText().toString().trim();
final String pass_text = pass.getText().toString().trim();
if(!TextUtils.isEmpty(email_text) && !TextUtils.isEmpty(pass_text))
{
mAuth.createUserWithEmailAndPassword(email_text,pass_text).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
public void onComplete(@NonNull Task<AuthResult> task) {
if(task.isSuccessful())
{
String user_id = mAuth.getCurrentUser().getUid();
DatabaseReference current_user = mDatabase.child(user_id);
current_user.child("Name").setValue(email_text);
}
}
});
}
}
}