java - OPeration failed
<p>i have the code below, but when i run it i get a message box appear saying OPeration failed, why is this doing it and what solution is aviable for it to run, the code should simply allow a user to print from a txt file </p>

<p>code :</p>

<pre><code>import java.io.*;
import javax.swing.JOptionPane;
import javax.print.*;
import javax.print.attribute.DocAttributeSet;
import javax.print.attribute.HashDocAttributeSet;
import javax.print.attribute.HashPrintRequestAttributeSet;
import javax.print.attribute.PrintRequestAttributeSet;

public class printimg
{
    public void printimg() throws FileNotFoundException, PrintException, InterruptedException {
    String filename = ("item.text"); // THIS IS THE TEXT FILE TO PRINT
    try{
    PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
    DocFlavor flavor = DocFlavor.INPUT_STREAM.TEXT_PLAIN_UTF_8; //  FILE IS .txt TYPE
    PrintService printService[] =
            PrintServiceLookup.lookupPrintServices(flavor, pras);
    PrintService defaultService =
            PrintServiceLookup.lookupDefaultPrintService();
    PrintService service = ServiceUI.printDialog(null, 200, 200,
            printService, defaultService, flavor, pras);
    if (service != null) {
        DocPrintJob job = service.createPrintJob();
        FileInputStream fis = new FileInputStream(filename);
        DocAttributeSet das = new HashDocAttributeSet();
        Doc doc = new SimpleDoc(fis, flavor, das);
        job.print(doc, pras);

    }
    }
    catch(Exception a){
        JOptionPane.showMessageDialog(null, "OPeration Failed");
    }
}
}
</code></pre>

<p>am getting this error now :</p>

<pre><code>java.lang.IllegalArgumentException: services must be non-null and non-empty
    at javax.print.ServiceUI.printDialog(ServiceUI.java:167)
    at printimg.printimg(printimg.java:20)
    at __SHELL8.run(__SHELL8.java:8)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at bluej.runtime.ExecServer$3.run(ExecServer.java:725)
</code></pre>
