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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:09:37+00:00 2026-05-15T22:09:37+00:00

Im trying to display this listview, but I keep getting a: 07-17 21:14:22.233: ERROR/AndroidRuntime(349):

  • 0

Im trying to display this listview, but I keep getting a:

07-17 21:14:22.233: ERROR/AndroidRuntime(349): java.lang.NullPointerException

I think I know what the problem is but I dont know how to fix it.

I have a String array which I will be using to be displayed in my list

parser topicparser = new parser();
  final String[] TOPICS = topicparser.topic("http://www.test.com");

Dont worry the parser works great. the only problem I see with it is that the parser doesnt know how many strings the website will have so I am setting the String array in the parser to be very big:

String substr[] = new String[250];

but I know that mostly there are only like 11 to 13 values that I will be storing in that array, the problem I think is when i do this:

setListAdapter(new ArrayAdapter<String>(this, R.layout.topics, TOPICS));

  ListView lv = getListView();

since the String array is set to have up to 250 values in it and I only actually store say 12 then there are a null entries so when I run the code it shows me my list view, but when I get to the bottom of the view it force closes and the log tells me that there was nullpointer. I can tell how many entries I collected while I am parsing, but how do I tell my listview to only show say 12 items in the list so there wont be any null entries. or is there any other solution for my problem.

Thank you,

@Cristian C.

I tried doing what you said, but now I am getting a:

java.lang.ClassCastException: java.util.Arrays$ArrayList

this is what I did:

String[] TOPICS = topicparser.topic("test.com"); 
ArrayList<String> niceArray = (ArrayList<String>) Arrays.asList(TOPICS); // eclipse told me I had to add the cast 
setListAdapter(new ArrayAdapter<String>(this, R.layout.topics, niceArray)); 

any ideas ? Thanks

  • 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-15T22:09:38+00:00Added an answer on May 15, 2026 at 10:09 pm

    instead of returning an array of strings in your topic method, I would return a List

    so instead of

    String substr[] = new String[250]
    

    you could write

    ArrayList<String> substr = new ArrayList<String>();
    

    so now you can just use

    substr.add("whatever string");
    

    the arraylist will only be as big as the items that you add, so you won’t have to worry about nullpointer exceptions

    and since the topic method now returns an ArrayList, the last part can be rewritten as

    niceArray = topicparser.topic("test.com");
    setListAdapter(new ArrayAdapter<String>(this, R.layout.topics, niceArray));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this piece of code I'm trying to get to display but no
I'm trying to display a table full of twitter statuses (yes, this is the
I'm trying to understand this bit of code: in display.php: <html> ... <body> <table>
I've been trying to display text using a Quartz context, but no matter what
When trying to display a byte stream from HLDS (Half-Life Dedicated Server) in a
I'm trying to display a series of titles varying from 60 characters to 160
I am trying to display a list of all files found in the selected
I'm trying to display a loading icon while my iPhone app downloads a network
I'm trying to display an array of files in order of date (last modified).
I'm trying to display a caret ( ^ ) in math mode in LaTeX

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.