Android Firebase,显示在警报对话框中从firebase检索到的图像

时间:2017-11-24 23:32:52

标签: java android firebase

我一直在尝试显示在警告对话框中从firebase检索到的图像。我已经为警报对话框创建了自定义布局。但是,我计算在其中显示图像。使用Glide检索任何图像。任何反馈将非常感谢!你可以查看我的代码;

/AndroidRuntime: FATAL EXCEPTION: main
              Process: com.example.aliihsangokalp.casepool, PID: 15517
              java.lang.NullPointerException: Argument must not be null
                  at com.bumptech.glide.util.Preconditions.checkNotNull(Preconditions.java:27)
                  at com.bumptech.glide.util.Preconditions.checkNotNull(Preconditions.java:22)
                  at com.bumptech.glide.RequestBuilder.into(RequestBuilder.java:595)
                  at com.example.aliihsangokalp.casepool.CaseSingleActivity$2.onDataChange(CaseSingleActivity.java:112)
                  at com.google.android.gms.internal.zzeex.zza(Unknown Source)
                  at com.google.android.gms.internal.zzegs.zzbwg(Unknown Source)
                  at com.google.android.gms.internal.zzegy.run(Unknown Source)
                  at android.os.Handler.handleCallback(Handler.java:751)
                  at android.os.Handler.dispatchMessage(Handler.java:95)
                  at android.os.Looper.loop(Looper.java:154)
                  at android.app.ActivityThread.main(ActivityThread.java:6682)
                  at java.lang.reflect.Method.invoke(Native Method)
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)

and also you can check the errors I get

private String mPost_key = null;

private DatabaseReference mDatabase;

private TextView mCaseSingleTitle;
private TextView mCaseSingleDesc;
private Button bttn;
private ImageView ımageView;

private ProgressDialog mProgress;

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



    mDatabase = FirebaseDatabase.getInstance().getReference().child("Cases");

    mPost_key = getIntent().getExtras().getString("case_id");

    mCaseSingleDesc = (TextView) findViewById(R.id.singleCaseDesc);

    mCaseSingleTitle = (TextView) findViewById(R.id.singleCaseTitle);
    bttn = (Button) findViewById(R.id.seeImage);



    final LayoutInflater inf = this.getLayoutInflater();
    mProgress = new ProgressDialog(this);



    bttn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            final View aaa = inf.inflate(R.layout.photo,null);
             ımageView = aaa.findViewById(R.id.singleCaseImage);

            final AlertDialog.Builder ImageDialog = new AlertDialog.Builder(CaseSingleActivity.this);


            ImageDialog.setTitle("Here is the photo : ");
            ImageDialog.setView(aaa);



            ImageDialog.setNegativeButton("ok", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {



                }
            });
            ImageDialog.show();


           }});

        mDatabase.child(mPost_key).addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {


            if(dataSnapshot.exists()) {

                String post_title = (String) dataSnapshot.child("title").getValue();
                String post_desc = (String) dataSnapshot.child("desc").getValue();
                String post_image = (String) dataSnapshot.child("image").getValue();
                String post_uid = (String) dataSnapshot.child("uid").getValue();

                mCaseSingleTitle.setText(post_title);
                mCaseSingleDesc.setText(post_desc);

                Glide.with(CaseSingleActivity.this).load(post_image).apply(new RequestOptions().fitCenter().override(1000,1000).dontAnimate().dontTransform()).into(ımageView) ;

                mProgress.dismiss();

            }
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        mProgress.dismiss();
        }
          });
          }
         }

1 个答案:

答案 0 :(得分:0)

看起来数据库的路径为空,请将Intent的{​​{1}}键存储在常量putExtra()变量中,以便在检索时不会错误地键入新密钥它

  

检查public static final额外

Intent