我在Android应用程序中获得运行时Null Point异常。
引起:java.lang.NullPointerException:尝试调用虚拟方法&com; go.google.firebase.database.ChildEventListenercom.google.firebase.database.Query.addChildEventListener(com.google.firebase.database.ChildEventListener )'在空对象引用上
以下是我的Firebase连接:
package com.example.nagesh.newapp;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ListView;
import android.widget.TextView;
import com.firebase.ui.database.FirebaseListAdapter;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
public class Last extends AppCompatActivity {
private ListView lst;
private DatabaseReference databaseReference;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_last);
DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReferenceFromUrl("https://newapp-46492.firebaseio.com/Users");
init();
}
private void init() {
lst = (ListView) findViewById(R.id.lstv);
FirebaseListAdapter<String> firebaseListAdapter = new FirebaseListAdapter<String>(this, String.class, android.R.layout.simple_list_item_1, databaseReference) {
@Override
protected void populateView(View v, String model, int position) {
TextView textView = (TextView) v.findViewById(android.R.id.text1);
textView.setText(model);
}
};
lst.setAdapter(firebaseListAdapter);
}
}
我是初学者......帮助我。
答案 0 :(得分:0)
您的参考资料如下。
DatabaseReference databaseReference = FirebaseDatabase.getInstance().child("Users");
它直接提供了"https://newapp-46492.firebaseio.com"