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 9201339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:58:58+00:00 2026-06-17T22:58:58+00:00

Here is my Main code.. public class MainActivity extends Activity { private static int

  • 0

Here is my Main code..

public class MainActivity extends Activity {

private static int RESULT_LOAD_IMAGE = 1;
private Spinner spinner1;
Bitmap b;

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

     addListenerOnSpinnerItemSelection();

    Intent i = new Intent(Intent.ACTION_PICK,   android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
            startActivityForResult(i, RESULT_LOAD_IMAGE);


}

/*@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}*/


@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

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

    if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) {
        Uri selectedImage = data.getData();
        String[] filePathColumn = { MediaStore.Images.Media.DATA };

        Cursor cursor = getContentResolver().query(selectedImage,
                filePathColumn, null, null, null);
        cursor.moveToFirst();

        int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
        String picturePath = cursor.getString(columnIndex);
        cursor.close();

        b = BitmapFactory.decodeFile(picturePath);

        imageView.setImageBitmap(b);

    }


}

public void addListenerOnSpinnerItemSelection() {
    ImageView imageView = (ImageView) findViewById(R.id.imgView);
    spinner1 = (Spinner) findViewById(R.id.spinner1);
    spinner1.setOnItemSelectedListener(new CustomOnItemSelected(imageView, this , b));
  }

}

Here is another class..

public class CustomOnItemSelected implements OnItemSelectedListener {

ImageView i;
Context c;
private Bitmap myBitmap;

CustomOnItemSelected(ImageView i,Context c, Bitmap b)
{
    this.i = i;
    this.c = c;
    myBitmap = b;
}

//private static final float ROTATE_FROM = 0.0f;

// private static final float ROTATE_TO = -10.0f * 360.0f;

public void onItemSelected(AdapterView parent, View view, int pos,long id) {
Toast.makeText(parent.getContext(),
“OnItemSelectedListener : ” + parent.getItemAtPosition(pos).toString(),
Toast.LENGTH_SHORT).show();

   if(parent.getItemAtPosition(pos).toString().equals("Rotate"))
  {

       Matrix mat = new Matrix();
        mat.postRotate(90);
        Bitmap bMapRotate = Bitmap.createBitmap(myBitmap, 0, 0, myBitmap.getWidth(), myBitmap.getHeight(), mat, true); //GIVING ERROR ON THIS LINE...
        i.setImageBitmap(bMapRotate);
    }

It’s giving null pointer exception error.. Please help me, what’s going wrong?

  • 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-17T22:58:59+00:00Added an answer on June 17, 2026 at 10:58 pm

    Your CustomOnItemSelected-object is created in addListenerOnSpinnerItemSelection(), which is called from onCreate, before b (your bitmap) is called. Therefore b is null when assigned to myBitmap.

    Move your addListenerOnSpinnerItemSelection()-call to onActivityResult() to make sure your bitmap is created before the CustomOnItemSelected-constructor is called.

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

Sidebar

Related Questions

Here is my code: public class MainActivity extends Activity { private static final int
Here is code of my Android app. MainActivity.java public class MainActivity extends Activity {
Here is my code: public class Test { static { main(null); } public static
Here is my code : public static void main(String[] args) { // System.setProperty( //
I am testing Hibernate here is the situation and code: public static void main(String[]
Here's the code snippet: public static void main (String[]arg) { char ca = 'a'
// Here's my code: Main Class: import java.awt.*; import java.awt.image.BufferedImage; import java.awt.image.DataBufferInt; import java.awt.image.BufferStrategy;
here's the main code at first I thought is was the message box but
So, here's the main code, which checks the URL of the current page for
Here is my main page code: <form><iframe name=iframe_pic src=iframe.html></iframe></form> Here is my iframe.html: <script

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.