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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:34:52+00:00 2026-06-04T05:34:52+00:00

Im getting a null pointer exception when I attempt to get an array of

  • 0

Im getting a null pointer exception when I attempt to get an array of image urls using jsoup, really not sure what Im doing wrong here as I appears that Im following the example layed out in the javadoc, any help would go a long way thanks.

public class ImagetestActivity extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);

    String url = "http://www.goal.com/en/news/1717/editorial/2012/05/20/3116140/in-pictures-chelsea-celebrate-champions-league-success#";
    Document doc = null;
    List<Element> media = new ArrayList<Element>();
    try {
        doc = Jsoup.connect(url).get();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    media = doc.select("[src]");

    for (Element src : media) {
        if (src.tagName().equals("img")) {
            Toast.makeText(ImagetestActivity.this, src.text(),
                    Toast.LENGTH_LONG).show();
        }
    }
}

}

  • 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-04T05:34:53+00:00Added an answer on June 4, 2026 at 5:34 am

    Try this:

    media = doc.select("img[src]");
    
    for (Element src : media) {
       Toast.makeText(ImagetestActivity.this, src.attr("src"),
                    Toast.LENGTH_LONG).show();
    }
    

    I.e. select images (no need to check the tag name). And probably you need src attribute value, not inner text (which is always empty)

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

Sidebar

Related Questions

Hi i am reading inbox using service but i m getting null pointer exception
I am getting null pointer exception when I am trying to get lat/long from
I am getting Null Pointer Exception for ImageView imag = (ImageView) findViewById(R.id.image). I have
im getting sometimes null pointer exception while accessing handler created in thread. I`m using
I am getting a null pointer exception report in the android developer console. I
I am getting null pointer exception while trying to add anything in my solrQueue.
Hoping you guys can figure out why im getting a null pointer exception with
Im getting null pointer exception in unbindDrawables where im Removing callbacks on all the
Iam getting a null pointer exception while sending some string text as an sms
I am getting same null pointer exception while running integration test in eclipse .while

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.