Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem passing variables

 
Mike Lipay
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What are the import statements for AutoHistory.java

Jhakda
 
Mike Lipay
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Rob Spoor
Sheriff
Pie
Posts: 20531
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Henry Wong
author
Marshal
Pie
Posts: 21123
78
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
 
Mike Lipay
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, maybe I snipped too much, let's try the entire code:

AutoHistory.java




VehicleFile.java
 
Campbell Ritchie
Sheriff
Pie
Posts: 48968
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20531
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Both Henry and I have already given the answer.
 
Henry Wong
author
Marshal
Pie
Posts: 21123
78
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, I think I understand what you mean now.
 
Campbell Ritchie
Sheriff
Pie
Posts: 48968
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Prime wrote:Both Henry and I have already given the answer.
Yes, you're right.
 
Jhakda Velu
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic