0
ボタン(bSave)をクリックし、名前、年齢、Idをリアルタイムfirebaseデータベースに保存しようとすると、多分問題は、アプリケーションとfirebaseの間の接続ですか?Firebaseデータベースに情報を保存すると "App stopped stopped"と表示される場合は、私のコードで何が間違っています
String id=databaseDrivers.push().getKey();
Driver driver=new Driver(id,name,age);
databaseDrivers.child(id).setValue(driver);
getKey()
サーブから値を取得します。私は、これはので、それはあると思い
RegisterAcitivity
package com.example.mher.loginregister;
import android.app.ProgressDialog;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
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;
import java.security.cert.CertPathBuilderSpi;
public class RegisterActivity extends AppCompatActivity {
private EditText etAge;
private EditText etName;
private EditText etEmail;
private EditText etPassword;
private Button bRegister;
private Button bSave;
private ProgressDialog progressDialog;
private FirebaseAuth firebaseAuth;
DatabaseReference databaseDrivers;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
firebaseAuth=FirebaseAuth.getInstance();
progressDialog=new ProgressDialog(this);
etAge=(EditText) findViewById(R.id.etAge);
etName=(EditText) findViewById(R.id.etName);
etEmail=(EditText) findViewById(R.id.etEmail);
etPassword=(EditText) findViewById(R.id.etPassword);
bRegister=(Button) findViewById(R.id.bRegister);
bSave=(Button) findViewById(R.id.bSave);
databaseDrivers= FirebaseDatabase.getInstance().getReference();
bSave.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
adddriver();
}
});
bRegister.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
registeruser();
}
});
}
private void adddriver()
{
String name=etName.getText().toString().trim();
String age=etAge.getText().toString().trim();
if(!TextUtils.isEmpty(name))
{
String id=databaseDrivers.push().getKey();
Driver driver=new Driver(id,name,age);
databaseDrivers.child(id).setValue(driver);
}
else
{
Toast.makeText(this,"Please enter a name",Toast.LENGTH_SHORT);
}
}
private void registeruser()
{
String email=etEmail.getText().toString().trim();
String password=etPassword.getText().toString().trim();
if(TextUtils.isEmpty(email))
{
Toast.makeText(this,"Please Enter Your Email",Toast.LENGTH_SHORT).show();
return;
}
if(TextUtils.isEmpty(password))
{
Toast.makeText(this,"Please Enter Your Password",Toast.LENGTH_SHORT).show();
return;
}
progressDialog.setMessage("Registering User");
progressDialog.show();
firebaseAuth.createUserWithEmailAndPassword(email,password).addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if(task.isSuccessful())
{
Toast.makeText(RegisterActivity.this,"Registered Successfully",Toast.LENGTH_SHORT).show();
progressDialog.hide();
}
else
{
Toast.makeText(RegisterActivity.this,"Could Not Register Successfully",Toast.LENGTH_SHORT).show();
progressDialog.hide();
}
}
});
}
}
ドライバクラス
package com.example.mher.loginregister;
public class Driver {
String DriverId;
String DriverName;
String DriverAge;
public Driver()
{
}
public Driver(String driverId, String driverName, String driverAge) {
DriverId = driverId;
DriverName = driverName;
DriverAge = driverAge;
}
public String getDriverId() {
return DriverId;
}
public String getDriverName() {
return DriverName;
}
public String getDriverAge() {
return DriverAge;
}
}
LogCatを使用して、クラッシュに関連するJavaスタックトレースを調べます。https://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-solve-this – CommonsWare