• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

declaring variables

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i need help plsss

i have ths code



and for some reason im getting an error stating

class ClassTwo is coderanch, should be declare in the file name classTwo.java

any ideas.??? did i already declare it right?
 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well you already have one class taht is public make the ClassTwo package.
But i should suggest that you put the class ClassTwo in a new file makees it more clear. .

regards Rille
[ December 03, 2005: Message edited by: Rikard Qvarforth ]
 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are only allowed to have one public class in a source file, and the name of the source file must match the public class name.
 
jessie mccarty
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I made the source file the same, but im still getting the same error =(
 
lowercase baba
Posts: 13091
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
just to be clear...

you have TWO separate files, one named "sample.java". this file should only have the code for the sample class.

you have a second file, named "ClassTwo.java" (and yes, the case DOES matter for both these filenames).

is this correct?
 
jessie mccarty
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
so do i need to take it out..actually what im trying to get form this is the result.. this is an exercise that i need to modify to get thr right result.. so what should i do?

thanks much
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by jessie mccarty:
so do i need to take it out...


Yes, if both class definitions are coderanch, then they each need to be in their own separate file, just as fred described above.
 
jessie mccarty
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


so the code will be then like this?
still getting an error " class or interface expected"
 
marc weber
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by jessie mccarty:
...so the code will be then like this? ...


Not quite. That looks like the class definition for "sample" with its name changed to TestTwo. Basically, you just need to separate what you had in your original post...

Note: By convention, class names are capitalized -- e.g., Sample.
 
jessie mccarty
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i separate them but still error " class or interface expected"
 
marc weber
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by jessie mccarty:
i separate them but still error " class or interface expected"


Can you post your current code? The code in my examples compile and run fine.
 
fred rosenberger
lowercase baba
Posts: 13091
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
also, post the exact error message. it should refer to the line where the error occurs.
 
jessie mccarty
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
soory for the late respond...actually the codes are compiling, when i tried to execute it, it gives me "Exception in main "thred" java.lang.NoSuchMethodError": main"
what does it mean?
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It means you don't have your classpath setup correctly.
Try running your program with:

java -cp . TestTwo

See the following tutorial for a step by step explanation: First Steps for Microsoft Windows
 
reply
    Bookmark Topic Watch Topic
  • New Topic