Bonjour,

Qu'est ce qui ne va pas dans ce code ?

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
  //  try {
 
                FileInputStream psStream = null;
 
                try { psStream = new FileInputStream("conditionnelle.JPEG"); }
                catch (FileNotFoundException ffne) {
                System.out.println("The file is not found : "+ffne);}
                if (psStream == null) { return; }
                DocFlavor psInFormat = DocFlavor.INPUT_STREAM.JPEG; //.INPUT_STREAM.POSTSCRIPT;
                Doc myDoc = new SimpleDoc(psStream, psInFormat, null);
                PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
                aset.add(new Copies(3));
                aset.add(MediaSize.ISO.A4) ;
                aset.add(Sides.TUMBLE); //DUPLEX
                //  aset.add(MediaSize.NA.NA_5X7); //LEGAL
                // aset.add(Sides.ONE_SIDED); //DUPLEX
                PrintService[] services = PrintServiceLookup.lookupPrintServices(psInFormat, aset);
                if (services.length > 0) {
                    DocPrintJob job = services[0].createPrintJob();
                try {
                    job.print(myDoc, aset);
                }
                catch (PrintException pe) {
 
                System.out.println("Error PrintException "+pe+ "!");
                }
                }
    }        
  /*      }
  catch (Exception ex) { System.out.println("Global Error "+ex+ "!"); }
  
  //end print
    }
*/
avec l'exception j'ai :

java.lang.ClassCastException
Sans exception j'obtiens ;
run:
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException
at javax.print.attribute.AttributeSetUtilities.verifyAttributeValue(AttributeSetUtilities.java:552)
at javax.print.attribute.HashAttributeSet.add(HashAttributeSet.java:301)
at javaappli2.JFramePrint.jButton1ActionPerformed(JFramePrint.java:92)
at javaappli2.JFramePrint.access$000(JFramePrint.java:20)
at javaappli2.JFramePrint$1.actionPerformed(JFramePrint.java:45)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2015)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2338)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6434)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6199)
at java.awt.Container.processEvent(Container.java:2203)
at java.awt.Component.dispatchEventImpl(Component.java:4790)
at java.awt.Container.dispatchEventImpl(Container.java:2261)
at java.awt.Component.dispatchEvent(Component.java:4616)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4803)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4463)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4393)
at java.awt.Container.dispatchEventImpl(Container.java:2247)
at java.awt.Window.dispatchEventImpl(Window.java:2674)
at java.awt.Component.dispatchEvent(Component.java:4616)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:662)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:211)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
BUILD SUCCESSFUL (total time: 7 seconds)