aspose file tools*
The moose likes Beginning Java and the fly likes static method to call from other package Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "static method to call from other package" Watch "static method to call from other package" New topic
Author

static method to call from other package

Eung maeng
Ranch Hand

Joined: Feb 10, 2002
Posts: 68
Hi,
would you be able to show me how static method call non-static method in same class?

I tried to put a simple of my two program below.

please show me how to fix this problem.

Regards,

e.g

package pgm;
import pgm.*;

class A;

public static Map getValues(String ISBN_digit) {
Hashtable ht = new Hashtable();
String message = "from CCHKDigit() ";
Boolean IN60 = new Boolean(true);

CHKISBN(String ISBN_digit) // my problem is in this method???

ht.put("msg", message);
ht.put("error", IN60);

return ht;
}

public char CHKISBN(String isbn10) {

PXERCD = '0';
isbn10 = isbn10.toUpperCase().trim();
char[] theChars = isbn10.toCharArray();

//int val=0;
StringBuffer sb = new StringBuffer();

// 2. validation of input ISBN code's chacters
F = 10;
RUNTOT=0;
for (int X = 0; X<=9; X++) {

if (X < 9) {
RUNTOT += F * Character.getNumericValue(theChars[X]);
F--;
}
//System.out.println("theChars[X]"+theChars[X]);
int val =NUMVALUES.indexOf(theChars[X]);
//System.out.println("INDEXOF-VAL:"+ val);
if(val == -1) {
PXERCD = '2';
System.out.println("pxercd"+PXERCD);
return PXERCD;
}//end of if
}//end of for


XCHECK = Character.getNumericValue(theChars[isbn10.length() - 1]);
XXREST = (int)((long)(RUNTOT)%(long)(11));

if (XXREST == 0) {
XXCHKD = 0;
}else if(XXREST == 1) {
XCCHKD = 'X';
XXCHKD = 1;
}else{
XXCHKD = (11 - XXREST);
}
// Check if error
if (Character.getNumericValue(isbn10.charAt(9)) != XXCHKD && XXREST !=1) {
PXERCD = '1';
}else if(isbn10.charAt(9) != XCCHKD && XXREST ==1) {
PXERCD = '1';
}else {
PXERCD = '0';
} //´┐Żend if-else

return PXERCD;

}//end of method of CHKISDN


package pgm;
class b{
public void checkDigits(String ITNO) {

ItemNo = ITNO;
Hashtable rValues = (Hashtable) CCHKDigit.getValues(ITNO);
String msg = (String) rValues.get("msg");
boolean error = ((Boolean)(rValues.get("error")) ).booleanValue();

System.out.println("Error" + error);
System.out.println("Message" + msg);
}
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
A static method in a class definition cannot directly access the instance methods. The instance methods only have meaning when you create an instance of the class.
Eung maeng
Ranch Hand

Joined: Feb 10, 2002
Posts: 68
thank, Keith,
Do you have any example source to get multiple return values from other class with instance method in instance of the class?

thanks,
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
I'm sorry, but I don't understand your question.

I don't see where you're trying to call an instance method in another class.

A method can't have multiple return types.

However, if you want to return multiple values, you can encapsulate them into an object.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: static method to call from other package
 
Similar Threads
Buffered Readers and hashtables.
Exception -- java.lang.StackOverflowError
Problem with Session Beans
please help meeeee
ejb3 application client can't find session bean. Error: Exception in thread "main" java.lang.Asserti