Java - Tengo un problema al compilar mi programa,necesito ayuda

 
Vista:

Tengo un problema al compilar mi programa,necesito ayuda

Publicado por MatRt (1 intervención) el 27/09/2021 02:31:29
Estoy haciendo un reproductor de musica en java netbeans utilizando jlayer,tengo un problema al compilar espero que me puedan dar una solucion a este dilema.

El problema:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at javax.swing.ImageIcon.<init>(ImageIcon.java:217)
    at MainPackage.Windows.initComponents(Windows.java:275)
    at MainPackage.Windows.<init>(Windows.java:27)
    at MainPackage.Windows$14.run(Windows.java:505)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
    at java.awt.EventQueue.access$500(EventQueue.java:97)
    at java.awt.EventQueue$3.run(EventQueue.java:709)
    at java.awt.EventQueue$3.run(EventQueue.java:703)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

Windows.java :
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
package MainPackage;
 
import java.io.*;
import javax.swing.DefaultListModel;
import java.util.ArrayList;
import javax.swing.JFrame;
import javax.swing.UIManager;
 
public class Windows extends javax.swing.JFrame {
 
    ReproduceAudio pl=new ReproduceAudio();
 
    ArrayList updateList= new ArrayList();
 
    javazoom.jl.player.Player player;
    File simpan;
 
 
    /**
     * Creates new form PlayerMemo
     */
    public Windows() {
        initComponents();
        this.setLocationRelativeTo(null);
    }
 
 
    void updateList(){
 
        updateList=pl.getListSong();
        DefaultListModel model=new DefaultListModel();
 
        for(int i=0;i<updateList.size();i++)
            {
                int j=1+1;
                model.add(i,j + " | " + ((File) updateList.get(i)).getName());
 
 
            }
        jList1.setModel(model);
 
    }
 
    // panel de control
 
    void add(){
 
        pl.add(this);
        updateList();
    }
 
    void remove(){
 
        try {
              int memoherdez=jList1.getLeadSelectionIndex();
              pl.ls.remove(memoherdez);
              updateList();
 
        } catch (Exception e) {
        }
 
    }
 
     void up(){
 
         try {
                int s1=jList1.getLeadSelectionIndex();
                simpan=(File)pl.ls.get(s1);
                pl.ls.remove(s1);
                pl.ls.add(s1-1,simpan);
                updateList();
                jList1.setSelectedIndex(s1-1);
 
         } catch (Exception e) {
         }
 
    }
 
      void down(){
 
          try {
                int s1=jList1.getLeadSelectionIndex();
                simpan=(File)pl.ls.get(s1);
                pl.ls.remove(s1);
                pl.ls.add(s1+1,simpan);
                updateList();
                jList1.setSelectedIndex(s1+1);
 
         } catch (Exception e) {
         }
 
    }
 
      void open(){
 
        pl.openPls(this);
        updateList();
    }
 
      void save(){
 
       pl.saveAsPlaylist(this);
       updateList();
    }
 
      File play1;
      static int a=0;
 
      void putar(){
 
          if(a==0)
             {
                 try {
                        int p1=jList1.getSelectedIndex();
                        play1=(File)this.updateList.get(p1);
                        FileInputStream fis=new FileInputStream(play1);
                        BufferedInputStream bis=new BufferedInputStream(fis);
                        player=new javazoom.jl.player.Player(bis);
                        a=1;
 
                 } catch (Exception e) {
                     System.out.println("Problema al tocar musica");
                     System.out.println(e);
                 }
 
                 new Thread()
                     {
                         @Override
                         public void run(){
 
                             try {
                                   player.play();
 
                             } catch (Exception e) {
 
                             }
                         }
 
                     }.start();
 
             }
          else
              {
                 player.close();
                 a=0;
                 putar();
 
              }
 
      }
 
      File sa;
      void next(){
 
      if(a==0)
             {
                 try {
                        int s1=jList1.getSelectedIndex()+1;
                        sa=(File)this.pl.ls.get(s1);
                        FileInputStream fis=new FileInputStream(sa);
                        BufferedInputStream bis=new BufferedInputStream(fis);
                        player=new javazoom.jl.player.Player(bis);
                        a=1;
                        jList1.setSelectedIndex(s1);
 
                 } catch (Exception e) {
                     System.out.println("Problema al tocar musica");
                     System.out.println(e);
                 }
 
                 new Thread()
                     {
                         @Override
                         public void run(){
 
                             try {
                                   player.play();
 
                             } catch (Exception e) {
 
                             }
                         }
 
                     }.start();
 
             }
          else
              {
                 player.close();
                 a=0;
                 next();
 
              }
 
      }
 
      void previous(){
 
             if(a==0)
             {
                 try {
                        int s1=jList1.getSelectedIndex()-1;
                        sa=(File)this.pl.ls.get(s1);
                        FileInputStream fis=new FileInputStream(sa);
                        BufferedInputStream bis=new BufferedInputStream(fis);
                        player=new javazoom.jl.player.Player(bis);
                        a=1;
                        jList1.setSelectedIndex(s1);
 
                 } catch (Exception e) {
                     System.out.println("Problema al tocar musica");
                     System.out.println(e);
                 }
 
                 new Thread()
                     {
                         @Override
                         public void run(){
 
                             try {
                                   player.play();
 
                             } catch (Exception e) {
 
                             }
                         }
 
                     }.start();
 
             }
          else
              {
                 player.close();
                 a=0;
                 previous();
 
              }
 
      }
 
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {
 
        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jList1 = new javax.swing.JList<>();
        jButton1 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();
        jButton7 = new javax.swing.JButton();
        jButton8 = new javax.swing.JButton();
        jButton9 = new javax.swing.JButton();
        jButton10 = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
 
        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
 
        jPanel1.setAutoscrolls(true);
 
        jScrollPane1.setViewportView(jList1);
 
        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/MainPackage/img/6.png"))); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
 
        jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/MainPackage/img/2.png"))); // NOI18N
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });
 
        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/MainPackage/img/1.png"))); // NOI18N
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
 
        jButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/MainPackage/img/3.png"))); // NOI18N
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });
 
        jButton5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/MainPackage/img/4.png"))); // NOI18N
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });
 
        jButton6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/MainPackage/img/10.png"))); // NOI18N
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });
 
        jButton7.setIcon(new javax.swing.ImageIcon(getClass().getResource("/MainPackage/img/9.png"))); // NOI18N
        jButton7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton7ActionPerformed(evt);
            }
        });
 
        jButton8.setIcon(new javax.swing.ImageIcon(getClass().getResource("/MainPackage/img/5.png"))); // NOI18N
        jButton8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton8ActionPerformed(evt);
            }
        });
 
        jButton9.setIcon(new javax.swing.ImageIcon(getClass().getResource("/MainPackage/img/7.png"))); // NOI18N
        jButton9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton9ActionPerformed(evt);
            }
        });
 
        jButton10.setIcon(new javax.swing.ImageIcon(getClass().getResource("/MainPackage/img/8.png"))); // NOI18N
        jButton10.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton10ActionPerformed(evt);
            }
        });
 
        jPanel2.setBackground(new java.awt.Color(0, 0, 0));
 
        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 349, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 377, Short.MAX_VALUE)
        );
 
        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jButton6, javax.swing.GroupLayout.DEFAULT_SIZE, 155, Short.MAX_VALUE)
                    .addComponent(jButton2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton5, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 208, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addComponent(jButton10)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButton9)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton8)
                        .addGap(35, 35, 35))))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jScrollPane1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton1, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jButton8, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton10, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jButton9, javax.swing.GroupLayout.Alignment.TRAILING)))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jButton4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton5)
                .addGap(4, 4, 4)
                .addComponent(jButton7)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButton6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButton2)
                .addGap(13, 13, 13)
                .addComponent(jButton3)
                .addGap(0, 122, Short.MAX_VALUE))
        );
 
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(23, 23, 23)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(23, Short.MAX_VALUE))
        );
 
        pack();
    }// </editor-fold>
 
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
    putar();    // TODO add your handling code here:
    }
 
    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
    up();        // TODO add your handling code here:
    }
 
    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
    down();   // TODO add your handling code here:
    }
 
    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
     add();   // TODO add your handling code here:
    }
 
    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {
    remove();    // TODO add your handling code here:
    }
 
    private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {
    save();   // TODO add your handling code here:
    }
 
    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {
    open();        // TODO add your handling code here:
    }
 
    private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) {
    previous();    // TODO add your handling code here:
    }
 
    private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {
    next();    // TODO add your handling code here:
    }
 
    private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {
    player.close();    // TODO add your handling code here:
    }
 
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Windows.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Windows.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Windows.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Windows.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>
 
        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Windows().setVisible(true);
            }
        });
    }
 
    // Variables declaration - do not modify
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton10;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton7;
    private javax.swing.JButton jButton8;
    private javax.swing.JButton jButton9;
    private javax.swing.JList<String> jList1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration
 
private DefaultListModel DefaultListModel() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }
ReproducirAudio:
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package MainPackage;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
 
public class ReproduceAudio {
    JFileChooser fc=new JFileChooser();
    ArrayList ls=new ArrayList();
 
    void add(JFrame frame){
        fc.setMultiSelectionEnabled(true);
        int fileValid=fc.showOpenDialog(frame);
        if (fileValid==javax.swing.JFileChooser.CANCEL_OPTION) {
        }else if(fileValid==javax.swing.JFileChooser.APPROVE_OPTION) {
            File[] file=fc.getSelectedFiles();
            ls.addAll(Arrays.asList(file));
        }
    }
 
    ArrayList getListSong(){
        return ls;
    }
    // save playlist
    FileOutputStream fos;
    ObjectOutputStream oos;
 
    public void saveAsPlaylist(JFrame frame){
        fc.setMultiSelectionEnabled(false);
        int Valid=fc.showSaveDialog(frame);
        if (Valid==javax.swing.JFileChooser.CANCEL_OPTION) {
        }
        else if(Valid==javax.swing.JFileChooser.APPROVE_OPTION) {
            File pls=fc.getSelectedFile();
            try {
              fos=new FileOutputStream(pls + ".tgr");
              oos=new ObjectOutputStream(fos);
              for(int i=0;i<ls.size();i++){
                   File tmp=(File) ls.get(i);
                   oos.writeObject(tmp);
              }
               oos.close();
            }
            catch (IOException e) {}
        }
    }
 
    FileInputStream fis;
    ObjectInputStream ois;
 
    public void openPls(JFrame frame){
 
        fc.setMultiSelectionEnabled(false);
        int Valid=fc.showOpenDialog(frame);
 
        if (Valid==javax.swing.JFileChooser.CANCEL_OPTION) {
            File pls=fc.getSelectedFile();
            try {
                   fis=new FileInputStream(pls);
                   ois=new ObjectInputStream(fis);
                   File tmp;
 
                   while((tmp=(File) ois.readObject())==null){
                       ls.add(tmp);
                   }
                   if((tmp=(File) ois.readObject())==null){
                          ls.isEmpty();
                      }
                   ois.close();
            } catch (IOException | ClassNotFoundException e) {}
        } else {}
    }
}
Solo quiero arreglar el error,porfavor ayudita.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder