|
Hi,
I don't understand why I get a error here, any help really appreciatet :)
this is the error I get from the last catch block:
Unreachable catch block for IOException. This exception is never thrown from the try statement body
import java.io.*;
import java.net.*;
public class OutputThread extends Thread
{
PrintWriter write;
protected static Socket out;
protected static DataOutputStream output;
protected String choice = "";
protected String newProduct = "";
protected String newPrice = "";
protected String newAmount = "";
public OutputThread (Socket clientSocket)
{
out = clientSocket;
write = null;
}
public void setChoice(String choice)
{
this.choice = choice;
}
public void addProduct(String newProduct, String newPrice)
{
this.newProduct= newProduct;
this.newPrice = newPrice;
}
public void addSale (String newProduct, String newAmount)
{
this.newProduct = newProduct;
this.newAmount = newAmount;
}
protected static void initialize()
{
try
{
output = new DataOutputStream(out.getOutputStream());
}
catch(IOException e)
{
System.out.println(e.getMessage());
}
}
public void sendData(double data)
{
try
{
output.writeDouble(data);
}
catch(IOException e)
{
System.out.println(e.getMessage());
}
}
public void run()
{
try
{
write = new PrintWriter(out.getOutputStream(), true);
}
catch (UnknownHostException e)
{
System.out.println(e.getMessage());
System.exit(1);
}
catch (IOException e)
{
System.err.println(e.getMessage());
System.exit(1);
}
try
{
BufferedReader stdIn = new BufferedReader(
new InputStreamReader(System.in));
String userInput;
while (!choice.equals(null))
{
if(choice.equals("1"))
{
write.println("addProduct");
userInput = newProduct;
write.println(userInput);
userInput = newPrice;
write.println(userInput);
choice = "0";
}
else if(choice.equals("2"))
{
write.println("addSales");
userInput = newProduct;
write.println(userInput);
userInput = newAmount;
write.println(userInput);
choice = "0";
}
else if(choice.equals("3"))
{
write.println("getTotalValue");
choice = "0";
}
}
}
catch(IOException e)
{
System.out.println(e.getMessage());
}
}
}
|
|
|
|
|
The class compiles okay without it.
// try
// {
BufferedReader stdIn = new BufferedReader(
new InputStreamReader(System.in));
String userInput;
while (!choice.equals(null))
{
if(choice.equals("1"))
{
write.println("addProduct");
userInput = newProduct;
write.println(userInput);
userInput = newPrice;
write.println(userInput);
choice = "0";
}
else if(choice.equals("2"))
{
write.println("addSales");
userInput = newProduct;
write.println(userInput);
userInput = newAmount;
write.println(userInput);
choice = "0";
}
else if(choice.equals("3"))
{
write.println("getTotalValue");
choice = "0";
}
}
// }
// catch(IOException e)
// {
// System.out.println(e.getMessage());
// }
}
|
|
|
|
|
|
|
|
|
|