致命异常:主要PID:3825

时间:2018-07-31 14:05:56

标签: java android

我正在按照youtube中的教程将数据保存到数据库Firebase中,但是 当我运行项目时,我的应用程序崩溃了。有人可以帮我吗?

运行我的应用程序时,此错误显示在我的logcat中:

07-31 13:33:16.488 3825-3825/com.personalcoding.firebaserealtimedatabase E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.personalcoding.firebaserealtimedatabase, PID: 3825
java.lang.NoSuchMethodError: No virtual method zzbqo()Z in class Lcom/google/firebase/FirebaseApp; or its super classes (declaration of 'com.google.firebase.FirebaseApp' appears in /data/app/com.personalcoding.firebaserealtimedatabase-1/split_lib_dependencies_apk.apk)
    at com.google.firebase.database.FirebaseDatabase.getInstance(Unknown Source)
    at com.google.firebase.database.FirebaseDatabase.getInstance(Unknown Source)
    at com.personalcoding.firebaserealtimedatabase.MainActivity.onCreate(MainActivity.java:28)
    at android.app.Activity.performCreate(Activity.java:6237)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
    at android.app.ActivityThread.-wrap11(ActivityThread.java)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:148)

这是我的主要活动代码:

public class MainActivity extends AppCompatActivity {

    EditText    editTextName;
    Button      buttonAdd;
    Spinner spinnerGenres;

    DatabaseReference databaseArtists;

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

        databaseArtists = FirebaseDatabase.getInstance().getReference("artists");

        editTextName = (EditText)findViewById(R.id.editTextName);
        buttonAdd = (Button)findViewById(R.id.buttonAddArtist);
        spinnerGenres = (Spinner)findViewById(R.id.spinnerGenres);

        buttonAdd.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                addArtist();
            }
        });
    }

    private void addArtist(){
        String name = editTextName.getText().toString().trim();
        String genre = spinnerGenres.getSelectedItem().toString();

        //cek nama tidak boleh kosong
        if(!TextUtils.isEmpty(name)){

            String id = databaseArtists.push().getKey();
            Artist artist = new Artist(id, name, genre);
            databaseArtists.child(id).setValue(artist);

            Toast.makeText(this, "Data success added", Toast.LENGTH_LONG).show();
        }else{
            Toast.makeText(this, "You should enter a name", Toast.LENGTH_LONG).show();
        }
    }
}

0 个答案:

没有答案