• Post Reply Bookmark Topic Watch Topic
  • New Topic

I'm having pointer and array problems.  RSS feed

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to get started with programming, and pointers are killing me. In C and in java I just can't seem to figure out pointers, and I would like some help. I'm using jsoup to parse a calendar page.

I want to use a switch or if/else statement to filter out the data I don't need for the app. This is by no means anything more than a draft because java is easier to work with than android.


This is the result:
Exception in thread "main" java.lang.NullPointerException
at ccTest.main.main(main.java:51)


here is all my code if it helps.
 
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it's kind of hard to help you out. Your error message says the Null Pointer exception happened on line 51:
at ccTest.main.main(main.java:51)

however, in the code you posted, line 51 is a comment:


so the code you are running is NOT the code you posted.
 
Shane kross
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for taking a look. I don't know why there's extra white space, but here is code I just ran, and copied. It returns the exact same error on line 51.

 
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no black magic here. You will need to break that expression down to one step at a time, and make sure that none of what is returned is null.



You need to check if the "days" array variable is null. You need to check if the iterate reference variable is null. And if those are not, then you need to check if the next() call returns null. etc. etc.

Henry
 
Sheriff
Posts: 4289
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have a basic logic problem here:



What happens if you are at the last iteration and iterate.next().text() != days[counter]?
 
Shane kross
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the advice. Going off what was said I have revamped the code, and no longer have nullPointerExeptions. I want to post the new code for posterity. I hope that it helps someone else at some point. I am not yet out of the woods. The code still doesn't work, but it's closer, and I'll keep going untill it works.

 
Knute Snortum
Sheriff
Posts: 4289
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


The reason you need a finally block is that a try block needs either a catch block or a finally block or both.
 
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
… and welcome to the Ranch
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!