1

NetBeans are sending error messages when ever i try to read the file after selecting the file from hard disk using JFileChooser the error message i get this messages but and the file are not loading in the JTable

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at AnimeAid.GuiInterface.createModel(GuiInterface.java:252)
at AnimeAid.GuiInterface.access$100(GuiInterface.java:34)
at AnimeAid.GuiInterface$2.actionPerformed(GuiInterface.java:144)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
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:6505)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3320)
at java.awt.Component.processEvent(Component.java:6270)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:735)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:694)
at java.awt.EventQueue$3.run(EventQueue.java:692)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:708)
at java.awt.EventQueue$4.run(EventQueue.java:706)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:705)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)

the method of reading

private DefaultTableModel createModel(String srtPath) {
    int maxLine = ReadFile.maxLine(srtPath);  // debug
    //Object[][] data = new Object[maxLine][];
    System.out.println(maxLine);  // debug
    ArrayList<String> ends = ReadFile.getFileEndingTime(srtPath);
    ArrayList<String> starts = ReadFile.getFileStartingTime(srtPath);
    ArrayList<String> subs = ReadFile.readSubtitles(srtPath);
    for (int i = 0; i < ReadFile.maxLine(srtPath) - 1; i++) {
        model.addRow(new Object[] {starts.get(i), ends.get(i), subs.get(i)});
    }


    return model;
}

the line number 221 is :

model.addRow(new Object[] {starts.get(i), ends.get(i), subs.get(i)});

when i apply this to my code inside for-loop and delete model.addRow(new..) i get all the value printed right so it is not = null so what is the issue if i did not delete model.addRow... only the first value of the file are printed

System.out.println(lins.get(i)+" "+starts.get(i)+" "+ ends.get(i)+" "+ subs.get(i));

the printed value looks like this

    1 00:00:01,600 0:00:04,080 <b>Mr Magnussen, please state your
full name for the record.</b>
2 00:00:04,080 0:00:07,040 Charles Augustus Magnussen.
3 00:00:08,960 0:00:12,160 how would you describe your

now i will add the every declaration and initialization related to the case

public class GuiInterface extends JFrame {
    String[] columnNames = {"#", "Start", "End", "Translation column"};
    DefaultTableModel model;
public GuiInterface(String title){
table = new JTable(new DefaultTableModel(columnNames, 1)); // look here


  ImageIcon openIcon = new ImageIcon(
                GuiInterface.class.getResource("/resources/image/folder-icon.png"));
        ImageIcon saveIcon = new ImageIcon(
                GuiInterface.class.getResource("/resources/image/red-disk-icon.png"));
        ImageIcon newIcon = new ImageIcon(
                GuiInterface.class.getResource("/resources/image/Actionsnew-icon.png"));




        Action openAction = new AbstractAction("Open Subtitle", openIcon) {
            @Override
            public void actionPerformed(ActionEvent e) {
                ourFileSelector.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
                ourFileSelector.showSaveDialog(null);
                ourSrtFile =  ourFileSelector.getSelectedFile();
                srtPath = ourSrtFile.getAbsolutePath();
                DefaultTableModel model = createModel(srtPath); //look here
                table.setModel(model);
            }
        };

}

 private DefaultTableModel createModel(String srtPath) {
    //int maxLine = ReadFile.maxLine(srtPath);  // debug
    //Object[][] data = new Object[maxLine][];
    //System.out.println(maxLine);  // debug
    DefaultTableModel model = new DefaultTableModel(columnNames, 0);// and here
    ArrayList<String> ends = ReadFile.getFileEndingTime(srtPath);
    ArrayList<String> starts = ReadFile.getFileStartingTime(srtPath);
    ArrayList<String> subs = ReadFile.readSubtitles(srtPath);
    ArrayList<String> lins = ReadFile.ArraylineLengths(srtPath);
    for (int i = 0; i < ReadFile.maxLine(srtPath) - 1; i++) {
        //System.out.println(lins.get(i)+" "+starts.get(i)+" "+ ends.get(i)+" "+ subs.get(i));
        model.addRow(new Object[] {lins.get(i), starts.get(i), ends.get(i), subs.get(i)});
    }
    return model;
}
  • Are you by any chance calling `updateUI()`? See also [`FileBrowser`](http://codereview.stackexchange.com/q/4446). – trashgod Mar 29 '14 at 19:56
  • 1
    Your second code block is irrelevant to the question. Show where your add your `Actions` to the `JToolBar` – Paul Samsotha Mar 30 '14 at 01:54
  • Please clearly label line 252 in your code snippet, as we have no way of associating line numbers from a stack trace with pasted code. Also ensure that `ReadFile`, `model`, `starts`, `ends`, and `subs` are not `null`. Also see http://stackoverflow.com/questions/218384/what-is-a-null-pointer-exception/218510#218510 – Jason C Mar 30 '14 at 15:39
  • @peeskillet can you take look why it is null pointer –  Mar 30 '14 at 16:44
  • can you tell me where is the issue i have to complete the project –  Mar 30 '14 at 19:40
  • @JasonC read the edit –  Mar 30 '14 at 23:40
  • @jackpeton Then `model` is `null`... did you read http://stackoverflow.com/questions/218384/what-is-a-null-pointer-exception/218510 or http://docs.oracle.com/javase/7/docs/api/java/lang/NullPointerException.html? – Jason C Mar 30 '14 at 23:43
  • it say if the object os = null; then this error going to happen but my method of reading from array are working fine and it say also Thrown when an application attempts to use null in a case where an object is required. These include: Calling the instance method of a null object. Accessing or modifying the field of a null object. Taking the length of null as if it were an array. Accessing or modifying the slots of null as if it were an array. Throwing null as if it were a Throwable value –  Mar 31 '14 at 08:52
  • where this is null coming from because the value are not null –  Mar 31 '14 at 08:53
  • @peeskillet can you take look at that –  Mar 31 '14 at 10:02
  • 1
    If all the values are in the list. The only thing that can be null is your model. Check if it has been initialized. Otherwise it has to be in the list. Print everything in the list. I can't help you much with the information you've provided. – Paul Samsotha Mar 31 '14 at 10:12
  • i think the wrong are coming form table = new JTable(new DefaultTableModel(columnNames, 1)); because i initialized again but in the method model are pointing to the global model so there is no model –  Mar 31 '14 at 10:41
  • @peeskillet i update the information can you take a look –  Mar 31 '14 at 10:54
  • 1
    1) I never told you to put the `DefaultTableModel` global, just the headers. 2) You never initialize it. 3) Put it back in the method where I had it. – Paul Samsotha Mar 31 '14 at 11:12
  • @peeskillet look for the comment //look here –  Mar 31 '14 at 11:45
  • 1
    I don't see what the problem is. – Paul Samsotha Mar 31 '14 at 11:48
  • no problem thanks it is uploading so slow as you told also the size of the column are not the same i width i asked –  Mar 31 '14 at 11:55

0 Answers0