布局隐藏的时候抱空指针的错误
来源:互联网 发布:我的购物车淘宝网手机 编辑:程序博客网 时间:2024/05/02 15:07
错误是:
02-27 10:36:25.145: E/AndroidRuntime(17662): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.sims.android/com.sims.map.MapLocation}: java.lang.NullPointerException
执行到: rlayout_map_route.setVisibility(View.GONE);时报的错
我有初始化:rlayout_map_route=(RelativeLayout)findViewById(R.id.rlayout_map_route);
我把前面的代码贴出来:
/**
* 周边信息
*/
public class MapLocation extends Activity implements OnClickListener,
IConnectionStatusCallback, SmackImplListener {
/**
* MapView 是地图主控件
*/
private MapView mMapView;
private BaiduMap mBaiduMap;
/**
* 布局上的控件的定义
*/
private Spinner spinner;
private LinearLayout otherlinear;
// private LinearLayout routeSeachLayout;
// private RelativeLayout relativeLayout;
private Button btOther;
private Button btMode;
private Button btLocation;
private Button btsnapshot;
private Button btSendMessageAll;//群发
private Button btMapType;
// private Button btDrivingSeach;
// private Button btTransitSeach;
// private Button btWalkingSeach;
// private Button btCloseRouteLayout;
private Button btnAdd;
private Button btnSubtract;
// private TextView textDestination;
private TextView textDescription;
private TextView textLocationHere;
private TextView textGoThere;
private TextView textSendMessage;
private ListView listViewMessAge;
/**
* 新布局的定义
* @author zxf
* */
private RelativeLayout rlayout_map_route;
private RelativeLayout rlayout_map_list;
private TextView txt_from;
private TextView txt_to;
private RadioGroup bottomRg;
private RadioButton rbtn_bus;
private RadioButton rbtn_driving;
private RadioButton rbtn_walking;
//新的路径规划方法
private Route_new route_line = null;
//新的适配器
private MapRouteListAdapter adapter1;
// 弹出框
private LatLng locationAdress = null;
private int mode_tanKuang = 0;
private LinearLayout linearTouXiang = null;
// 路径信息适配器
//private MapListAdapter adapter;
// 定位相关
private LocationClient mLocClient = null;
public MyLocationListenner myListener = new MyLocationListenner();
private LocationMode mCurrentMode;
private BitmapDescriptor mCurrentMarker = null;
private final static int SCAN_TIME = 1000;
// 规划路径
//private Route drawRoute = null;
private int destination = -1;
/** 当前经纬度 **/
private int curRadius = -1;
boolean isFirstLoc = true;// 是否首次定位
boolean isRequest = false;// 是否请求定位
// 本人与好友的坐标
People personMe = new People();
private LatLng personMeLatLng;
private List<People> persons;
// 标注与坐标
private LatLng curLatlng = null;
private int curIndex = -1;
private LatLng leftTop = null;
private LatLng rightBottom = null;
private List<OverlayOptions> maze;
//导航多方案
private int type = 0;
private static int DRIVING=0; //自驾
private static int WALKING=0; //步行
private static int BUS=0; //公交
// 屏幕宽高
private int screenWidth;
private int screenHeight;
/**
* 距离数据
*/
private final static int[] disTance = { 0, 50, 100, 200, 500, 1000, 2000,
5000, 10000 };
// 初始化全局 bitmap 信息,不用时及时 recycle
private BitmapDescriptor bdA;
private BitmapDescriptor bd;
// 监听
private SDKReceiver mReceiver;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_map);
SmackImpl.AddListener(this);
init();
initWidget();
initRoute();
//初始化新的路径规划方法
route_line=new Route_new(MapLocation.this, mBaiduMap);
//drawRoute = new Route(MapLocation.this, mBaiduMap);
initSpinner();
initSetMapOnClickListener();
setMapLocation();
setMarkOnClickListner();
}
private void init() {
// 注册 SDK 广播监听者
IntentFilter iFilter = new IntentFilter();
iFilter.addAction(SDKInitializer.SDK_BROADTCAST_ACTION_STRING_PERMISSION_CHECK_ERROR);
iFilter.addAction(SDKInitializer.SDK_BROADCAST_ACTION_STRING_NETWORK_ERROR);
mReceiver = new SDKReceiver();
registerReceiver(mReceiver, iFilter);
persons = new ArrayList<People>();
bd = BitmapDescriptorFactory.fromResource(R.drawable.icon_gcoding);
bdA = BitmapDescriptorFactory
.fromResource(R.drawable.icon_map_cur_location);
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
screenHeight = dm.heightPixels;
screenWidth = dm.widthPixels;
}
// 初始化控件
private void initWidget() {
linearTouXiang = (LinearLayout) findViewById(R.id.linear_touxiang);
//新界面的初始化
rlayout_map_list=(RelativeLayout)findViewById(R.id.rlayout_map_list);
rlayout_map_route=(RelativeLayout)findViewById(R.id.rlayout_map_route);
// relativeLayout = (RelativeLayout) findViewById(R.id.relative_map);
//
// routeSeachLayout = (LinearLayout) findViewById(R.id.route_plan_map);
mMapView = (MapView) findViewById(R.id.bmapView);
spinner = (Spinner) findViewById(R.id.spinner);
btLocation = (Button) findViewById(R.id.location);
btMode = (Button) findViewById(R.id.mode);
btOther = (Button) findViewById(R.id.other);
btsnapshot = (Button) findViewById(R.id.snapshotpicture);
otherlinear = (LinearLayout) findViewById(R.id.otherlinear);
btSendMessageAll = (Button) findViewById(R.id.sendMessageAll);
btMapType = (Button) findViewById(R.id.maptype);
//出行方式的选择按钮的初始化
rbtn_bus=(RadioButton) findViewById(R.id.rbtn_bus);
rbtn_driving=(RadioButton) findViewById(R.id.rbtn_driving);
rbtn_walking=(RadioButton) findViewById(R.id.rbtn_walking);
btLocation = (Button) findViewById(R.id.location);
// btDrivingSeach = (Button) findViewById(R.id.search_driving_map);
// btTransitSeach = (Button) findViewById(R.id.search_trantirt_map);
// btWalkingSeach = (Button) findViewById(R.id.search_walking_map);
// btCloseRouteLayout = (Button) findViewById(R.id.close_route_message_map);
btnAdd = (Button) findViewById(R.id.map_add);
btnSubtract = (Button) findViewById(R.id.map_subtract);
listViewMessAge = (ListView) findViewById(R.id.list_route);
// textDestination = (TextView) findViewById(R.id.destinationtext_map);
textDescription = (TextView) findViewById(R.id.map_description);
textLocationHere = (TextView) findViewById(R.id.map_location_here);
textGoThere = (TextView) findViewById(R.id.map_go_here);
textSendMessage = (TextView) findViewById(R.id.map_send_loaction_message);
//新界面控件的初始化
txt_from=(TextView)findViewById(R.id.txt_from);
txt_to=(TextView)findViewById(R.id.txt_to);
// relativeLayout.setVisibility(View.GONE);
// routeSeachLayout.setVisibility(View.GONE);
//新界面隐藏//就是这里出的错
rlayout_map_route.setVisibility(View.GONE);
rlayout_map_list.setVisibility(View.GONE);
btSendMessageAll.setVisibility(View.GONE);
otherlinear.setVisibility(View.GONE);
textSendMessage.setOnClickListener(this);
textLocationHere.setOnClickListener(this);
textGoThere.setOnClickListener(this);
btOther.setOnClickListener(this);
btLocation.setOnClickListener(this);
btsnapshot.setOnClickListener(this);
btSendMessageAll.setOnClickListener(this);
btMapType.setOnClickListener(this);
// btWalkingSeach.setOnClickListener(this);
// btTransitSeach.setOnClickListener(this);
// btDrivingSeach.setOnClickListener(this);
// btCloseRouteLayout.setOnClickListener(this);
btnAdd.setOnClickListener(this);
btnSubtract.setOnClickListener(this);
mMapView.removeViewAt(2);
mCurrentMode = LocationMode.NORMAL;
mBaiduMap = mMapView.getMap();
MapStatusUpdate msu = MapStatusUpdateFactory.zoomTo(12.0f);
mBaiduMap.setMapStatus(msu);
}
02-27 10:36:25.145: E/AndroidRuntime(17662): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.sims.android/com.sims.map.MapLocation}: java.lang.NullPointerException
执行到: rlayout_map_route.setVisibility(View.GONE);时报的错
我有初始化:rlayout_map_route=(RelativeLayout)findViewById(R.id.rlayout_map_route);
我把前面的代码贴出来:
/**
* 周边信息
*/
public class MapLocation extends Activity implements OnClickListener,
IConnectionStatusCallback, SmackImplListener {
/**
* MapView 是地图主控件
*/
private MapView mMapView;
private BaiduMap mBaiduMap;
/**
* 布局上的控件的定义
*/
private Spinner spinner;
private LinearLayout otherlinear;
// private LinearLayout routeSeachLayout;
// private RelativeLayout relativeLayout;
private Button btOther;
private Button btMode;
private Button btLocation;
private Button btsnapshot;
private Button btSendMessageAll;//群发
private Button btMapType;
// private Button btDrivingSeach;
// private Button btTransitSeach;
// private Button btWalkingSeach;
// private Button btCloseRouteLayout;
private Button btnAdd;
private Button btnSubtract;
// private TextView textDestination;
private TextView textDescription;
private TextView textLocationHere;
private TextView textGoThere;
private TextView textSendMessage;
private ListView listViewMessAge;
/**
* 新布局的定义
* @author zxf
* */
private RelativeLayout rlayout_map_route;
private RelativeLayout rlayout_map_list;
private TextView txt_from;
private TextView txt_to;
private RadioGroup bottomRg;
private RadioButton rbtn_bus;
private RadioButton rbtn_driving;
private RadioButton rbtn_walking;
//新的路径规划方法
private Route_new route_line = null;
//新的适配器
private MapRouteListAdapter adapter1;
// 弹出框
private LatLng locationAdress = null;
private int mode_tanKuang = 0;
private LinearLayout linearTouXiang = null;
// 路径信息适配器
//private MapListAdapter adapter;
// 定位相关
private LocationClient mLocClient = null;
public MyLocationListenner myListener = new MyLocationListenner();
private LocationMode mCurrentMode;
private BitmapDescriptor mCurrentMarker = null;
private final static int SCAN_TIME = 1000;
// 规划路径
//private Route drawRoute = null;
private int destination = -1;
/** 当前经纬度 **/
private int curRadius = -1;
boolean isFirstLoc = true;// 是否首次定位
boolean isRequest = false;// 是否请求定位
// 本人与好友的坐标
People personMe = new People();
private LatLng personMeLatLng;
private List<People> persons;
// 标注与坐标
private LatLng curLatlng = null;
private int curIndex = -1;
private LatLng leftTop = null;
private LatLng rightBottom = null;
private List<OverlayOptions> maze;
//导航多方案
private int type = 0;
private static int DRIVING=0; //自驾
private static int WALKING=0; //步行
private static int BUS=0; //公交
// 屏幕宽高
private int screenWidth;
private int screenHeight;
/**
* 距离数据
*/
private final static int[] disTance = { 0, 50, 100, 200, 500, 1000, 2000,
5000, 10000 };
// 初始化全局 bitmap 信息,不用时及时 recycle
private BitmapDescriptor bdA;
private BitmapDescriptor bd;
// 监听
private SDKReceiver mReceiver;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_map);
SmackImpl.AddListener(this);
init();
initWidget();
initRoute();
//初始化新的路径规划方法
route_line=new Route_new(MapLocation.this, mBaiduMap);
//drawRoute = new Route(MapLocation.this, mBaiduMap);
initSpinner();
initSetMapOnClickListener();
setMapLocation();
setMarkOnClickListner();
}
private void init() {
// 注册 SDK 广播监听者
IntentFilter iFilter = new IntentFilter();
iFilter.addAction(SDKInitializer.SDK_BROADTCAST_ACTION_STRING_PERMISSION_CHECK_ERROR);
iFilter.addAction(SDKInitializer.SDK_BROADCAST_ACTION_STRING_NETWORK_ERROR);
mReceiver = new SDKReceiver();
registerReceiver(mReceiver, iFilter);
persons = new ArrayList<People>();
bd = BitmapDescriptorFactory.fromResource(R.drawable.icon_gcoding);
bdA = BitmapDescriptorFactory
.fromResource(R.drawable.icon_map_cur_location);
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
screenHeight = dm.heightPixels;
screenWidth = dm.widthPixels;
}
// 初始化控件
private void initWidget() {
linearTouXiang = (LinearLayout) findViewById(R.id.linear_touxiang);
//新界面的初始化
rlayout_map_list=(RelativeLayout)findViewById(R.id.rlayout_map_list);
rlayout_map_route=(RelativeLayout)findViewById(R.id.rlayout_map_route);
// relativeLayout = (RelativeLayout) findViewById(R.id.relative_map);
//
// routeSeachLayout = (LinearLayout) findViewById(R.id.route_plan_map);
mMapView = (MapView) findViewById(R.id.bmapView);
spinner = (Spinner) findViewById(R.id.spinner);
btLocation = (Button) findViewById(R.id.location);
btMode = (Button) findViewById(R.id.mode);
btOther = (Button) findViewById(R.id.other);
btsnapshot = (Button) findViewById(R.id.snapshotpicture);
otherlinear = (LinearLayout) findViewById(R.id.otherlinear);
btSendMessageAll = (Button) findViewById(R.id.sendMessageAll);
btMapType = (Button) findViewById(R.id.maptype);
//出行方式的选择按钮的初始化
rbtn_bus=(RadioButton) findViewById(R.id.rbtn_bus);
rbtn_driving=(RadioButton) findViewById(R.id.rbtn_driving);
rbtn_walking=(RadioButton) findViewById(R.id.rbtn_walking);
btLocation = (Button) findViewById(R.id.location);
// btDrivingSeach = (Button) findViewById(R.id.search_driving_map);
// btTransitSeach = (Button) findViewById(R.id.search_trantirt_map);
// btWalkingSeach = (Button) findViewById(R.id.search_walking_map);
// btCloseRouteLayout = (Button) findViewById(R.id.close_route_message_map);
btnAdd = (Button) findViewById(R.id.map_add);
btnSubtract = (Button) findViewById(R.id.map_subtract);
listViewMessAge = (ListView) findViewById(R.id.list_route);
// textDestination = (TextView) findViewById(R.id.destinationtext_map);
textDescription = (TextView) findViewById(R.id.map_description);
textLocationHere = (TextView) findViewById(R.id.map_location_here);
textGoThere = (TextView) findViewById(R.id.map_go_here);
textSendMessage = (TextView) findViewById(R.id.map_send_loaction_message);
//新界面控件的初始化
txt_from=(TextView)findViewById(R.id.txt_from);
txt_to=(TextView)findViewById(R.id.txt_to);
// relativeLayout.setVisibility(View.GONE);
// routeSeachLayout.setVisibility(View.GONE);
//新界面隐藏//就是这里出的错
rlayout_map_route.setVisibility(View.GONE);
rlayout_map_list.setVisibility(View.GONE);
btSendMessageAll.setVisibility(View.GONE);
otherlinear.setVisibility(View.GONE);
textSendMessage.setOnClickListener(this);
textLocationHere.setOnClickListener(this);
textGoThere.setOnClickListener(this);
btOther.setOnClickListener(this);
btLocation.setOnClickListener(this);
btsnapshot.setOnClickListener(this);
btSendMessageAll.setOnClickListener(this);
btMapType.setOnClickListener(this);
// btWalkingSeach.setOnClickListener(this);
// btTransitSeach.setOnClickListener(this);
// btDrivingSeach.setOnClickListener(this);
// btCloseRouteLayout.setOnClickListener(this);
btnAdd.setOnClickListener(this);
btnSubtract.setOnClickListener(this);
mMapView.removeViewAt(2);
mCurrentMode = LocationMode.NORMAL;
mBaiduMap = mMapView.getMap();
MapStatusUpdate msu = MapStatusUpdateFactory.zoomTo(12.0f);
mBaiduMap.setMapStatus(msu);
}
0 0
- 布局隐藏的时候抱空指针的错误
- 安装Guvnor的时候出现500报空指针错误
- Intent获取值的时候空指针错误
- 隐藏极深的空指针-
- 布局时候出现的一个小错误
- 用List的时候遇到的一个空指针异常
- 复合主键导致的空指针错误
- 复合主键导致的空指针错误
- 一个教科书一般的“空指针”错误
- 空指针nullpointer的错误感悟
- Service的onStartCommand方法空指针错误
- Intent传值时的一个空指针错误
- 解决spring task在调用controller时,当controller访问service时候空指针错误的问题
- 再使用java list的时候出现空指针异常
- android 用gson解析json的时候报空指针
- 整合ssh的时候出现空指针java.lang.NullPointerException
- JdbcTemplate自动注入的时候出现空指针异常
- setAdapter的时候,总是报错 空指针异常
- [转]截图原理(一)——Android自动化测试学习历程(1)
- Jquery过滤器的基本使用案例
- H5学习笔记之Transform
- Android Studio 2.0 真机调试 安装不了安装包
- 谁能提供一下Android4.1.2系统的签名工具
- 布局隐藏的时候抱空指针的错误
- asp链接mysql数据库
- OnItemClickListener()
- 我的2016——程序员年到三十,工作第四年
- SpringBoot 整合Mail发送功能问题与解决
- HTML入门学习笔记--CSS选择器(3)
- 浅谈关于SRAM与DRAM的区别
- hello2017
- H5学习笔记之CSS3 animation