Quantcast
Channel: Active questions tagged crash - Stack Overflow
Viewing all articles
Browse latest Browse all 7199

My App Crash after open one scheen with ListView

$
0
0

my app crash after open one activity with ListView.My intention is show the names of the Firebase Real time Data Basebut with this error this is impossible

Code XML :

<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:layout_gravity="center"    android:orientation="vertical" ><ListView        android:id="@+id/ListView1"        android:layout_width="match_parent"        android:layout_height="match_parent"/></RelativeLayout>

Code.java :

import android.os.Bundle;import android.widget.ArrayAdapter;import android.widget.ListView;import androidx.annotation.NonNull;import androidx.annotation.Nullable;import androidx.appcompat.app.AppCompatActivity;import com.google.firebase.database.ChildEventListener;import com.google.firebase.database.DataSnapshot;import com.google.firebase.database.DatabaseError;import com.google.firebase.database.DatabaseReference;import com.google.firebase.database.FirebaseDatabase;import java.util.ArrayList;public class Drinks extends AppCompatActivity {ListView ListView1;ArrayList<String> MyArrayList = new ArrayList<>();DatabaseReference mRef;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_drinks);        final ArrayAdapter<String> MyArrayAdapter = new ArrayAdapter<String>(Drinks.this,android.R.layout.simple_list_item_1,MyArrayList);        ListView1 = (ListView) findViewById(R.id.ListView1);        ListView1.setAdapter(MyArrayAdapter);        mRef = FirebaseDatabase.getInstance().getReference().child("Main");        mRef.addChildEventListener(new ChildEventListener() {            @Override            public void onChildAdded(@NonNull DataSnapshot snapshot, @Nullable String previousChildName) {                String value = snapshot.getValue(String.class);                MyArrayList.add(value);                MyArrayAdapter.notifyDataSetChanged();            }            @Override            public void onChildChanged(@NonNull DataSnapshot snapshot, @Nullable String previousChildName) {                MyArrayAdapter.notifyDataSetChanged();            }            @Override            public void onChildRemoved(@NonNull DataSnapshot snapshot) {            }            @Override            public void onChildMoved(@NonNull DataSnapshot snapshot, @Nullable String previousChildName) {            }            @Override            public void onCancelled(@NonNull DatabaseError error) {            }        });    }}

Viewing all articles
Browse latest Browse all 7199

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>