• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

File Scanner with java.lang.nullpointer error?  RSS feed

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys. I am a complete beginner so i will try my best to explain the problem.

I am getting the error: java.lang.NullPointerException Didn't create a FileScanner to count the Tags"

I get this error when i try to run option 3 in my menu.

Enter 1 to Load SEO Tag Definitions
Enter 2 to Display the SEO Tags Definitions
Enter 3 to Load and Analyse an HTML file
Enter 4 to Exit."
I have 2 text files, one called seotags.txt that displays as follows:

This is the seotags.txt file


This is the ranges.html file





This is the error that i am getting.


I have spent hours trying to work it out but with no success. Any help would be much appreciated! Thank you!
 
author & internet detective
Posts: 39076
714
Eclipse IDE Java VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michael,
Welcome to CodeRanch!

Can you add ex.printStackTrace() to the program before
System.out.println("Didn't create a FileScanner to count the Tags");

This will tell you which line number the NullPointer is on. Then post which line that is (and what code is on that line so we can recognize it.)
 
Michael Connolly
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Jeanne Boyarsky wrote:Michael,
Welcome to CodeRanch!

Can you add ex.printStackTrace() to the program before
System.out.println("Didn't create a FileScanner to count the Tags");

This will tell you which line number the NullPointer is on. Then post which line that is (and what code is on that line so we can recognize it.)



Line 176.
"
at java.lang.String.contains(String.java:2133)
at vowelscounter.VowelsCounter.main(VowelsCounter.java:176)"

Any ideas?

Thank you
 
Rancher
Posts: 3353
33
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please copy and post the full text of the error message, not just a few lines.
 
Michael Connolly
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Norm Radder wrote:Please copy and post the full text of the error message, not just a few lines.



ERROR: java.lang.NullPointerException
Didn't create a FileScanner to count the Tags
Welcome to BMC SEO Tag Analyser

1. Enter 1 to Load SEO Tag Definitions
2. Enter 2 to Display the SEO Tags Definitions
3. Enter 3 to Load and Analyse an HTML file
4. Enter 4 to Exit.

at java.lang.String.contains(String.java:2133)
at vowelscounter.VowelsCounter.main(VowelsCounter.java:176)
Option:
 
Norm Radder
Rancher
Posts: 3353
33
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is that the exact output?  The message I get for a NPE looks like this:


Exception in thread "main" java.lang.NullPointerException
at TestCode25.main(TestCode25.java:339)


Notice the first line.
 
Michael Connolly
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Norm Radder wrote:Is that the exact output?  The message I get for a NPE looks like this:


Exception in thread "main" java.lang.NullPointerException
at TestCode25.main(TestCode25.java:339)


Notice the first line.



Yea the output i provided is the exact output.
 
Norm Radder
Rancher
Posts: 3353
33
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

 the output i provided is the exact output.


What java program are you using?  My java program does not have the same text as yours for a NPE.

Look at the variables on line 176 and find the one with the null value.  Then backtrack in the code to find out why that variable did not have a valid value.
 
Michael Connolly
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Norm Radder wrote:

 the output i provided is the exact output.


What java program are you using?  My java program does not have the same text as yours for a NPE.

Look at the variables on line 176 and find the one with the null value.  Then backtrack in the code to find out why that variable did not have a valid value.



I done that. tagCountWord is set to not = null. tagsList is = null when i change it, it causes errors.

I am probably doing something really stupid but not sure what.
 
Michael Connolly
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
NetBeans
 
Norm Radder
Rancher
Posts: 3353
33
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Print out the contents of the tagsList array to be sure it does not contain any null values.  Use the Arrays class's toString method:
 
Michael Connolly
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Norm Radder wrote:Print out the contents of the tagsList array to be sure it does not contain any null values.  Use the Arrays class's toString method:



Prints out an ID null
 
Norm Radder
Rancher
Posts: 3353
33
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the array variable is null, then check that the code that gives it a value is executed.
 
Michael Connolly
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Norm Radder wrote:If the array variable is null, then check that the code that gives it a value is executed.



Sorry, i am not that advanced. I would try to do what you asked if i knew what to do, maybe if you said it in a way that i could understand.

Thanks a lot.
 
Norm Radder
Rancher
Posts: 3353
33
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Make sure the assignment statement that gives a value to the array is executed.
 theArray = new DataType[size]

Make sure the statements that assign values to the slots in the array are executed.
theArray[index] = aValue



Where did you put the statement that prints the contents of the array?  It should be immediately before the statement (line 176) where the NPE happens
 
Michael Connolly
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[quote=Norm Radder
Where did you put the statement that prints the contents of the array?  It should be immediately before the statement (line 176) where the NPE happens

Oh, i put it in the wrong place. After putting it where you told me to i get the following output below if that helps.

an ID [6, <h1, ><h2, ><h3, ><h4, ><h5, ><h6, 5, ><img, ><video, ><audio, ><object, ><iframe, 4, ><a, ><title, ><meta, ><link, 4, ><!DOCTYPE , ><html , ><head , ><body, null] >
an ID [6, <h1, ><h2, ><h3, ><h4, ><h5, ><h6, 5, ><img, ><video, ><audio, ><object, ><iframe, 4, ><a, ><title, ><meta, ><link, 4, ><!DOCTYPE , ><html , ><head , ><body, null] >
an ID [6, <h1, ><h2, ><h3, ><h4, ><h5, ><h6, 5, ><img, ><video, ><audio, ><object, ><iframe, 4, ><a, ><title, ><meta, ><link, 4, ><!DOCTYPE , ><html , ><head , ><body, null] >
java.lang.NullPointerException
an ID [6, <h1, ><h2, ><h3, ><h4, ><h5, ><h6, 5, ><img, ><video, ><audio, ><object, ><iframe, 4, ><a, ><title, ><meta, ><link, 4, ><!DOCTYPE , ><html , ><head , ><body, null] >
an ID [6, <h1, ><h2, ><h3, ><h4, ><h5, ><h6, 5, ><img, ><video, ><audio, ><object, ><iframe, 4, ><a, ><title, ><meta, ><link, 4, ><!DOCTYPE , ><html , ><head , ><body, null] >
an ID [6, <h1, ><h2, ><h3, ><h4, ><h5, ><h6, 5, ><img, ><video, ><audio, ><object, ><iframe, 4, ><a, ><title, ><meta, ><link, 4, ><!DOCTYPE , ><html , ><head , ><body, null] >
an ID [6, <h1, ><h2, ><h3, ><h4, ><h5, ><h6, 5, ><img, ><video, ><audio, ><object, ><iframe, 4, ><a, ><title, ><meta, ><link, 4, ><!DOCTYPE , ><html , ><head , ><body, null] >
an ID [6, <h1, ><h2, ><h3, ><h4, ><h5, ><h6, 5, ><img, ><video, ><audio, ><object, ><iframe, 4, ><a, ><title, ><meta, ><link, 4, ><!DOCTYPE , ><html , ><head , ><body, null] >
an ID [6, <h1, ><h2, ><h3, ><h4, ><h5, ><h6, 5, ><img, ><video, ><audio, ><object, ><iframe, 4, ><a, ><title, ><meta, ><link, 4, ><!DOCTYPE , ><html , ><head , ><body, null] >
an ID [6, <h1, ><h2, ><h3, ><h4, ><h5, ><h6, 5, ><img, ><video, ><audio, ><object, ><iframe, 4, ><a, ><title, ><meta, ><link, 4, ><!DOCTYPE , ><html , ><head , ><body, null] >
an ID [6, <h1, ><h2, ><h3, ><h4, ><h5, ><h6, 5, ><img, ><video, ><audio, ><object, ><iframe, 4, ><a, ><title, ><meta, ><link, 4, ><!DOCTYPE , ><html , ><head , ><body, null] >
an ID [6, <h1, ><h2, ><h3, ><h4, ><h5, ><h6, 5, ><img, ><video, ><audio, ><object, ><iframe, 4, ><a, ><title, ><meta, ><link, 4, ><!DOCTYPE , ><html , ><head , ><body, null] >
an ID [6, <h1, ><h2, ><h3, ><h4, ><h5, ><h6, 5, ><img, ><video, ><audio, ><object, ><iframe, 4, ><a, ><title, ><meta, ><link, 4, ><!DOCTYPE , ><html , ><head , ><body, null] >
an ID [6, <h1, ><h2, ><h3, ><h4, ><h5, ><h6, 5, ><img, ><video, ><audio, ><object, ><iframe, 4, ><a, ><title, ><meta, ><link, 4, ><!DOCTYPE , ><html , ><head , ><body, null] >
at java.lang.String.contains(String.java:2133)
an ID [6, <h1, ><h2, ><h3, ><h4, ><h5, ><h6, 5, ><img, ><video, ><audio, ><object, ><iframe, 4, ><a, ><title, ><meta, ><link, 4, ><!DOCTYPE , ><html , ><head , ><body, null] >
at vowelscounter.VowelsCounter.main(VowelsCounter.java:179)
an ID [6, <h1, ><h2, ><h3, ><h4, ><h5, ><h6, 5, ><img, ><video, ><audio, ><object, ><iframe, 4, ><a, ><title, ><meta, ><link, 4, ><!DOCTYPE , ><html , ><head , ><body, null] >
an ID [6, <h1, ><h2, ><h3, ><h4, ><h5, ><h6, 5, ><img, ><video, ><audio, ><object, ><iframe, 4, ><a, ><title, ><meta, ><link, 4, ><!DOCTYPE , ><html , ><head , ><body, null] >
an ID [6, <h1, ><h2, ><h3, ><h4, ><h5, ><h6, 5, ><img, ><video, ><audio, ><object, ><iframe, 4, ><a, ><title, ><meta, ><link, 4, ><!DOCTYPE , ><html , ><head , ><body, null] >
an ID [6, <h1, ><h2, ><h3, ><h4, ><h5, ><h6, 5, ><img, ><video, ><audio, ><object, ><iframe, 4, ><a, ><title, ><meta, ><link, 4, ><!DOCTYPE , ><html , ><head , ><body, null] >
an ID [6, <h1, ><h2, ><h3, ><h4, ><h5, ><h6, 5, ><img, ><video, ><audio, ><object, ><iframe, 4, ><a, ><title, ><meta, ><link, 4, ><!DOCTYPE , ><html , ><head , ><body, null] >
an ID [6, <h1, ><h2, ><h3, ><h4, ><h5, ><h6, 5, ><img, ><video, ><audio, ><object, ><iframe, 4, ><a, ><title, ><meta, ><link, 4, ><!DOCTYPE , ><html , ><head , ><body, null] >
an ID [6, <h1, ><h2, ><h3, ><h4, ><h5, ><h6, 5, ><img, ><video, ><audio, ><object, ><iframe, 4, ><a, ><title, ><meta, ><link, 4, ><!DOCTYPE , ><html , ><head , ><body, null] >
an ID [6, <h1, ><h2, ><h3, ><h4, ><h5, ><h6, 5, ><img, ><video, ><audio, ><object, ><iframe, 4, ><a, ><title, ><meta, ><link, 4, ><!DOCTYPE , ><html , ><head , ><body, null] >
an ID [6, <h1, ><h2, ><h3, ><h4, ><h5, ><h6, 5, ><img, ><video, ><audio, ><object, ><iframe, 4, ><a, ><title, ><meta, ><link, 4, ><!DOCTYPE , ><html , ><head , ><body, null] >
ERROR: java.lang.NullPointerException
Didn't create a FileScanner to count the Tags
Welcome to BMC SEO Tag Analyser

1. Enter 1 to Load SEO Tag Definitions
2. Enter 2 to Display the SEO Tags Definitions
3. Enter 3 to Load and Analyse an HTML file
4. Enter 4 to Exit.

Option:
 
Michael Connolly
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Michael Connolly wrote:

Norm Radder wrote:Print out the contents of the tagsList array to be sure it does not contain any null values.  Use the Arrays class's toString method:



Prints out an ID null



Oh, so i worked it out, i had a null value at the end, i had it as size 24 so i changed it to size 23 and it's fixed the problem.


Man thank you sooooo much for your help and patience. Highly appreciated!
 
Norm Radder
Rancher
Posts: 3353
33
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at the contents of the array that was printed,  The last entry was null which means it was not assigned a value.  Look at the logic and see why there is an empty slot at the end of the array.
When the code loads the array, it needs to get one more value for the end of the array or the size of the array must be one less.
 
Michael Connolly
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Norm Radder wrote:Look at the contents of the array that was printed,  The last entry was null which means it was not assigned a value.  Look at the logic and see why there is an empty slot at the end of the array.
When the code loads the array, it needs to get one more value for the end of the array or the size of the array must be one less.



Yea i had it set to size 24 rather than size 23. Again, thanks so much for having the patience.
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hello

import p1utils.FileScanner;

the module is unknown to me. Where can I find this?

thanks for answer
 
Manuel Prochnow
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Knute Snortum wrote:Manuel Prochnow,
Your post was moved to a new topic.
(This informational message will self destruct in two days)



I am new here. why my post was moved?
 
Marshal
Posts: 62231
193
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Manuel Prochnow wrote:. . . I am new here. why my post was moved?

Because it was a question different from the original subject of this thread.
 
"I know this defies the law of gravity... but I never studied law." -B. Bunny Defiant tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!