Results 1 to 6 of 6
Thread: unreported IOException problem
- 04-20-2010, 10:38 PM #1
Member
- Join Date
- Mar 2009
- Posts
- 48
- Rep Power
- 0
unreported IOException problem
hi,
i am trying to call one method from different file but getting this error..
i already reported this exception in that method but cant understand where else need to report ?callMethod.java:31: unreported exception java.io.IOException; must be caught or declared to be thrown
the method of MyFile:Java Code:public class callMethod extends JFrame implements ActionListener { JButton button; callMethod(){ button=new JButton("show"); button.addActionListener(this); add(button); } public static void main(String[] args) throws IOException { callMethod cm=new callMethod(); cm.setSize(200,100); cm.setVisible(true); } public void actionPerformed (ActionEvent e) { if (e.getSource()==button) { MyFile file=new MyFile(); String[][] show=file.method("get", "20"); //error mentioned in this line .. .. } }
i can run it from MyFile but cant call from different file...Java Code:public String[][] method(String name, String value) throws IOException { ... ..
pls help me...what we are thinking, it might not be true
- 04-20-2010, 10:41 PM #2
Senior Member
- Join Date
- Mar 2010
- Posts
- 266
- Rep Power
- 4
cannot throw an IOException. Even if you add is asJava Code:public void actionPerformed (ActionEvent e)
it will complain (although differently).Java Code:public void actionPerformed (ActionEvent e) throws IOException
do this:
Java Code:public void actionPerformed (ActionEvent e) { try { // execute IOException-throwing stuff } catch (IOException ex) { // do something with it: ex.printStackTrace(), or throw a runtime exception, or simply ignore it. } }
-
the method, "method" throws the exception but your actionPerformed method calls this method and doesn't do anything with the exception. I recommend you do what the error is in essence telling you to do: put the method call in the actionPerformed in a try/catch block.
Java Code:public void actionPerformed (ActionEvent e) { if (e.getSource()==button) { MyFile file=new MyFile(); try { String[][] show=file.method("get", "20"); } catch (IOException ioe) { ioe.printStackTrace(); // or whatever else may need to be done if file not found } .. .. } }
- 04-20-2010, 11:02 PM #4
Member
- Join Date
- Mar 2009
- Posts
- 48
- Rep Power
- 0
great great thanks........
really appreciate you....
Why i cant add reputation for you Fubarable??
its showing message "you must spread some reputation around................"what we are thinking, it might not be true
-
You've need to give to others before you can give to me. Not to worry though, it's the thought that counts.
- 04-20-2010, 11:14 PM #6
Member
- Join Date
- Mar 2009
- Posts
- 48
- Rep Power
- 0
Similar Threads
-
Unreported exception java.sql.SQLException
By javamula in forum AWT / SwingReplies: 4Last Post: 09-29-2009, 02:32 PM -
unreported exception IOException -- Yet I AM catching it?
By Agathorn in forum New To JavaReplies: 2Last Post: 09-18-2009, 11:22 PM -
IOException error
By eeraj in forum AWT / SwingReplies: 3Last Post: 08-31-2009, 04:05 AM -
Error: unreported exception java.io.IOException; ??
By jonsamwell in forum New To JavaReplies: 5Last Post: 08-24-2008, 04:11 AM -
GUI IOException
By serfster in forum New To JavaReplies: 3Last Post: 06-13-2008, 04:19 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks