Search code examples
androideclipsedead-code

Dead code using android eclipse


I am working on android application in which i am using a logic to find the direction of a person from coordinated. Everything is working fine but i got error at console: : "Dead Code". My code is given below, please explain me this thing.

private void direction() {

        String userLocation = mLatitude + ","
                + mLongitude ;

        if(userLocation!=null){
            String distLocation = Constants.sMY_LOCATION.getLatitude() + ","
                    + Constants.sMY_LOCATION.getLongitude();
            String url = "https://maps.google.com/maps?f=d&saddr=" + userLocation
                    + "&daddr=" + distLocation;
            Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
            startActivity(i);
        }else{ // Getting Dead Code Yellow error here
            finish();
            Toast.makeText(getBaseContext(), "Please check your internet and try again!", Toast.LENGTH_SHORT).show();
        }


    }

Solution

  • It's because your else can't be reached

    String userLocation = mLatitude + ","
                + mLongitude ;
    
        if(userLocation!=null){
           ...
        }else{
           ...
        }
    

    userLocation will never be null