Dave Lilley

Greenhorn
+ Follow
since Apr 10, 2007
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Dave Lilley

Most of what you've said i agree with and i should have perhaps explained somethings.

As stated in my first post, I am taking a simple task of having a console program start with a parameter OR not.

versions...

1. run program and display text (if arguments where given) to the screen and exit. done and moved on

2. add a test to check for argument and if nothing display suitable message, then exit. Or display the argument that was given to the screen.
Done and moved on

3. use a method to do the above (namely a method to display to the screen).
Done and moved on

4. introduce file handling, test for the filename is present, if it is delete it, then create it again inserting the argument passed (write the argument to a file in a known location and filename), then read from that file the data inside to the screen, then exit.
hit a snag with i/o operation (see erros at end of post)

5. look at refining the program more (ie introduction of constructors etc).
to be done

all of this was so i could take baby steps to understanding how things glue together.

I have a book here by Ivor Hilton on Beginning Java 2. Which has helped me in some understanding (and lost me on others - ps got up to end of chapter 5 defining classes then i start going glassy eyed so to speak )

Found a tutorial that gave me this idea of this program as i kept giving up because i couldn't really relate what i was reading etc to something pratical.

So here is the Original program i had along with the errors i got notice they all refer to the fact that te datastream "variables" for reading and writing are te issue.



Errors i got generated when i compile (currently under linux but also under Windows too

dave@localhost:~$ /home/dave/jdk1.6.0/bin/javac /dos/my_project/crm/mysimpleio.java
/dos/my_project/crm/mysimpleio.java:41: non-static method ToFile(java.lang.String) cannot be referenced from a static context
ToFile(text);
^
/dos/my_project/crm/mysimpleio.java:56: non-static method FromFile(java.lang.String) cannot be referenced from a static context
FromFile(text);
^
/dos/my_project/crm/mysimpleio.java:64: cannot find symbol
symbol : variable thefileOut
location: class mysimpleio
thefileOut.write(thefilename);
^
/dos/my_project/crm/mysimpleio.java:67: cannot find symbol
symbol : variable thefileOut
location: class mysimpleio
thefileOut.close();
^
/dos/my_project/crm/mysimpleio.java:73: cannot find symbol
symbol : variable thefileIn
location: class mysimpleio
thefileIn.read(thefilename);
^
/dos/my_project/crm/mysimpleio.java:75: cannot find symbol
symbol : variable thefileIn
location: class mysimpleio
thefileIn.close();
^
6 errors
dave@localhost:~$


under linux i'm using Java 1.6.0 and windows it's 1.5



please if you can assist me with the I/O issue i think i can get the constructor bit okay (well i did so when working from the book and erros i got were mostly typo's or of that ilk.

Should i move the datastream bits down into the methods and not in the main as they are currently??

dave.

ps appreachiate the hints about moving code out to make it cleaner.
17 years ago
Hi ho there one and all!

My program started off taking a parameter from the cmd line and displaying it back to the screen.

I altered this to test if a parameter was entered and if nothing was then to display a suitable message.

I then moved to two methods to display suitable messages.

Now i want to be able to write to a file the parameter passed and then to read this back and display it to the screen.

(Note each time this is run the text file is deleted and recreated!).

Now i've been told you cannot mix static methods with dynamic variables and that's fine but i don't understand !!!

I have a good understanding of OOP but when it comes to the actual doing Well then it becomes a head ache.

googled for a sample tutorial on this type of issue to no avail everything seems to brush over this (else i'm missing something VERY basic!).

program as it stands now is below.



then i get the errors below

E:\my_project\crm>javac mysimpleio.java
mysimpleio.java:75: cannot resolve symbol
symbol : method readUTF (java.lang.String)
location: class java.io.DataInputStream
thefileIn.readUTF(thefilename);
^
1 error

E:\my_project\crm>javac mysimpleio.java


Problem.... If i move the datastream decarations into main then other errors popup. see snippet below (everything else below is the same as code above.



errors

E:\my_project\crm>javac mysimpleio.java
mysimpleio.java:10: illegal start of expression
static DataOutputStream thefileOut;
^
mysimpleio.java:11: illegal start of expression
static DataInputStream thefileIn;
^
2 errors

E:\my_project\crm>

HELP
17 years ago