• 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

Help with Java compilation error

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what i did is i wrote first 2 progs with out main method it will compile ...so these 2 programs can be used my other classes..
so i wrote one more prog as PremierSearch... to call these 2 methods..
the first 2 progs it compiled ...
so my prob is for the 3rd prog i am getting 2 errors.. so how to overcome these errors...

public class InternetSearchEngine {
static void search() {
System.out.println("Found 20 results on Web");
}
}
...........
public class DirectorySearchEngine {
static void search() {
System.out.println("Found 10 results on Novel Directory");
}
}

...............

public class PremierSearch {
public static void main(String args[]) {
search();
InternetSearchEngine.search();
DirectorySearchEngine.search();
System.out.println(" Search Completed ");
}
static void search() {
System.out.println("Found 5 results in Local");
}
}

PremierSearch.java:6: error: cannot find symbol
InternetSearchEngine.search();

symbol: variable DirectorySearchEngine
location: class PremierSearch
2 errors
 
Ranch Hand
Posts: 1164
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please use code tags and properly indented code like I mentioned in a reply to your previous post. Can't understand why you should be getting these errors. Nothing looks odd to me. When are you getting these errors? When trying to compile the 3rd source file is it? In what order are you compiling?
 
sailaja cherukuri
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i am writing the code in notepad ........... i am not using eclipss etc.... i am sryy frm the next prgm i will use eclipss ... thankuuu
 
Mansukhdeep Thind
Ranch Hand
Posts: 1164
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I never told you that you should use eclipse. If you are a beginner, please use notepad++ or some other text editor but not an IDE. Why are you saying sorry? What I was asking you to do is simply to paste code in tags as follows:



Now please explain when are you getting the above errors.
 
Ranch Hand
Posts: 384
Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi sailaja,

Are all three classes you mentioned in the same package ???

 
sailaja cherukuri
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
package example;

class calculator
{
public static void main(String args[])
{
System.out.println("this is a package example");
}
}
 
sailaja cherukuri
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the above prob i need to compile as javac example\calculator.java

i am trying to compile a class that uses package........ but i am getting an error

file not found: example\calculator.java.......

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

sailaja cherukuri wrote:the above prob i need to compile as javac example\calculator.java

i am trying to compile a class that uses package........ but i am getting an error

file not found: example\calculator.java.......


Does the directory you are running javac from contain a directory called example and does that directory contain a file called calculator.java ?
 
sailaja cherukuri
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes .... the directory is example... in that directory calculator.java is a filee........ i have to execute class in that directoryy...
 
Mansukhdeep Thind
Ranch Hand
Posts: 1164
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But from where / which directory are you executing this command?
 
Ranch Hand
Posts: 228
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

sailaja cherukuri wrote:the above prob i need to compile as javac example\calculator.java

i am trying to compile a class that uses package........ but i am getting an error

file not found: example\calculator.java.......



Compiling the java code from this command requires you get into the directory which is just above the example.

And can you show the directory structure of the 3 classes that you wrote above?
As i see all the three classes should be in same package as the modifiers of the methods you are using in the PremierSearch are package private.
 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please avoid misspelt words; people who did not grow up speaking English will find prob directoryy sryy etc very difficult to understand.
 
Never trust an airline that limits their passengers to one carry on iguana. Put this tiny ad in your shoe:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic