Re: catch error statement
It ouputs "Error: null" if you hit an exception with a null message. For details:
Code:
} catch(Exception e) {
//System.err.println("Error: " + e.getMessage());
e.printStackTrace();
}
Re: catch error statement
It ouputs "Error: null" if you hit an exception with a null message. For details:
Code:
} catch(Exception e) {
//System.err.println("Error: " + e.getMessage());
e.printStackTrace();
}
Re: catch error statement
alright. doesn't help me much because all i get is this...
Code:
java.lang.NullPointerException
at gui.writeToTextArea(gui.java:192)
at taskBckg.listTask(taskBckg.java:221)
at taskBckg.processRequest(taskBckg.java:109)
at gui.actionPerformed(gui.java:177)
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.plaf.basic.BasicButtonListener.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.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(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)
I'm thinking that it doesn't like my listTask() method. before I had it do a "throws IOException". I changed it to try catch to see if I could get it working this way...
Code:
public void listTask() {
gui setStatus = new gui();
try {
BufferedReader in = new BufferedReader(new FileReader("tasks.txt"));
Scanner scanner = new Scanner(new File("tasks.txt"));
Pattern pattern = Pattern.compile("(.+)Ø(.+)Ø(.+)§");
while (scanner.hasNextLine()) {
Matcher m = pattern.matcher(scanner.nextLine());
if (m.find()) {
setStatus.writeToTextArea('n', "\n "
+ ": \nTask Title: " + m.group(1)
+ " \nTask Content: " + m.group(2)
+ " \nTask Priority: " + m.group(3) + "\n\n");
}
}
in.close();
} catch (Exception e) {
e.printStackTrace();
}
}
here is my method that calls on list task:
Code:
public void processRequest(String command) {
command = command.toUpperCase();
// gui3.writeToTextArea('n', task);
switch (command) {
case "L":
gui updateInput = new gui();
listTask();
System.out.print("Now Listing tasks...");
break;
}
}
Re: catch error statement
That helps a lot.
You now know what the error is (a null pointer), and where it is occurring (line 192 of gui).
So you now know something on line 192 is null and you are attempting to call a method or access an attribute of it.
Re: catch error statement
hm... well here is line 192...
Code:
textArea.append(userInputText.toUpperCase());
not sure how it helps without any context. let me know if you would like to see other code. but not sure why that wouldn't be working. it seems like there are errors in other places too?
also, do you know how to show the line numbers in eclipse?
Re: catch error statement
i also get this error in gui: Code:
The type gui must implement the inherited abstract method WindowListener.windowOpened(WindowEvent)
on line: Code:
public class gui implements WindowListener,ActionListener {
Re: catch error statement
Quote:
Originally Posted by
droidus
hm... well here is line 192...
Code:
textArea.append(userInputText.toUpperCase());
not sure how it helps without any context. let me know if you would like to see other code. but not sure why that wouldn't be working. it seems like there are errors in other places too?
Either textArea or userInputText is null when this line is executed.
Quote:
Originally Posted by
droidus
also, do you know how to show the line numbers in eclipse?
Window->Preferences->Editor->somewhere under here.
Quote:
Originally Posted by
droidus
i also get this error in gui:
Code:
The type gui must implement the inherited abstract method WindowListener.windowOpened(WindowEvent)
on line:
Code:
public class gui implements WindowListener,ActionListener {
That says your code doesn't compile, which begs the question of how you've managed to run it.
Anyway, gui is implementing WindowListener, so must implement all the methods of that, including windowOpened.
Re: catch error statement
in my gui class, i have the following:
Code:
textArea = new JTextArea(5, 20);
won't that initialize the text area?
and i had a method called before that modified the text area:
Code:
gui.writeToTextArea('s', "What would you like to do? [L]ist tasks or [C]reate a new one or [E]dit a task or [D]elete a task or [H]elp?");
Re: catch error statement
Then, if textArea is definitely not null (and until you stick a System.out.println to show that you are probably guessing) it must be userInputText.
I'd suggest sticking some debugging Sysouts in there to see what's going on.
Put simply, the JVM doesn't lie. Something on the line that throws a NullPointer is null.
Re: catch error statement
user input text seems to work. when i print out textArea, it says null. then when i use .getText() on it, it returns "java.lang.NullPointerException". it should be textArea.getText(), not textArea, right?
Re: catch error statement
If textArea is null then you need to figure out why it isn't being set.
You cannot call a method on a null reference.