my dog learned polymorphism*
The moose likes Beginning Java and the fly likes compiling package program error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "compiling package program error" Watch "compiling package program error" New topic
Author

compiling package program error

saravanan rajendran
Ranch Hand

Joined: Jun 13, 2008
Posts: 75
hi,
I have problem when compiling package program please help me
my two program path is: /usr/local/apache-tomcat-5.5.26/webapps/Asianet/WEB-INF/classes/com/example/servlets/
first program:

package com.example.servlets;
public class balance
{
public void show()
{
System.out.println("welcome");
}
}
when i compile balance program its compiled
second program:

import com.example.servlets.*;
public class auto
{
public static void main(String args[])
{

balance.show();
}
}
when i compile balance program its showing below error:

auto.java:7: cannot find symbol
symbol : class balance
location: class com.example.servlets.auto
balance obj=new balance();
^
auto.java:7: cannot find symbol
symbol : class balance
location: class com.example.servlets.auto
balance obj=new balance();
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39826
    
  28
Apart from trying to invoke an instance method as if it were static, don't know.
saravanan rajendran
Ranch Hand

Joined: Jun 13, 2008
Posts: 75
hi,
thanks for yr reply i not that much good in java please help me. In main method i removed static but same error coming.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39826
    
  28
Very peculiar error, which I think is caused by your biting off more than you can chew.

Start with applications which don't require such complicated imports.
The main method has to be static.
How are you calling "balance.show()" in the main() method; this looks like a static call; have you go some code which creates an object called balance?
Is this the actual code you are using? Read this FAQ. I suspect it is a classpath problem, but it is incomprehensible without knowing what you are actually trying to compile.
Soni Agrawal
Greenhorn

Joined: May 26, 2008
Posts: 6
first of all, You can't call any non-static metnod in the static function..
second you have to call function on the object not on the class name..that should be obj.show(); in place of balance.show();
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39826
    
  28
Agree, but there's more wrong with this app, something we don't know about yet. Maybe spelling balance/Balance.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: compiling package program error