• Post Reply Bookmark Topic Watch Topic
  • New Topic

Open File Function

 
Mathew Mintalm
Ranch Hand
Posts: 103
Eclipse IDE Firefox Browser Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello.

I would like to ask for help.

I have strange problem (for me) with my "Open File Function"

Ok so let me explain my problem, so I have for example simple GUI window.

I have void for my GUI component and constructor for class:



I have menu in my Window with button with Action to use loadFile(); function:



and here is my loadFile function:



And everything works fine, If I will press my button with loadFile function it will show me JFileChooser, I can type file etc. And for example I'll try to open some kind of txt file it show me this error:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at l2jeditor.MainWindow.getJTextArea(MainWindow.java:78)
at l2jeditor.MainWindow.loadFile(MainWindow.java:57)
at l2jeditor.MainWindow.access$4(MainWindow.java:51)
at l2jeditor.MainWindow$20.actionPerformed(MainWindow.java:979)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.AbstractButton.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)


Would be great if someone could help me.
 
Paul Clapham
Sheriff
Posts: 21892
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The stack trace shows the exception being thrown in a method named "getJTextArea". And that method is called from a method named "loadFile".

However the loadFile method you posted does not call a getJTextArea method. So the code you are looking at is not the code which throws the exception. You should recompile and redeploy to make sure you are looking at the right code.
 
Mathew Mintalm
Ranch Hand
Posts: 103
Eclipse IDE Firefox Browser Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe is there anyone who is able to show me another method to open file and add text from this file in my textArea ?
 
Rob Spoor
Sheriff
Posts: 20822
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your code should work, but as Paul mentioned the error is coming from somewhere else.
 
Mathew Mintalm
Ranch Hand
Posts: 103
Eclipse IDE Firefox Browser Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I dont know why but I can relate to my textArea if i want to do it beyond my

private void initComponents() {

Maybe someone know whats could be wrong.

I can compile without error, but as I can see i have this kind of error all the time when i would like to relete to my textArea beyond this void..
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> Maybe someone know whats could be wrong.

no one knows because the error is in the code you haven't posted.

we can guess - how much time do you have?

if the code is only about 2/300 lines, post all your code
 
Mathew Mintalm
Ranch Hand
Posts: 103
Eclipse IDE Firefox Browser Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
~1500 lines in 4 classes.

 
Rob Spoor
Sheriff
Posts: 20822
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Paul already mentioned, the exception is thrown on line 78, in method getJTextArea. Some object on that line is null.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!