aspose file tools*
The moose likes Beginning Java and the fly likes Problem passing variables Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Problem passing variables" Watch "Problem passing variables" New topic
Author

Problem passing variables

Mike Lipay
Ranch Hand

Joined: Sep 11, 2007
Posts: 171
For the sake of modularization I have two .java files, the main and the sub. I am trying to pass an array between the two, but I keep getting a compile error on the main program:



Here is the main routine snippet (AutoHistory):


Here is the sub code (VehicleFile):



VehicleFile.java compiles cleanly, but AutoHistory.java tosses the above error. Any help would be greatly appreciated.

Jhakda Velu
Ranch Hand

Joined: Feb 26, 2008
Posts: 166
What are the import statements for AutoHistory.java

Jhakda


If I become filthy rich, I'll sponsor research for painless dental treatment at Harvard Medical School. Thats why,I'm learning Java.I have 32 teeth, 22 are man made.
Mike Lipay
Ranch Hand

Joined: Sep 11, 2007
Posts: 171
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19790
    
  20

Mike Lipay wrote:utine snippet (AutoHistory):

You can't put statements directly in a class; statements only go in methods, static blocks and initializer blocks.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19073
    
  40



I know that this is a snippet, so this may be off-base... However, if this is not a snippet, then the error makes sense. Java code can't be anywhere -- they have to be in methods, constructors, or initializers, which the call to the count() method isn't.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Mike Lipay
Ranch Hand

Joined: Sep 11, 2007
Posts: 171
OK, maybe I snipped too much, let's try the entire code:

AutoHistory.java




VehicleFile.java
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
Have you got the VehicleFile.class file in the same directory as the AutoHistory.java file? Have you got any package declarations you haven't told us about?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19790
    
  20

Both Henry and I have already given the answer.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19073
    
  40

OK, maybe I snipped too much, let's try the entire code:


Nope, you didn't snip too much -- My statement (and Rob's) still stands. Java statements (that are not declarations) needs to be in a method, constructor, or initializer.

This statement...


Where it is located... is not legal.


[Rob keeps beating me to the answer... ]

Henry
Mike Lipay
Ranch Hand

Joined: Sep 11, 2007
Posts: 171
Thanks, I think I understand what you mean now.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
Rob Prime wrote:Both Henry and I have already given the answer.
Yes, you're right.
Jhakda Velu
Ranch Hand

Joined: Feb 26, 2008
Posts: 166
I think i got Campbell to think in the wrong way by asking this
What are the import statements for AutoHistory.java


Totally missed on this one. Thanks Henry and Rob for pointing in the right direction.

Jhakda
 
 
subject: Problem passing variables