如何解决“尝试在空对象引用上调用虚拟方法'java.lang.String java.lang.Object.toString()'”?

时间:2019-02-05 11:15:50

标签: java android firebase-realtime-database

我是android新手。并且我已将数据保存到Firebase实时数据库中。现在,我想检索该数据,但这样做时我的应用程序崩溃,标题出现错误。我的代码在下面。

FiscalCodeIsCorrect

我的LogCat错误在下面。

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.google.android.gms.tasks.OnSuccessListener;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
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 com.google.firebase.database.ValueEventListener;
import com.google.firebase.storage.FirebaseStorage;
import com.google.firebase.storage.StorageReference;
import com.sa90.materialarcmenu.ArcMenu;
import com.sa90.materialarcmenu.StateChangeListener;
import com.squareup.picasso.Picasso;

public class ClickPostActivity extends AppCompatActivity {

private TextView TIME, DISC, SENDER;
private ImageView post;



private String KEY;

private DatabaseReference  clickPostRef ;

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

    TIME = findViewById(R.id.daytime);
    DISC = findViewById(R.id.post_saying);
    SENDER = findViewById(R.id.click_post_name);
    post = findViewById(R.id.post_image_clicked);

    Bundle b = getIntent().getExtras();


    KEY = b.getString("KEY");

    clickPostRef = FirebaseDatabase.getInstance().getReference().child("All User Uploads").child(KEY);
    clickPostRef.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(@NonNull DataSnapshot dataSnapshot) {

            String name = dataSnapshot.child("name").getValue().toString();
            String discription = dataSnapshot.child("disc").getValue().toString();
            String postImage = dataSnapshot.child("mImageUrl").getValue().toString();
            String time = dataSnapshot.child("time").getValue().toString();

            SENDER.setText(name);
            DISC.setText(discription);
            TIME.setText(time);

            Picasso.get().load(postImage).into(post);


        }

        @Override
        public void onCancelled(@NonNull DatabaseError databaseError) {

        }
    });

请让我知道是否有人回答。它将被申请。预先感谢

0 个答案:

没有答案