Usm*_*han -1 eclipse android dead-code
我正在研究android应用程序,其中我使用逻辑从协调中找到一个人的方向.一切正常,但我在控制台出错:"死码".我的代码如下,请解释一下这个问题.
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();
}
}
Run Code Online (Sandbox Code Playgroud)
这是因为你的其他人无法联系到
String userLocation = mLatitude + ","
+ mLongitude ;
if(userLocation!=null){
...
}else{
...
}
Run Code Online (Sandbox Code Playgroud)
userLocation永远不会为null