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

  • SEARCH
  • Home
  • 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 7957213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:12:55+00:00 2026-06-04T04:12:55+00:00

I have a pop up window which I want to display an image and

  • 0

I have a pop up window which I want to display an image and two buttons. Buttons do appear but ImageView throws nullpointer exception when I try to use it. Below is the code snippet where I display the PopUpWindow:

private void initiatePopupWindow() {
        try {
            //We need to get the instance of the LayoutInflater, use the context of this activity
            LayoutInflater inflater = (LayoutInflater) RestPageActivity.this
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            //Inflate the view from a predefined XML layout
            View layout = inflater.inflate(R.layout.popup_details,
                    (ViewGroup) findViewById(R.id.popup_element));
            // create a 300px width and 470px height PopupWindow
            System.out.println("SELECTED INDEX" + selectedIndex + "***" + IDs.size());


            System.out.println("ITEM ID:" + IDs.get(selectedIndex) + "--------------");
            ImageView iv = (ImageView) findViewById(R.id.ivItem);

            if (StaticParameters.getCompleteData().getMenusHash().containsKey(IDs.get(selectedIndex))) {
                Menu m = StaticParameters.getCompleteData().getMenusHash().get(IDs.get(selectedIndex));
                byte[] imgBytes = FileHandler.readFile2(this, "items", m.getActiveImage());
                System.out.println("///////////////77" + imgBytes.length + "//" + m.getActiveImage());
                if (imgBytes != null && iv != null) {
                    Bitmap b = BitmapFactory.decodeByteArray(imgBytes, 0, imgBytes.length);
                    iv.setImageBitmap(b);

                    Matrix mMatrix = new Matrix();
                    mMatrix.setRectToRect(new RectF(0, 0, iv.getMeasuredWidth(), iv.getMeasuredHeight()), new RectF(0, 0, 100, 100), Matrix.ScaleToFit.CENTER);
                } else
                    System.out.println("else geldi");

            } else if (StaticParameters.getCompleteData().getProductsHash().containsKey(IDs.get(selectedIndex))) {
                Product m = StaticParameters.getCompleteData().getProductsHash().get(IDs.get(selectedIndex));
                byte[] imgBytes = FileHandler.readFile2(this, "items", m.getActiveImage());
                System.out.println("///////////////77" + imgBytes.length + "//" + m.getActiveImage());
                if (imgBytes != null && iv != null) {
                    Bitmap b = BitmapFactory.decodeByteArray(imgBytes, 0, imgBytes.length);
                    iv.setImageBitmap(b);

                    Matrix mMatrix = new Matrix();
                    mMatrix.setRectToRect(new RectF(0, 0, iv.getMeasuredWidth(), iv.getMeasuredHeight()), new RectF(0, 0, 100, 100), Matrix.ScaleToFit.CENTER);
                } else
                    System.out.println("else geldi");
            }

            pw = new PopupWindow(layout, 300, 470, true);
            // display the popup in the center
            pw.showAtLocation(layout, Gravity.CENTER, 0, 0);


            //mResultText = (TextView) layout.findViewById(R.id.server_status_text);
            Button cancelButton = (Button) layout.findViewById(R.id.cancelButton);
            //makeBlack(cancelButton);
            cancelButton.setOnClickListener(cancel_button_click_listener);
            Button approveButton = (Button) layout.findViewById(R.id.completeButton);
            //makeBlack(cancelButton);
            approveButton.setOnClickListener(approve_button_click_listener);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
  • 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-04T04:12:56+00:00Added an answer on June 4, 2026 at 4:12 am

    if in your activity you have declared an attribute

    private ImageView iv;
    

    you have to change:

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

    By

    iv = (ImageView) findViewById(R.id.ivItem);
    you get this nullPointer exception because you are declaring it locally that’s what i thing your problem is

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Window which pop-ups another Window. I want the second Window to
I have a pop up which is timed to appear after 2 minutes on
I have a pop up window which contains a datatable, the data is showing
I am developing a chat application. And i want to have pop up window
I have a pop-up window in jQuery that fades in, and will fade out
I have a pop-up window a user logs into, once they are logged in
Many websites have very good looking pop-up window. For example checkout http://www.myntra.com and when
I have a pop up with plenty of options which can be edited -
I have the below java script function in which I want to redirect the
I want to make sure the user wants to have something pop up by

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.