布局隐藏的时候抱空指针的错误

来源:互联网 发布:我的购物车淘宝网手机 编辑:程序博客网 时间: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);

}
0 0
原创粉丝点击