Reputation: 5609
This is an excerpt from the code:
if (resultText.equalsIgnoreCase("open browser"))
{
try{
Process p; //resultText="";
p = Runtime.getRuntime().exec("cmd /c start chrome.exe");
}catch(Exception ae){}
}
In the eclipse its showing a warning as:
The value of local variable p is not used
What's wrong in here? Please help me understand the problem. Thank you.
Upvotes: 1
Views: 233
Reputation: 6816
Why do you need to p at all ?
Process p; //resultText="";
p = Runtime.getRuntime().exec("cmd /c start chrome.exe");
You are not using it after assign value to it. If you use it the warning will go away.
You code should be:
if (resultText.equalsIgnoreCase("open browser"))
{
try{
Runtime.getRuntime().exec("cmd /c start chrome.exe");
}catch(Exception ae){}
}
As you don't need variable p at all.
Upvotes: 2
Reputation: 103
Basically its not actually an error. It's your Eclipse, warning you that you aren't actually reading that variable (p), so you aren't receiving any input from it.
Nowhere in the code, you use the variable p.
To remove the error - it is necessary to remove the variable "p".
Upvotes: 1
Reputation: 3
Try this:
if (resultText.equalsIgnoreCase("open browser"))
{
try{
Runtime.getRuntime().exec("cmd /c start chrome.exe");
}catch(Exception ae){
System.out.println("An error has oucurd... :d sorry");
}
}
Upvotes: 0
Reputation: 794
You can ignore warnings.
It's just telling you that you assigned a value to p
but never used it.
Upvotes: 0
Reputation: 5661
The warning is telling you that you are assigning a value to p
, but never using it afterwards.
It is a warning, so it is ignorable.
Upvotes: 2
Reputation: 14296
This is just a warning from the IDE. It's not an error. It's just letting you know that p
is never being used. You could just make your code into:
if (resultText.equalsIgnoreCase("open browser"))
{
try{
Runtime.getRuntime().exec("cmd /c start chrome.exe");
}catch(Exception ae){}
}
And it will do the same thing.
Upvotes: 5