2013-04-17 2 views
0

동일한 폴더의 다른 클래스에서 "송장"방법을 호출하는 프로그램을 작성하고 있습니다.자바 - 오류 : 기호를 찾을 수 없습니다

strInvoice= invoice(); 
JOptionPane.showInputDialog(null, strInvoice, "*Name*'s Party Store", -1); 

이는 방법은에있는 클래스 파일의 모습입니다 : 내 프로그램의 방법에 따라 호출 오전 방법

다음
error: cannot find symbol 

strInvoice = invoice(); 
      ^
symbol: method invoice() 

이 : 나는 다음과 같은 오류가 계속 같은 폴더 :

public String invoice() 
{ 
    String strInfo=""; //string returned containing all the information 
    double dBalloonNoDiscount; //balloon total without discount 
    double dCandleNoDiscount; //candle total without discount 
    double dBannerNoDiscount; //banner total without discount 
    double dSubtotal;  //subtotal 
    double dTax;   //tax 
    double dShippingCost;  //shipping cost 
    double dTotal;   //total 
    String strShippingType;  //shipping type 

    dBalloonNoDiscount = balloons * 2.50; 
    dCandleNoDiscount = candles * 6.00; 
    dBannerNoDiscount = banners * 2.00; 

    dSubtotal = subtotal(); 
    dTax = tax(); 
    dShippingCost = shippingCost(); 
    strShippingType = shippingType(); 
    dTotal = orderTotal(); 

    strInfo += "\nQuantity" 
     + "\n\nBalloons: " + balloons + " @ $2.50 = " 
      + df.format(dBalloonNoDiscount) + "* Discount Rate: " 
      + df.format(discount('B')) + " = " 
      + df.format(subtotal('B')) 
     + "\n\nCandles: " + candles + " @ 6.00 = " 
      + df.format(dCandleNoDiscount) + "* Discount Rate: " 
      + df.format(discount('C')) + " = " 
      + df.format(subtotal('C')) 
     + "\n\nBanners: " + banners + " @ $2.50 = " 
      + df.format(dBannerNoDiscount) + "* Discount Rate: " 
      + df.format(discount('N')) + " = " 
      + df.format(subtotal('N')) 
     + "\nSubtotal: " + df.format(dSubtotal) 
     + "\n Tax: " + df.format(dTax) 
     + "\nShipping: " + df.format(dShippingCost) + " - " 
      + strShippingType 
     + "\n Total: " + dTotal; 

    return strInfo; 
} 

충분한 정보가 있기를 바랍니다. 나는 그 문제를 찾을 수없는 것 같습니다.

+0

OO 및 Java의 몇 가지 기본 사항을 살펴보고 몇 가지 간단한 예제를 시도해보고 사용해보십시오. 그것은 장기적으로 도움이 될 것입니다. – Krishna

답변

0

다른 클래스의 메서드를 호출 할 수있게하려면 해당 메서드를 정적으로 만들거나 정의 된 클래스의 인스턴스를 가져와야합니다. 귀하의 경우에는

당신은 아마 인스턴스를 필요가 무엇인가 : 다음 나중에

YourClass instance = new YourClass(); 

과 : 당신이 그것을 호출하고 다음

strInvoice = instance.invoice(); 
2
I am writing a program that calls upon the "invoice" method from a different 
class in the same folder. 

좋아 :

strInvoice= invoice(); 

전화가 필요하므로 작동하지 않습니다. 방법은 다음과 같습니다 :

strInvoice = obj.invoice(); 

여기서 obj는 다른 클래스의 인스턴스입니다. invoice() 방법은 public static 경우

또는 당신은 또한처럼 호출 할 수 있습니다 : 당신이 그것을 호출되는 클래스 외부에 메서드를 호출하는 경우

strInvoice = SomeClass.invoice(); 
+0

도와 주셔서 대단히 감사합니다! – Logan94

1

, 당신은을 호출하기 전에 참조가 필요 방법.

invoice() 메소드는 다른 클래스에서 사용할 수 있으며 다른 클래스에서는이 메소드를 호출하므로 invoice() 메소드를 사용할 수있는 클래스 (객체) 참조가 필요합니다. 예 :

ClassA object = new ClassA(); 
    object.invoice(); // assume invoice method is available in ClassA. 
+0

도움 주셔서 감사합니다! – Logan94

관련 문제