Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Unhandled exception type UnknownHostException

Reply
Thread Tools

Unhandled exception type UnknownHostException

 
 
Linus
Guest
Posts: n/a
 
      02-25-2005
Someone can tell me why running the code it returns the error:
Unhandled exception type UnknownHostException

import java.io.*;
import java.net.*;


public class ArrayClient {


public static void main(String argv[]) {

ObjectOutputStream oos = null;
ObjectInputStream ois = null;
//un pacchetto
try
{
final InetAddress localAddr2 = InetAddress.getLocalHost();
pacchetto pak=new pacchetto(1,"217.9.65.34",localAddr2,999);
System.out.println("Questo pacchetto "+ pak );
InetAddress destinazione;




// two arrays
int dataset1[] = {3, 3, 3, 3, 3, 3, 3};
int dataset2[] = {5, 5, 5, 5, 5, 5, 5};
try {
// open a socket connection
Socket socket = new Socket("127.0.0.1", 4000);
System.out.println("Contenuto di Socket: "+ socket );
// open I/O streams for objects
oos = new ObjectOutputStream(socket.getOutputStream());
ois = new ObjectInputStream(socket.getInputStream());
// create two serialized objects
SerializedObject so1 = new SerializedObject();
SerializedObject so2 = new SerializedObject();
SerializedObject result = null;
int outArray[] = new int[7];
so1.setArray(dataset1);
so2.setArray(dataset2);
// write the objects to the server
oos.writeObject(so1);
oos.writeObject(so2);
oos.flush();
// read an object from the server
result = (SerializedObject) ois.readObject();
outArray = result.getArray();
System.out.print("The new array is: ");
// after unpacking the array, iterate through it
for(int i=0;i<outArray.length;i++) {
System.out.print(outArray[i] + " ");
}
oos.close();
ois.close();
}
catch (UnknownHostException e)
{
System.err.println ("Can't detect localhost : " + e);
}

} catch(Exception e) {
System.out.println(e.getMessage());
}
}
}

//THE PACCHETTO CLASS:

import java.io.Serializable;
import java.net.*;

public class pacchetto implements Serializable
{
int hopToLive=0;
InetAddress destinatario;
InetAddress mittente;
InetAddress[] nodiIntermedi= new InetAddress[5];
int time;

pacchetto(int i,String j, InetAddress k, int l)
{
hopToLive=i;
destinatario=InetAddress.getByName(j);
mittente=k;
for (int m=0; m<4;m++)
{
nodiIntermedi[m]=null;
}
time=l;

}

public int getNumeroHop()
{
return hopToLive;
}

public void setNumeroHop(int i)
{
hopToLive=i;
}



public InetAddress getDestinatario()
{
return destinatario;
}

public void setDestinatario(InetAddress i)
{
destinatario=i;
}

public InetAddress getMittente()
{
return mittente;
}

public void setMittente(InetAddress i)
{
mittente=i;
}

public InetAddress getNodiIntermedi(int i)
{
return nodiIntermedi[i];
}

public InetAddress[] getNodiIntermedi()
{
return nodiIntermedi;
}

public void setNodiIntermedi(InetAddress value,int i)
{
nodiIntermedi[i] = value;
}

public int getTime()
{
return time;
}

public void setTime(int i)
{
time=i;
}




}
 
Reply With Quote
 
 
 
 
Tilman Bohn
Guest
Posts: n/a
 
      02-25-2005
In message <(E-Mail Removed) >,
Linus wrote on 25 Feb 2005 02:49:35 -0800:

> Someone can tell me why running the code it returns the error:
> Unhandled exception type UnknownHostException


But that is not the real error you get. The real error message
actually tells you how to fix it. Either catch UnknownHostException in
your pacchetto class, or declare that you throw it. The compiler is even
so nice as to tell you the exact line number where you call
InetAddress.getByName() and prints that line out for you.

As an aside, and referring to http://www.physci.org/codes/sscce.jsp ,
your example is neither short, nor self-contained, nor correct. Your
code does not compile as posted (apart from that particular error).
There is no SerializedObject type anywhere. Your code is also not
minimal, since all the stuff you're doing with those is not necessary to
reproduce the problem in the first place.

--
Cheers, Tilman

`Boy, life takes a long time to live...' -- Steven Wright
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
an unhandled win32 exception was unhandled occurred in inetinfo.exe Warren Tang ASP .Net 1 09-23-2008 03:01 PM
An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in sy NicK chlam via DotNetMonster.com ASP .Net 0 03-21-2005 01:01 AM
An unhandled exception has been caught by the VSW exception filter. Tedka ASP .Net 2 07-19-2004 08:09 PM
An unhandled exception has been caught by the VSW exception filter. Ola ASP .Net 0 04-26-2004 01:00 PM
An unhandled exception of type 'System.Threading.ThreadAbortException' occurred in Unknown Module. Lee Simpson ASP .Net 0 07-18-2003 09:52 AM



Advertisments