Exeptions mir dem jfilechooser

Status
Nicht offen für weitere Antworten.

rock

Mitglied
Hi, wollte einen einfachen filechooser der nur string array macht wo alle absolute pfade der Dateien drin sind die man angeklickt hat. Und das klappt auch aber er wirft die ganze Zeit IndexOutOfBoundsException
Kann mir einer helfen?

Code:
package applets;

import java.io.File;
import javax.swing.JFileChooser;


public class uploadapp extends javax.swing.JApplet {
    int returnVal=1;
    JFileChooser fc=new JFileChooser();
    
    public void init() {
        try {
            java.awt.EventQueue.invokeAndWait(new Runnable() {
                public void run() {
                    initComponents();
                }
            });
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

   
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        btndurchsuchen = new javax.swing.JButton();

        btndurchsuchen.setLabel("Durchsuchen...");
        btndurchsuchen.setName(""); // NOI18N
        btndurchsuchen.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btndurchsuchenActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(33, 33, 33)
                .addComponent(btndurchsuchen)
                .addContainerGap(294, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(btndurchsuchen)
                .addContainerGap(266, Short.MAX_VALUE))
        );
    }// </editor-fold>

private void btndurchsuchenActionPerformed(java.awt.event.ActionEvent evt) {
    fc = new JFileChooser();
    fc.setMultiSelectionEnabled(true);

        File[] files = null; 
        int laenge=0;
        String[] SelectedFiles=null;
        
        if (evt.getSource() == btndurchsuchen){
            returnVal = fc.showOpenDialog(uploadapp.this); 
            if ( returnVal == JFileChooser.APPROVE_OPTION) {
                files = fc.getSelectedFiles();
                laenge = files.length;
                SelectedFiles = new String[laenge];
            }
                 else {
                
                }
            
        }
      

        for(int i=0;i< laenge; i++)
        {   SelectedFiles[i]= files[i].getAbsolutePath();
            System.out.println(SelectedFiles[i]);
        }
}


    // Variables declaration - do not modify
    private javax.swing.JButton btndurchsuchen;
    // End of variables declaration

}

Exception
Code:
Exception occurred during event dispatching:
java.lang.IndexOutOfBoundsException: Invalid index
        at javax.swing.DefaultRowSorter.convertRowIndexToModel(DefaultRowSorter.java:497)
        at sun.swing.FilePane$SortableListModel.getElementAt(FilePane.java:528)
        at javax.swing.plaf.basic.BasicListUI.paintCell(BasicListUI.java:191)
        at javax.swing.plaf.basic.BasicListUI.paintImpl(BasicListUI.java:304)
        at javax.swing.plaf.basic.BasicListUI.paint(BasicListUI.java:227)
        at javax.swing.plaf.ComponentUI.update(ComponentUI.java:143)
        at javax.swing.JComponent.paintComponent(JComponent.java:763)
        at javax.swing.JComponent.paint(JComponent.java:1027)
        at javax.swing.JComponent.paintToOffscreen(JComponent.java:5122)
        at javax.swing.BufferStrategyPaintManager.paint(BufferStrategyPaintManager.java:277)
        at javax.swing.RepaintManager.paint(RepaintManager.java:1213)
        at javax.swing.JComponent._paintImmediately(JComponent.java:5070)
        at javax.swing.JComponent.paintImmediately(JComponent.java:4880)
        at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:799)
        at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:714)
        at javax.swing.RepaintManager.seqPaintDirtyRegions(RepaintManager.java:694)
        at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:128)
        at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:284)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:178)
        at java.awt.Dialog$1.run(Dialog.java:1046)
        at java.awt.Dialog$3.run(Dialog.java:1098)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.awt.Dialog.show(Dialog.java:1096)
        at javax.swing.JFileChooser.showDialog(JFileChooser.java:723)
        at javax.swing.JFileChooser.showOpenDialog(JFileChooser.java:626)
        at applets.uploadapp.btndurchsuchenActionPerformed(uploadapp.java:64)
        at applets.uploadapp.access$100(uploadapp.java:7)
        at applets.uploadapp$2.actionPerformed(uploadapp.java:33)
        at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
        at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
        at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
        at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
        at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
        at java.awt.Component.processMouseEvent(Component.java:6134)
        at javax.swing.JComponent.processMouseEvent(JComponent.java:3265)
        at java.awt.Component.processEvent(Component.java:5899)
        at java.awt.Container.processEvent(Container.java:2023)
        at java.awt.Component.dispatchEventImpl(Component.java:4501)
        at java.awt.Container.dispatchEventImpl(Container.java:2081)
        at java.awt.Component.dispatchEvent(Component.java:4331)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4299)
        at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3963)
        at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3893)
        at java.awt.Container.dispatchEventImpl(Container.java:2067)
        at java.awt.Component.dispatchEvent(Component.java:4331)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:284)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
 
Applet -> Sandbox
Darf nicht auf lokale Ressourcen zugreifen

Muss dafür signiert werden!

So generell noch:
- Klassenname groß
- Variablennamen klein
 
Dann müsste eine andere Exception ausgeworfen werden, die auch ausgeworfen wird wenn ich es von einem html file aus lade.
Und bei Eclipse und NetBeans kann ich normal Dateien hin und her switchen und auch mehrere Dateien auswählen die dann auch ausgegeben werden aber es wird ständig die "java.lang.IndexOutOfBoundsException" ausgeworfen sonst läufts normal
 
kann viellecht jemand erklären was damit gemeint ist?


Anonymous hat gesagt.:
In the BasicDirectoryModel class the SwingUtilities.invokeLater(...) method should be invoked from caller thread instead of COM-thread.

ich benutze kein SwingUtilities.invokeLater

mein Programm:

Anonymous hat gesagt.:
// create a file chooser dialog
JFileChooser file_chooser = new JFileChooser(appletPath + searchDirectory);
file_chooser.setMultiSelectionEnabled(false);
file_chooser.setDialogType(JFileChooser.OPEN_DIALOG);

// set filter to accept .rpy files
file_chooser.setFileFilter(new FileFilter() {
public boolean accept(File f) {
return f.isDirectory() || f.getName().toLowerCase().endsWith(".rpy");
}
public String getDescription() {
return "Rhapsody Project Files (*.rpy)";
}
});

// set filter to accept XML files
file_chooser.setFileFilter(new FileFilter() {
public boolean accept(File f) {
return f.isDirectory() || f.getName().toLowerCase().endsWith(".xml");
}
public String getDescription() {
return "Model Description Files (*.xml)";
}
});

int iReturn = file_chooser.showOpenDialog(null);

if (iReturn == JFileChooser.APPROVE_OPTION) {
loadModelDesriptionFile(file_chooser.getSelectedFile().getAbsolutePath());
}
 
Status
Nicht offen für weitere Antworten.

Zurück
Oben