🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.swing
Article #8712

Re: JTextField - Unable to throw IOException

#8712
From: David Haynes
Date: Mon, 24 Jul 2000 00:00
34 lines
2073 bytes
On Sun, 23 Jul 2000 22:10:20 GMT, lchiacch@ix.netcom.com (Len
Chiacchia) wrote:

This message is telling you that one of the calls to java.net is 
capable of thowing an UnknownHostException and that you
have not written any code to catch this condition. 

Looking at your code, the possible candidates are:
getByName and getHostAddress. So, you need to wrap them
in a try {...} catch {...} construct. For example,
public void jButton1_actionPerformed(ActionEvent e) {
	String myIP = jTextField1.getText();
	try {
		InetAddress inet = InetAddress.getByName(myIP);
		jTextField3.setText(inet.getHostAddress());
	}
	catch ( UnknownHostException e ) {
		System.err.println("Cannot find host entry");
	}
}

>
>I am trying to use a JTextField for the user to enter an IP address.
>The user will click the JButton which then will run a routine that
>will get the Internet Host Name.  It can't get it to work. I get an
>error that 'unreported exception: java.net.UnknownHostException; must
>be caught or declared to be thrown.'  Here is the applicable code
>segments.  Can anyone tell me what I missed????  Len
>. 
> public void jButton1_actionPerformed(ActionEvent e) {
>        String myIP = jTextField1.getText();
>        InetAddress inet = InetAddress.getByName(myIP);
>        jTextField3.setText(inet.getHostAddress());
>  }
Technical Details
Message-ID: <ea1ons8bcsbjjoktqfjj128f927paskl78@4ax.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <397b69e8.14384932@nntp.ix.netcom.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,5868b15b38c39c4
X-Google-Attributes: gid111d45,public
From: David Haynes <david.haynes2@sympatico.ca>
Subject: Re: JTextField - Unable to throw IOException
Date: 2000/07/24
Message-ID: <ea1ons8bcsbjjoktqfjj128f927paskl78@4ax.com>
X-Deja-AN: 650048236
Content-Transfer-Encoding: 7bit
References: <397b69e8.14384932@nntp.ix.netcom.com>
Content-Type: text/plain; charset=us-ascii
X-Abuse-Info: Otherwise we will be unable to process your complaint properly
X-Complaints-To: support@usenetserver.com
Organization: DHC Inc.
MIME-Version: 1.0
NNTP-Posting-Date: Mon, 24 Jul 2000 05:03:58 EDT
Newsgroups: borland.public.jbuilder.java.swing