• 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
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Inputting data from a csv file to create a data array

 
Ranch Hand
Posts: 99
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all:

As of right now I am working on a program that will input values from a csv and store it in a two-dimensional array and be used to calculate differen things and make certain decisions. I know there's probably a lot of forums already out there that answer this question but so far none have helped. So I decided to ask the question myself, see if it gets better results. So far here is my code:



Does anyone know what needs to be adjusted? The compiler keeps mentioning about an error or something in line 12.

Thanks in advance for your help everyone!

PS: I also want to put this code into a method so all I have to do is call it up and the program does it automatically. I don't know if that can be done or not. Again, any help would be GREATLY appreciated.

Thanks again everyone!

 
Sheriff
Posts: 22815
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That code compiles just fine here. Can you tell us what the compiler error you're getting is?
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sam Thompson wrote:The compiler keeps mentioning about an error or something in line 12.


Tell The Details
 
Sam Thompson
Ranch Hand
Posts: 99
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks again...

I guess I didn't read the whole thing NetBeans gave me lol. Sorry about that...

Here is the error message Netbeans gave me...

Exception in thread "main" java.io.FileNotFoundException: C:\Users\sdl36\Dropbox\Projects_and_Curiosities\T2R.csv (The system cannot find the path specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:106)
at java.io.FileInputStream.<init>(FileInputStream.java:66)
at java.io.FileReader.<init>(FileReader.java:41)
at T2R.main(T2R.java:12)

Thank you
 
Joanne Neal
Rancher
Posts: 3742
16
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's a runtime exception, not a compiler error.
It's saying that the file you are trying to open doesn't exist. The // in your file name on line 12 looks a little suspect. Try getting rid of one of them.
 
Sam Thompson
Ranch Hand
Posts: 99
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I deleted the two slashes and I got the same exact error more-or-less.

The T2R CSV file does actually exist. Should there be a different pathname sequence instead of the one already there? The CSV file is in my Dropbox.
Should it be placed somewhere else.

Thanks again.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Joanne Neal wrote:Try getting rid of one of them.

 
Sam Thompson
Ranch Hand
Posts: 99
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok. I put one back in.

But it still has a problem with it for some reason. Still giving me the same error message.
 
Saloon Keeper
Posts: 7645
178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A FileNotFoundException would also be thrown if the file is inaccessible due to lack of pemissions, either on the file itself or one of its parent directories.
 
Sam Thompson
Ranch Hand
Posts: 99
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is throwing that kind of exception...

Could the DropBox file be inaccessible? How do you make it accessible?

Or it would be better if i put the CSV elsewhere in the computer?

Thanks again.
 
Ranch Hand
Posts: 378
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
have you tried replacing the / with \ and doing a directory listing with dir from a command line? This should help you to eliminate any errors in the path like missing letters etc.

Also put the file in another drive and see if it works. If it does then it could be a permission or security problem I guess..
 
Sam Thompson
Ranch Hand
Posts: 99
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How would you use dir in a command line to access the file? I'll try the other suggestions while I wait to hear from you folks.

Thanks again

S.T.
 
Gamini Sirisena
Ranch Hand
Posts: 378
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not exactly to access it but to see if there is something wrong with the path

so dir c:\blah\blah\blash.csv should list the file with some details of it. Then you would know that the path is correct and the file does exist at the path used in the java program and the problem is elsewhere.
 
Sam Thompson
Ranch Hand
Posts: 99
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It works now.

However, I am having another problem, though... here is the next error message that has come up. And I notice Netbeans has it underlined in red too, this line.

Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - no suitable constructor found for StringTokenizer(java.io.BufferedReader)
constructor java.util.StringTokenizer.StringTokenizer(java.lang.String) is not applicable
(actual argument java.io.BufferedReader cannot be converted to java.lang.String by method invocation conversion)
constructor java.util.StringTokenizer.StringTokenizer(java.lang.String,java.lang.String) is not applicable
(actual and formal argument lists differ in length)
constructor java.util.StringTokenizer.StringTokenizer(java.lang.String,java.lang.String,boolean) is not applicable
(actual and formal argument lists differ in length)
at t2r.tester_class.main(tester_class.java:15)
Java Result: 1
BUILD SUCCESSFUL (total time: 1 second)


Any help would be greatly appreciated. Thanks!
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sam Thompson wrote:It works now.


What was the problem ? It might help other people if you explain how you fixed it.


Sam Thompson wrote:However, I am having another problem, though... here is the next error message that has come up.


That seems fairly self explanatory. somewhere in your code (probably on line 15 of tester_class.java) , you are trying to create a StringTokenizer and you are passing a reference to a BufferedReader object to the constructor. StringTokenizer doesn't have a constructor that accepts a BufferredReader argument.
 
Sam Thompson
Ranch Hand
Posts: 99
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh lol. Sorry about that.

The solution I found was that I forgot to type in the rest of the file name, it was T2R_weights and not just T2R. All it was a simple pathname error. Be careful with that.

Hmmmm...

If that is the case concerning the constructor, what should the code really say? I am still learning how to do input and output coding.
Thanks
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sam Thompson wrote:If that is the case concerning the constructor, what should the code really say? I am still learning how to do input and output coding.


Difficult to say without seeing the relevant code.
 
Sam Thompson
Ranch Hand
Posts: 99
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is my code that I have so far...



Thanks again.

S.T.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That code is not producing the error you got. That code is in T2R.java, but it's a file called tester_class.java that's being compiled when you get the error.
 
Sam Thompson
Ranch Hand
Posts: 99
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ohhhhhh.... I see what you are saying now.

You are right.

Thank you so much for your help.

So all I would have to do is rewrite the class name or rewrite the file name so they either match with tester_class or T2R class.

Again, thank you so much! You were a great help!

And thank you to the others who also contributed to my endeavor!

S.T.
 
What's that smell? I think this tiny ad may have stepped in something.
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic