在locationChanged上显示或隐藏图像按钮

时间:2014-03-12 07:38:13

标签: android image camera

如何显示/隐藏图像按钮?如果我使用imagebutton.setVisiblity(View.GONE),应用程序崩溃。为什么呢?

这是我的代码:

 if(acc > 0  && acc < 15){
  b.setVisibility(View.VISIBLE);
  d.setVisibility(View.GONE);

 }else if(acc > 15){
  b.setVisibility(View.GONE);
  d.setVisibility(View.VISIBLE);

}else{
  b.setVisibility(View.GONE);
  d.setVisibility(View.VISIBLE);
}

logcat的:

03-12 03:10:46.204: E/AndroidRuntime(1734): java.lang.NullPointerException
03-12 03:10:46.204: E/AndroidRuntime(1734):     at com.joules.prdpcamera.MainActivity$myLocationListener.onLocationChanged(MainActivity.java:231)
03-12 03:10:46.204: E/AndroidRuntime(1734):     at android.location.LocationManager$ListenerTransport._handleMessage(LocationManager.java:279)
03-12 03:10:46.204: E/AndroidRuntime(1734):     at android.location.LocationManager$ListenerTransport.access$000(LocationManager.java:208)
03-12 03:10:46.204: E/AndroidRuntime(1734):     at android.location.LocationManager$ListenerTransport$1.handleMessage(LocationManager.java:224)
03-12 03:10:46.204: E/AndroidRuntime(1734):     at android.os.Handler.dispatchMessage(Handler.java:102)
03-12 03:10:46.204: E/AndroidRuntime(1734):     at android.os.Looper.loop(Looper.java:136)
03-12 03:10:46.204: E/AndroidRuntime(1734):     at android.app.ActivityThread.main(ActivityThread.java:5017)
03-12 03:10:46.204: E/AndroidRuntime(1734):     at java.lang.reflect.Method.invokeNative(Native Method)
03-12 03:10:46.204: E/AndroidRuntime(1734):     at java.lang.reflect.Method.invoke(Method.java:515)
03-12 03:10:46.204: E/AndroidRuntime(1734):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
03-12 03:10:46.204: E/AndroidRuntime(1734):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
03-12 03:10:46.204: E/AndroidRuntime(1734):     at dalvik.system.NativeStart.main(Native Method)

这是整个locationListener代码:位置mananger

@Override
public void onLocationChanged(Location location) {
f(location !=null){

double clat=location.getLatitude();
double clng=location.getLongitude();

DecimalFormat df = new DecimalFormat("###.######");
 vlatitude = df.format(clat);
vlongitude = df.format(clng);

int num1Lat = (int)Math.floor(clat);
int num2Lat = (int)Math.floor((clat - num1Lat) * 60);
double num3Lat = (clat - ((double)num1Lat+((double)num2Lat/60))) * 3600000;

int num1Lon = (int)Math.floor(clng);
int num2Lon = (int)Math.floor((clng - num1Lon) * 60);
double num3Lon = (clng - ((double)num1Lon+((double)num2Lon/60))) * 3600000;

flat = num1Lat+"/1,"+num2Lat+"/1,"+num3Lat+"/1000";
flong = num1Lon+"/1,"+num2Lon+"/1,"+num3Lon+"/1000";

if (clat > 0) {
latref = "N"; 
} else {
latref = "S";
}

if (clng> 0) {
longref = "E";    
} else {
longref = "W";
}
float f = location.getAccuracy();

int acc = Math.round(Float.valueOf(f));

if (acc !=0){
if(acc > 0  && acc < 15){
b.setVisibility(android.view.View.GONE);
d.setVisibility(android.view.View.VISIBLE);

}else if(acc > 15){
b.setVisibility(android.view.View.VISIBLE);
d.setVisibility(android.view.View.GONE);
}

}

}

}

0 个答案:

没有答案