Questions tagged [unreachable-statement]

Use this tag when your compiler is giving you "Unreachable code detected", "Unreachable statement" warning / error message for your code in question and you don't understand the reason.

Unreachable statements are codes that compilers detect as not reachable. There could be variety of situations when this happens.

Having a return statement in the middle of the code. The code that follows are considered as not reachable.

C# example:

string GetName()
{
   string s = "abc";
   return s; 
   s = s + "d"; // Warning CS0162: Unreachable code detected
   return s;
}

Another, would be having a variable defined with certain value and then check the variable for different value to do some operations.

while (false)
{
   Console.WriteLine("unreachable"); // Warning CS0162: Unreachable code detected
}

Java example:

public String getName()
{
   String s = "abc";
   return s; 
   s = s + "d"; // Unreachable statement
   return s;
}

Compilers generally throw Warning message for these type of issues. But it depends on compiler to compiler. For instance .NET compiler may just throw warning but Java may throw it as error.

61 questions
0
votes
1 answer

unreachable statement trying to set up a button that will open a new activity

Im very much new to this. I have a quick question. I get an "unreachable statement on line 30 (establecimientos = findViewById(R.id.establecimientos) while trying to set up that button to take me to a new activity. Can you help pointing at what is…
0
votes
2 answers

Unreachable Statement while Uploading 2 Images

I am trying to upload 2 images and this is a class used for that. However, I am getting unreachable statement error. public class uploadinfo { private String imageName; private String imageURL; private String imageURL2; public…
0
votes
3 answers

How to tell Android studio that a method does not return

I have an Android error handler which never returns (it logs a message and throws an error exception). If I call my error handler from a method which normally returns a value, the Android Studio lint checker reports an error because no value is…
0
votes
3 answers

Complex Conditionals and Unreachable Statements

I am very new to Java and am having some trouble. I feel like this an easy fix. Basically, I am looking to return a statement if two criteria are met. Below is my attached code. boolean Windy = false; if (Windy = true) return "It is…
Jack
  • 3
  • 4
0
votes
1 answer

What is the meaning of Unreacheable Statement

It says "int addition = t+r;" is an unreachable statement. what does that mean? How to correct it? public class parseMETHOD { public static void main(String[] args) { int a=9; int b=45; int…
0
votes
5 answers

Unreachable Statements if condition Java

double runde(double x, int n) { if (n < 0) { throw new IllegalArgumentException("Anzahl der Nachkommastellen darf nicht negativ sein."); return 0.0 ; } if (n==x) {/* Ist n=x? Wenn ja, dann nicht runden*/ return x ; } /* X…
user9163844
0
votes
1 answer

Cant ping from one VM workstation to another VM workstation connected through switch hub

I'm trying to set up 2 VMware workstations so that they will be able to communicate between each other. Despite connecting both of them to a hub through lan cable, they still failed to communicate to each other. The result from pinging between both…
user234568
  • 741
  • 3
  • 11
  • 21
0
votes
1 answer

It's showing unreachable statement error

I'm trying to make a toast on item selected but it's showing unreachable statement error. My code is: btn=(Button)findViewById(R.id.button); btn.setOnClickListener( new View.OnClickListener() { @Override …
Srinivas Nahak
  • 1,846
  • 4
  • 20
  • 45
0
votes
1 answer

How to avoid an "unreachable statement" due to compile-time-computed values?

If I write the following CUDA code: #include template __global__ void foo() { printf("In kernel foo() with N = %u\n", N); if (N < 10) { return; } printf("Wow, N is really high!\n"); /* a whole lot of code here…
einpoklum
  • 118,144
  • 57
  • 340
  • 684
0
votes
2 answers

Unreachable expression after launch of new thread

When the following code is run, it launches the thread r, as the output from it is received but the test phrase is never outputted though there are no errors outputted that would suggest an error. Why is this not able to progress past the thread…
pie154
  • 603
  • 3
  • 10
  • 28
0
votes
3 answers

Stuck in a loop of errors: unreachable statement and no return statement provided

Here is a snippet of my code: public static int dc (String s,int k, int c){ String s1, s2; int m, n; if (check(s, k) != -1) { int p = check(s, k); c++; s1 = s.substring(0, p) + s.substring(p + 1); s2 = s.substring(0, p + 1) +…
Rohinb97
  • 121
  • 5
0
votes
1 answer

java 8 unreachable statement switch case statement

Our teacher taught us about if-else statement and he's teaching us about how switch statement can be an alternative with if-else so I was coding and I get this unreachable statement error. I donno how I'm suppose to debug coz I just updated my Java…
0
votes
0 answers

Android ConnectivityManager is error 'unreachable statement'

@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { return inflater.inflate(R.layout.item_recipe_list, container, false); ConnectivityManager connMgr = …
0
votes
3 answers

Unreachable Statement On "Return"

Here's My First Class: public class Fraction { int Numerator; int Denominator; /** * Constructor for objects of class Fraction */ public Fraction() { // initialise instance variables Numerator=0; …
Brendan ten
  • 27
  • 1
  • 1
  • 3
0
votes
1 answer

How to do this Card class in java?

so basically for my computer science class we have to create a Card class which takes user input for the card notation (for example "4S") and has a getDescription method which returns the description of the card ("four of spades"). the problem is, i…