• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Two scanner FileReader

 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am able to compile my code but for some reason when I try to run my program nothing happens and I narrowed it down to the second scanner filereader that i need to read in data from a second file and create a customerList. I made it exactly the same as the first one so I don't know what i'm doing wrong. The only part that needs to be looked at is the first 30 lines but just in case I thought i'd send the rest.
 
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you getting any exceptions? You can use a debugger to step through and see why this is happening.
 
Ranch Hand
Posts: 85
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
put debugging point and run code and find out where that your program giving exception.
 
Dustin Schreader
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I guess I don't understand how to put debugging point, is there a way I can see an example?
 
Mohamed Sanaulla
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can use an IDE for that- You can download Netbeans and search for debugging using Netbeans.
 
Dustin Schreader
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I figured out how to use netbeans and the debugger and this is what i get

Have no file for /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/jsfd.jar
Have no file for /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/laf.jar
Have no file for /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/sunrsasign.jar
java.io.FileNotFoundException: customerDat.txt (No such file or directory)

I have the file in the same folder and project why does it say there is no such file or directory, the spelling is correct too, I checked it 3 times to be sure?
 
Mohamed Sanaulla
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just see if your code is using any packages and see where the file is located relative to the location of class from where you are using it.
 
Ranch Hand
Posts: 72
IntelliJ IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Looking at your code I don't see any classes VideoList, CustomerList with default access. Where are those located? If they are in different packages they you should explicitly import them.
 
Dustin Schreader
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am not familiar with these items having default access, I could very well have not added that at all. Is there a certain bit of code I should have added to make them default access?
 
Mohamed Sanaulla
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Anton Shaykin wrote:Looking at your code I don't see any classes VideoList, CustomerList with default access. Where are those located? If they are in different packages they you should explicitly import them.



He has problem accessing an external file and not the Java class. Looking at the Exception- its FileNotFoundException.
 
Mohamed Sanaulla
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dustin Schreader wrote:I am not familiar with these items having default access, I could very well have not added that at all. Is there a certain bit of code I should have added to make them default access?



Where have you stored you other file? If there's is no FileNotFoundException for the other file, then you can place your customerDat.txt in the same location.
 
Dustin Schreader
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok I started out making this on jpadpro and all the files, even the .txt files were in the same folder. I then started using netbeans and i'm sure that I selected the folder all the files were in. The weird part is just by changing some of the code around I can get the debugger to say that the other videoDat.txt file can't be found either. All the files are in the same folder so that should make them local or viewable i guess right?
 
Dustin Schreader
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there something wrong with the way I'm doing the Scanner and readfile, making it not able to see that I have data files? Or maybe some other flaw in the code or one of my other classes?
 
Marshal
Posts: 80234
424
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You don't usually need to pass a FileReader to the Scanner constructor. You can if you want to because it implements the Readable interface, but you can usually pass a File object. But (as people have already told you) a FileNotFoundException can be caused by the file not being in the location you specified. It can also be caused because the file is read-only or write-only, or it is already in use by another application.

It is also worthwhile double-checking the exact spelling of the file names. If your file is actually called CustomerDat.txt, you will be unable to find it. If you really can't find the files, find out about JFileChooser to seek files.

To give a member of a class (or a class) default (or package-private) access, simply miss out the access modifier; don't call it public or private or protected.

As for other flaws, it worries me to see a main method 132 lines long. It also worries me to see all members of a class marked static, unless you are creating a "utility class", which I don't think you are.
 
Dustin Schreader
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you, I will try and go through my code to see what I can change and check the read write only. BTW it worries me too that the main method is that long and static but according to the assignment I have to use the authors code which Isn't the best to begin with and we have to modify it.
 
Campbell Ritchie
Marshal
Posts: 80234
424
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are given particular instructions for your assignment, you will have to go along with them. It may be worth telling your teacher that people have misgivings about that bit of design; he might use something different next year.
 
Getting married means "We're in love, so let's tell the police!" - and invite this tiny ad to the wedding:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic