Question

What I'm trying to do is when an Imageview item being preesed, then a Dialog will open up and show the inage in a large scale.

Now first of all this is the XML layout of the dialog -

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/imageView_large_pic"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/bkgnd_pressed" />

</LinearLayout>

Now the code to the Dialog is as follows -

Dialog settingsDialog = new Dialog(MainChat.this);

settingsDialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);

 settingsDialog.setContentView(getLayoutInflater().inflate(R.layout.image_large
          , null));

ImageView ivLarge = (ImageView) findViewById(R.id.imageView_large_pic);

String pathpic = v.getTag().toString();

ivLarge.setImageURI(Uri.parse(pathpic));

settingsDialog.show();

Now I tried to dubuging this code, and it get stuck at this line - ivLarge.setImageURI(Uri.parse(pathpic));

The logcat gives me that this is java.lang.NullPointerException error.

Thanks for any kind of help

Was it helpful?

Solution

You are looking in the wrong place for the ImageView

ImageView ivLarge = (ImageView) findViewById(R.id.imageView_large_pic);

is looking in the layout you inflate in setContentView(). Instead, you need to look in the Dialog's layout. Try instead

ImageView ivLarge = (ImageView) settingsDialog .findViewById(R.id.imageView_large_pic);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top