• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Package Problem

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I have this problem with packages. In the below written code, when I run it without declaring package statement(the very first line in my both .java files), It compiles and executes fine. but when I declare them in the package, it gives me problem in "MyClass.java".. compilation error.. says that
"cannot find symbol" on the line
"MyClass2 sp = new MyClass2()"

Code is :


Can anyone explain why it is so??

Thanks
Manu.
 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

To understand the package, read this url

http://www.jarticles.com/package/package_eng.html

thanks
 
author and cow tipper
Posts: 5009
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you use pacakges, you are esseintally telling the complier that you are going to be placing and organizeing your code into sub-directories. A package is really nothing more than a directory on the filesystem. However, since Java is cross platform, you can't really use a normal directory notation, as Linux slashes are different from PC DOS slashes. So, Java uses a dot notation, and coins the cute little term 'package'

Getting packaged code to compile can definitely be annoyting. I put together a short multimedia tutorial that shows you exactly where a java source file should go when you want to package compile it, and how to run the source code generated by the compilation:

JDK Tutorials for Compiling Packaged Code - Even Some Classpath Switches in there Too!!!


Working with the SDK is important, but eventually, you'll want to move to an IDE like Eclipse or use NetBeans or something.

Cheers!

-Cameron McKenzie
 
Manu Dhanda
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, I think you din't get my problem exactly.

Even if I use the package mypack in the above written code, it 'll compile. But for that I have to remove 4 lines of code from the main() method as written below.
Now, the below written code is working fine.

So, the problem creating line is
MyClass2 sp= new MyClass2();

Exactly am making a mistake while am creating the object of MyClass2.
and the error is also at this same line.

So, I should say I understand how to compile 'n run the code with packages, but there is something am missing while am creating this object of MyClass2.

Thanks
Manu.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic