473,471 Members | 4,625 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Error in actionPerformed???

Hey, I'm trying to design a simple interface and I'm getting this
error:

actionPerformed(java.awt.event.ActionEvent) in GUI cannot implement
actionPerformed(java.awt.event.ActionEvent) in
java.awt.event.ActionListener; overridden method does not throw
java.io.IOException
public void actionPerformed(ActionEvent event)

I'm sure this is fairly simple but i'm relatively new to java and
can't work it out!

The code for actionPerformed is as follows, where GetContent and
CompareFiles are outside classes which deal with the URL and GUI is
the name of the overall class...

-----------------------------

public void actionPerformed(ActionEvent event)
throws MalformedURLException, IOException {

try {
URL url = new URL(enterURL.getText());
URLConnection connection = url.openConnection();
GetContent gc = new GetContent();
CompareFiles cf = new CompareFiles();
}

catch (MalformedURLException err)
{
System.err.println("Usage: java URLApp
http://www.URL.com");
}
catch (IOException e)
{
System.err.println("Run software again to check if
content has changed.");
}

-----------------------------

Thanks a lot,
Geoff
Jul 17 '05 #1
4 7177
"Geoff" <ge******@hotmail.com> wrote in message
news:18**************************@posting.google.c om...
Hey, I'm trying to design a simple interface and I'm getting this
error:

actionPerformed(java.awt.event.ActionEvent) in GUI cannot implement
actionPerformed(java.awt.event.ActionEvent) in
java.awt.event.ActionListener; overridden method does not throw
java.io.IOException
public void actionPerformed(ActionEvent event)

I'm sure this is fairly simple but i'm relatively new to java and
can't work it out!

The code for actionPerformed is as follows, where GetContent and
CompareFiles are outside classes which deal with the URL and GUI is
the name of the overall class...

-----------------------------

public void actionPerformed(ActionEvent event)
throws MalformedURLException, IOException {

*snip code*

The problem is exactly what it says. You can't make a method throw an
exception that doesn't. The actionPerformed method isn't declared to throw
an IOException, therefore you can't try to make it do so. However, at no
time in your code do you throw an IOException anyway. You catch any that
occur, so your method doesn't *need* this declaration, unless you're
planning to change it. I think you need to read up a bit more on Exceptions.
MalformedURLException is a RuntimeException, which is treated a bit
differently and probably won't cause you this problem, but again, you don't
need it there.
Jul 17 '05 #2
ge******@hotmail.com (Geoff) wrote in message news:<18**************************@posting.google. com>...
Hey, I'm trying to design a simple interface and I'm getting this
error:

actionPerformed(java.awt.event.ActionEvent) in GUI cannot implement
actionPerformed(java.awt.event.ActionEvent) in
java.awt.event.ActionListener; overridden method does not throw
java.io.IOException
public void actionPerformed(ActionEvent event)

I'm sure this is fairly simple but i'm relatively new to java and
can't work it out!

The code for actionPerformed is as follows, where GetContent and
CompareFiles are outside classes which deal with the URL and GUI is
the name of the overall class...

-----------------------------

public void actionPerformed(ActionEvent event)
throws MalformedURLException, IOException {

try {
URL url = new URL(enterURL.getText());
URLConnection connection = url.openConnection();
GetContent gc = new GetContent();
CompareFiles cf = new CompareFiles();
}

catch (MalformedURLException err)
{
System.err.println("Usage: java URLApp
http://www.URL.com");
}
catch (IOException e)
{
System.err.println("Run software again to check if
content has changed.");
}

-----------------------------

Thanks a lot,
Geoff

You method does not actually throw those errors. It catches and
handles them. Remove the throws from your method signature.

Greg
Jul 17 '05 #3
Yea I'd fixed the error but wasn't sure how.. but i know now, cheers!
Jul 17 '05 #4
ge******@hotmail.com (Geoff) wrote in message news:<18**************************@posting.google. com>...
Hey, I'm trying to design a simple interface and I'm getting this
error:

actionPerformed(java.awt.event.ActionEvent) in GUI cannot implement
actionPerformed(java.awt.event.ActionEvent) in
java.awt.event.ActionListener; overridden method does not throw
java.io.IOException
public void actionPerformed(ActionEvent event)

I'm sure this is fairly simple but i'm relatively new to java and
can't work it out!


As correctly noted elsewhere, it isn't possible for the exceptions listed
in the 'throws' clause to actually _escape_ from the method, due to the
exception handlers wrapping the main body of the code.

One unrelated, but useful, point: it really isn't good practice to run
lengthy operations - especially network IO where timings are particularly
unpredictable - from within an event handler. Event methods are called
on someone else's thread, so long execution times hog that thread and
prevent it from doing anything else (like processing further events,
perhaps!) Best practice is to exit from an event handler ASAP - firing
off a separate thread of our own if extended processing time is required.
-FISH- ><>
Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: nu b | last post by:
Hello all. I am new and I am having a tough time spotting my error here. The idea is to produce an applet that will have a JButton which I can push to display the string myName. Later I will make...
0
by: do | last post by:
This is direction: Modifying the calculateJButtonActionPerformed method. Modify the if statement that starts in line 217 to check if the user has not entered a name and/or selected any...
4
by: cnixuser | last post by:
Hello, I am posting reguarding some modifications I made to a text editor program that I wrote in my java class at my school today. The file I was modifying is a very simple java text editor with...
2
by: mak1084 | last post by:
hi get this error C:\Aprac\TableInsert.java:4: TableInsert is not abstract and does not override abstract method actionPerformed(java.awt.event.ActionEvent) in java.awt.event.ActionListener public...
15
by: cypriot | last post by:
Hi. I want to insert data to ms access from an application I developed in java but I think I have a prob with data types. This is my code. savebutton.addActionListener( new ActionListener()...
3
by: gokulagopal | last post by:
I am sending the code please help me in finding the error and correct it.The code is below: import java.awt.*; import java.awt.event.*; class CalcFrame extends Frame { ...
2
by: creativeinspiration | last post by:
Hi everybody, I have a question. In java I have a class which has global variables. Also, in this class I have an actionPerformed method implemented, which is called every time some event happens....
1
by: wco5002 | last post by:
Hey, I'm writing a simple program that stores several images in an array and allows the user to switch the images via a few buttons (first, previous, next, last) I've managed to get most of the code...
2
by: vijayrvs | last post by:
SearchCrawler.java The program search crawler used to search the files from the website. From the following program i got 7 compiler error. can any body clarify it and provide me solution. ...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.