• 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

Why i am getting this error?

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

I get this error while compiling my java code

trial1.java:2: package skk doesnot exist
import skk.MyClass;
^
trial1.java:3: cannot find symbol
symbol: class MyClass
class OtherClass extends MyClass{}


i have two seperate files MyClass.java and trial1.java

the code in them are as follows :

MyClass.java
----------------
package skk;
public class MyClass{}

trial1.java
---------------------

package kkk;
import skk.MyClass;
class OtherClass extends MyClass{}



Can anyone please help me out with this !!!



 
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Read this: http://download.oracle.com/javase/tutorial/java/package/index.html
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok few things that might be wrong:

1) trial1.java needs to have T capital (obviously this isn't the cause of your problem but just something to remember)

2) There has to be at least 1 public class in trial1.java. This is because each source file must contain at least 1 public class. Currently, there appears to be no public class present. Also, the public class should be named trial1 in your case (as per the source file name).

3) Another thing which you might want to check is the package structure. Since you have got two packages and both are root then you should have two folders both inside your project workspace. For example, if your project name is "Test" then we should have the following structure for the source files:

Test (folder)
|
|-- kkk (folder)
|--trial.java
|
|-- skk (folder)
|-- MyClass.java

Too bad I don't have access to my pc right now or I would have checked your code manually. Let me know if this doesn't work.
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Anchit Herredia wrote:2) There has to be at least 1 public class in trial1.java. This is because each source file must contain at least 1 public class.



This is wrong. A source file does not need to contain a public class but if it does there can be only one.
 
Anchit Herredia
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Joanne Neal wrote:

Anchit Herredia wrote:2) There has to be at least 1 public class in trial1.java. This is because each source file must contain at least 1 public class.



This is wrong. A source file does not need to contain a public class but if it does there can be only one.



Thanks for correcting me. Yes, there can be no public classes (in which case there will only be "default" classes and they can all have any names irrespective of the filename). The name restriction of class name matching the filename is only applicable to the public class (if present).
 
Ranch Hand
Posts: 115
Firefox Browser Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
is package kkk a sub-package of skk?

if yes then it should be

 
reply
    Bookmark Topic Watch Topic
  • New Topic