[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Problem with a java error (cannot be applied to (java.io.PrintWriter))

Posted on 2009-12-28
6
Medium Priority
?
370 Views
Last Modified: 2013-12-14
Can anybody help me with this Java problem I'm having.

I have a java file with the following commands.

slip  = new PaySlip(emp,sum);
slipWrite = new PrintWriter(new FileWriter(args[2]));
slip.printPay(slipWrite);

In the PaySlip.java file I have this for the printPay method

      public void printPay()
      {
            double netpay;            
            emp.calcPay(this);
            netpay = gross - tax;
            
            System.out.println(emp.getYtdGross());
            System.out.println(emp.getFirst());
            System.out.println(emp.getLast());
            System.out.println(emp.getSalary());
            System.out.println(emp.getDeptCode());
     }

When I go to compile the main app I get

mainapp.java:80: printPay() in PaySlip cannot be applied to (java.io.PrintWriter)

           slip.printPay(slipWrite);  // call printPay to calculate and print payslip
                ^

Would you know what this means and how to fix it?

0
Comment
Question by:enigma1234567890
6 Comments
 
LVL 40

Expert Comment

by:Gurvinder Pal Singh
ID: 26131601
where are you accepting the Print Writer arguments
slip.printPay(slipWrite); \\ is passing argument slipWrite

printPay() \\ no argument
0
 
LVL 40

Accepted Solution

by:
Gurvinder Pal Singh earned 2000 total points
ID: 26131621
replace
public void printPay()
with
public void printPay(PrintWriter slipWrite )
0
 
LVL 20

Expert Comment

by:Sathish David Kumar N
ID: 26131886
can u post the error stack!!
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Expert Comment

by:karthikdhamodharan
ID: 26132429
The method signature of the printPay method is wrong. It should be actually defined as follows

  public void printPay(PrintWriter pw)

and you can invoke this method as you have used it,

 slip.printPay(slipWrite);
0
 

Expert Comment

by:priety
ID: 26139928
Your method signature is as follows:

public void printPay();

This method is not taking any arguments.

For your code to compile.
Your method printPay needs to be as follows:
public void printPay(.PrintWriter pr);

0
 

Author Closing Comment

by:enigma1234567890
ID: 31670408
thanks
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
In this post we will learn different types of Android Layout and some basics of an Android App.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This video teaches viewers about errors in exception handling.
Suggested Courses
Course of the Month19 days, 20 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question