Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9300631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T22:49:31+00:00 2026-06-18T22:49:31+00:00

I am trying to display an image in a pop-up using the code below.

  • 0

I am trying to display an image in a pop-up using the code below. Basically there is a list of audio files, and when I click on it, a pop-up appears, showing its album art (this is what I expect it to do). But, the app crashes. LogCat gives a NullPointerException — which I am sure it is because of the ImageView only. Here is my code:

public class MainActivity extends SherlockListActivity {
    Uri sourceUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
    @SuppressWarnings("deprecation")
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);        
        @SuppressWarnings("unused")
        ActionBar ab = getSupportActionBar();
        String[] from = {MediaStore.MediaColumns.TITLE,MediaStore.MediaColumns.DATA};
        int[] to = {android.R.id.text1};

        CursorLoader cursorLoader = new CursorLoader(this,sourceUri,null,null,null,MediaStore.Audio.Media.TITLE);
        Cursor cursor = cursorLoader.loadInBackground();
        startManagingCursor(cursor);
        ListAdapter adapter = new SimpleCursorAdapter(this,android.R.layout.simple_list_item_1,cursor,from,to,CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
        setListAdapter(adapter);

    }
    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
        Cursor cl = ((SimpleCursorAdapter)l.getAdapter()).getCursor();
        cl.moveToPosition(position);
        String loc = cl.getString(cl.getColumnIndex(MediaStore.MediaColumns.DATA));
        File f = new File(loc);
        MusicMetadataSet mmds;
        try {
            mmds = new MyID3().read(f);
            if(mmds!=null){
            MusicMetadata mmd =  (MusicMetadata)mmds.getSimplified();
            String s = mmd.getArtist() +"-"+mmd.getSongTitle();
            Toast.makeText(this,s,Toast.LENGTH_SHORT).show();
            @SuppressWarnings("unchecked")
            Vector<ImageData> img = mmd.getPictureList();
                if(!img.isEmpty()){
                    byte[] imgData = img.get(0).imageData;
                    Bitmap bmp = BitmapFactory.decodeByteArray(imgData, 0, imgData.length);
                    LayoutInflater layoutInflater=(LayoutInflater)getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);  
                    View popupView = layoutInflater.inflate(R.layout.popup, null);
                    final PopupWindow popupWindow = new PopupWindow(popupView,100,100);

                                /**** PROBLEM BECAUSE OF THIS ************/
                    ImageView iv = (ImageView)findViewById(R.id.imageView);
                    iv.setImageBitmap(bmp);



                    popupWindow.showAtLocation(popupView, Gravity.CENTER, 0, 0);
                    Button btnOk = (Button)popupView.findViewById(R.id.btnOk);
                    btnOk.setOnClickListener(new OnClickListener() 
                    {                    
                        @Override
                        public void onClick(View v) 
                        {
                            popupWindow.dismiss();  //dismissing the popup
                        }
                    });


                }
            }
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    } 

How can I resolve it? Here is my popup.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:orientation="vertical"
  android:background="#90FFFFFF"
  android:layout_height="wrap_content">

  <TextView
      android:layout_width="fill_parent"
      android:text="@string/art"
      android:textColor="#000000"
      android:gravity="center"
      android:textStyle="bold"
      android:layout_height="wrap_content">
  </TextView>
  <ImageView
      android:layout_width="fill_parent"
      android:id="@+id/imageView"
      android:contentDescription="@string/art"
      android:layout_height="wrap_content"
      />
  <Button
      android:layout_width="fill_parent"
      android:id="@+id/btnOk"
      android:text="@string/ok"
      android:layout_height="wrap_content">
  </Button>
</LinearLayout>

The thing is, the TextView and the Button appear just fine. The problem strangely occurs with ImageView only! Please help, this is driving me insane.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T22:49:32+00:00Added an answer on June 18, 2026 at 10:49 pm

    Change your code

     ImageView iv = (ImageView)findViewById(R.id.imageView);
    

    to

     ImageView iv = (ImageView)popupView.findViewById(R.id.imageView);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to display an image using a PHP script. Basically so the php
I am trying to display the image on JSP page using Following code <%
i am trying to display an image by using the < img > tag
I'm trying to display an image before the list in a listactivity. If I
hi i am trying to display image obtained from url (using jsoup) in a
I am trying to display an image using ImageView in Android. The image data
I am trying to display an image from C:\temp. Here's the code: string root
I am trying to display an image from the /webroot/img/ folder using the following
I'm trying to display an image file from a directory using a PHP echo
i am trying to display image using GridView. This is the first time i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.