Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

compiling package

 
Pradyut Bhattacharya
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have created a package with the file name lmn.java as : -



it compiles without any errors

but on calling it from this file




and on compiling in command prompt as

javac -classpath D:\java\p9\ xyz.java

it gives the error message

bad class file: D:\java\p9\lmn.class
class file contains wrong class: p9.lmn
Please remove or make sure it appears in the correct subdirectory of the classpa
th.
lmn obj = new lmn();
^

pls help

thanks
Pradyut
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Both lmn and xyz are in the same package so you don't need to use an import statement. Besides, the import statement imports a class lmn from package nine but the class you showed is in package p9. If you simply remove the "import nine.lmn" statement, it will fix this particular error.

As a side note, it would be helpful if you start class names with uppercase and use CamelCase if the name contains more than one word. Also, variable names should use camelCase but start with a lowercase letter instead. Finally, package names are typically all lowercase.

If you follow these conventions, it will be much easier for us to read your code when you ask for help here. You may also find it helps YOU read your own code more easily.

Keep Coding! (TM)

Layne
 
cocoloco cocotero
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try this

1) create xyz.java file
2) create a folder called p9 that supend from directory where xyz is included
2) create file Lmn.java in this folder (the package name refer to directory p9) and compile
3) compile now xyz.java file
4) execute xyz.

this should work.

Regards.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic