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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:00:51+00:00 2026-05-18T04:00:51+00:00

I am currently trying to call a method from a utility class that will

  • 0

I am currently trying to call a method from a utility class that will reference a new cursor created for this utility method. Unfortunately, my new class will not let me create the cursor without context. I have tried numerous ways of passing context from the calling activity, but get null pointer exceptions in most cases.

Here is the portion of my code:

findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                        Tools.pickRandomItem();

                    }
});

and in the Tools Class:

     public static void pickRandomItem() {   

    Cursor cur = getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, null, 
               null, null,MediaColumns.TITLE + " ASC");




}

Using the above code it throws an error on getContentResolver(), and all attempts I’ve made to pass context have failed.

I am fairly new to programming for Android, and don’t fully understand the concept of contexts. Any help you could provide would be greatly appreciated!

  • 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-05-18T04:00:52+00:00Added an answer on May 18, 2026 at 4:00 am

    Create a class that extends Application for your project (you have to declare it in the Manifest too), in the Application make a

    private static MyApplication app
    

    in the onCreate() of it assign it to the field

    app = this;
    

    and make a

    public static MyApplication get()
    

    in it. When you need a Context you can use a

    MyApplication.get()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently trying to write a Dump() method from LinqPad equivalent iin C# for
I am new to Ruby and currently trying a few examples from the Ruby
I currently trying to find a solution, how to ensure that a test fails
I'm currently trying to pass a mono threaded program to multithread. This software do
I'm currently trying to consume a list of strings from some XML using Apache
I am trying to pass current object reference i.e. self to the Timer class
I'm currently trying to get a custom WebView that displays a ContextMenu when it
I currently have a class that sets the current time when an object has
I'm currently developing an EventManager class to ensure that no events are left wired
I'm currently trying to read in an XML file, make some minor changes (alter

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.