2 m0 37686614 m0_37686614 于 2017.08.29 16:30 提问

java.lang.NoClassDefFoundError问大神 ,点击省列表后直接程序崩溃 10C

图片说明图片说明
package com.coolweather.app.activity;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import com.coolweather.app.R;
import com.coolweather.app.WeatherActivity;
import com.coolweather.app.db.CoolWeatherDB;
import com.coolweather.app.model.City;
import com.coolweather.app.model.County;
import com.coolweather.app.model.Province;
import com.coolweather.app.util.HttpCallbackListener;
import com.coolweather.app.util.HttpUtil;
import com.coolweather.app.util.Utility;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Response;
public class ChooseAreaActivity extends Activity{
public static final int LEVEL_PROVINCE=0;
public static final int LEVEL_CITY=1;
public static final int LEVEL_COUNTY=2;

    @SuppressWarnings("deprecation")
    private ProgressDialog progressDialog;
    private TextView titleText;
    private ListView listView;
    private ArrayAdapter<String > adapter;
    private CoolWeatherDB coolWeatherDB;
    private List<String> dataList=new ArrayList<String>();
    private List<Province> provinceList;
    private List<City> cityList;
    private List<County> countyList;
    private Province selectedProvince;
    private City selectedCity;
    private int currentLevel;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
        setContentView(R.layout.choose_area);
        titleText=(TextView)findViewById(R.id.title_text);
        listView=(ListView)findViewById(R.id.list_view);
        adapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,dataList);
        listView.setAdapter(adapter);
        coolWeatherDB=CoolWeatherDB.getInstance(this);
        listView.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?>arg0,View view, int index,long arg3) {
                if(currentLevel==LEVEL_PROVINCE) {
                    selectedProvince=provinceList.get(index);
                    queryCity();
                }else if(currentLevel==LEVEL_CITY) {
                    selectedCity=cityList.get(index);
                    queryCounty();
                }else if(currentLevel==LEVEL_COUNTY) {
                    String weatherId=countyList.get(index).getWeatherId();
                    Intent intent=new Intent(ChooseAreaActivity.this,WeatherActivity.class);
                    intent.putExtra("weather_id",weatherId);
                    startActivity(intent);
                    finish();

                }
            }               
        });
        queryProvince();
    }
    private void queryProvince() {
        titleText.setText("中国");
        provinceList=coolWeatherDB.loadProvinces();
        if(provinceList.size()>0) {
            dataList.clear();
            for(Province province:provinceList) {
                dataList.add(province.getProvinceName());

            }
            adapter.notifyDataSetChanged();
            listView.setSelection(0);

            currentLevel=LEVEL_PROVINCE;

        }else {
            String address="http://guolin.tech/api/china/";
            queryFromServer(address,"province");
        }
    }


        private void queryCity() {
            titleText.setText(selectedProvince.getProvinceName());
            cityList=coolWeatherDB.loadCities(selectedProvince.getId());
            if(cityList.size()>0) {
                dataList.clear();
                for(City city:cityList) {
                    dataList.add(city.getCityName());

                }
                adapter.notifyDataSetChanged();
                listView.setSelection(0);

                currentLevel=LEVEL_CITY;
            }else {
                int provinceCode=selectedProvince.getProvinceCode();
                String address="http://guolin.tech/api/china/"+provinceCode;
                queryFromServer(address,"city");
            }
        }
        private void queryCounty() {
            titleText.setText(selectedCity.getCityName());
            countyList=coolWeatherDB.loadCounties(selectedCity.getId());
            if(countyList.size()>0) {
                dataList.clear();
                for(County county:countyList) {
                    dataList.add(county.getCountyName());
                }
                adapter.notifyDataSetChanged();
                listView.setSelection(0);

                currentLevel=LEVEL_COUNTY;

            }else {
                int provinceCode=selectedProvince.getProvinceCode();
                int cityCode=selectedCity.getCityCode();
                String address="http://guolin.tech/api/china/"+provinceCode+"/"+cityCode;
                queryFromServer(address,"county");
            }
        }


    private void queryFromServer(String address,final String type) {

        showProgressDialog();
    HttpUtil.sendOkHttpRequest(address, new Callback() {

            @Override
            public void onResponse(Call call,Response response) throws IOException{
                String responseText=response.body().string();
                boolean result=false;
                if("province".equals(type)) {
                    result=Utility.handleProvinceResponse(responseText);

                }else if("city".equals(type)) {
                    result=Utility.handleCityResponse(responseText,selectedProvince.getId());
                }else if("county".equals(type)) {
                    result=Utility.handleCountyResponse(responseText, selectedCity.getId());
                }
                if(result) {
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            closeProgressDialog();
                            if("province".equals(type)) {
                                queryProvince();
                            }else if("city".equals(type)) {
                                queryCity();
                            }else if("county".equals(type)) {
                                queryCounty();
                            }
                        }
                    });
                }
            }
            @Override
            public void onFailure(Call call,IOException e) {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        closeProgressDialog();
                        Toast.makeText(ChooseAreaActivity.this,"加载失败",Toast.LENGTH_SHORT).show();
                    }
                });
            }
        });
    }

    private void showProgressDialog() {
        if(progressDialog==null) {
            progressDialog=new ProgressDialog(this);
            progressDialog.setMessage("正在加载");
            progressDialog.setCanceledOnTouchOutside(false);

        }
        progressDialog.show();
    }
    private void closeProgressDialog() {
    if(progressDialog!=null) {
        progressDialog.dismiss();
    }
    }
    @Override
    public void onBackPressed() {
        if(currentLevel==LEVEL_COUNTY) {
            queryCity();
        }else if(currentLevel==LEVEL_CITY) {
            queryProvince();
        }else {
            finish();
        }
    }

}

7个回答

qq_23292875
qq_23292875   2017.08.29 16:34

去看看他提示你这个类是不是编译成功了 多重新编译几次

baidu_26611019
baidu_26611019   2017.08.29 17:00

从报错来看大意是:找不到ChooseAreaActivity这个Activity,可能的原因:Activity没有在AndroidManifest.xml里面注册

m0_37686614
m0_37686614 注册了
3 个月之前 回复
anyanyan07
anyanyan07   2017.08.29 18:10

clean project一下,再运行试试

baidu_26611019
baidu_26611019   2017.08.29 18:13

clean一下,仔细检查你的AndroidManifest.xml文件,如果还是不行可以将gen目录删掉,再clean

Small_Mouse0
Small_Mouse0   Ds   Rxr 2017.08.29 18:40

感觉你注册的有问题吧,,你去AndroidMainfest.xml文件中,,按住ctrl,,看能不能访问到你的activity,,

报错为啥多了个“$2”符号
图片说明

huangjingfeng2016
huangjingfeng2016   2017.10.16 23:58

把你贴的代码放到IDE,行数对不上,打个断点看下queryFromServer方法的异步执行到哪

qq_24938003
qq_24938003   2017.10.19 14:35

HttpUtil.sendOkHttpRequest(address, new Callback() {是不是这个地方Callback的问题,Callback的包导对了吗?

Csdn user default icon
上传中...
上传图片
插入图片