While populating ListView app crashes.
Error: null point Exception
public class Recycler extends AppCompatActivity
{
private ListView mListView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_recycler);
mListView = (ListView) findViewById(android.R.id.list);
DatabaseReference ref = FirebaseDatabase.getInstance().getReferenceFromUrl("https://afirebaseproject-eab4d.firebaseio.com/data/a");
FirebaseListAdapter<String> adapter = new FirebaseListAdapter<String>(
this,
String.class,
android.R.layout.simple_list_item_1,
ref
)
{
@Override
protected void populateView(View v, String model, int position) {
TextView text = (TextView) findViewById(android.R.id.list);
text.setText(model);
}
};
mListView.setAdapter(adapter);
}
}
XML ListView id- list
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
....
tools:context="shah.parth.temp2.Recycler">
<ListView
android:id="@+id/list"
style="@android:style/Widget.ListView" />
</android.support.constraint.ConstraintLayout>
This is the error which I am getting
FATAL EXCEPTION: main
Process: shah.parth.temp2, PID: 2845
java.lang.RuntimeException: Unable to start activity ComponentInfo{shah.parth.temp2/shah.parth.temp2.Recycler}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ListView.setAdapter(android.widget.ListAdapter)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2423)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2483)
at android.app.ActivityThread.access$900(ActivityThread.java:153)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1349)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5441)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:738)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:628)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ListView.setAdapter(android.widget.ListAdapter)' on a null object reference
at shah.parth.temp2.Recycler.onCreate(Recycler.java:41)
at android.app.Activity.performCreate(Activity.java:6303)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2376)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2483)
at android.app.ActivityThread.access$900(ActivityThread.java:153)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1349)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5441)
at java.lang.reflect.Method.invoke(Native Method)