private void queryCounties() {
   countyList = coolWeatherDB.loadCounties(selectedCity.getId());
   if (countyList.size() > 0) {
     dataList.clear();
     for (County county : countyList) {
       dataList.add(county.getCountyName());
     }
     adapter.notifyDataSetChanged();
     listView.setSelection(0);
     titleText.setText(selectedCity.getCityName());
     currentLevel = LEVEL_COUNTY;
   } else {
     queryFromServer(selectedCity.getCityCode(), "county");
   }
 }
 private void queryProvinces() {
   Log.d("mainaicityt", "hello444");
   provinceList = coolWeatherDB.loadProvinces(); // 空指针异常,注意看逻辑
   if (provinceList.size() > 0) {
     dataList.clear();
     for (Province province : provinceList) {
       dataList.add(province.getProvinceName());
     }
     dataList.add("");
     adapter.notifyDataSetChanged();
     listView.setSelection(0);
     titleText.setText("中国");
     currentLevel = LEVEL_PROVINCE;
   } else {
     queryFromServer(null, "province");
   }
 }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    isFromWeatherActivity = getIntent().getBooleanExtra("from_weather_activity", false);
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    if (prefs.getBoolean("city_selected", false) && !isFromWeatherActivity) {
      Intent intent = new Intent(this, WeatherActivity.class);
      startActivity(intent);
      finish();
      return;
    }

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.choose_area);
    listView = (ListView) findViewById(R.id.list_view);
    titleText = (TextView) findViewById(R.id.title_text);
    adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, dataList);
    listView.setAdapter(adapter);
    Log.d("mainaicityt", "hello111");
    coolWeatherDB = CoolWeatherDB.getInstance(this);
    Log.d("mainaicityt", "hello");
    listView.setOnItemClickListener(
        new OnItemClickListener() {

          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (currentLevel == LEVEL_PROVINCE) {
              selectedProvince = provinceList.get(position);
              queryCities();
            } else if (currentLevel == LEVEL_CITY) {
              selectedCity = cityList.get(position);
              queryCounties();
            } else if (currentLevel == LEVEL_COUNTY) {
              String countyCode = countyList.get(position).getCountyCode();
              Intent intent = new Intent(ChooseAreaActivity.this, WeatherActivity.class);
              intent.putExtra("county_code", countyCode);
              startActivity(intent);
              finish();
            }
          }
        });
    Log.d("mainaicityt", "hello33");
    queryProvinces();
  }