手机上运行酷欧天气,显示加载失败?

大树学长 2016-07-27 05:02:22

手机是华为,安卓系统4.4.2,
代码是网上下载的,弄的几个都是一样问题,这完整版的都有问题,我还学什么鬼

@Override
public void onError(Exception e)
{
// 通过runOnUiThread()方法回到主线程处理逻辑
runOnUiThread(new Runnable()
{
@Override
public void run()
{
closeProgressDialog();
Toast.makeText(ChooseAreaActivity.this, "加载失败",Toast.LENGTH_SHORT).show();
}
});
}
...全文
633 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
饿了也要前行 2019-12-16
  • 打赏
  • 举报
回复
引用 12 楼 Liangyl8818 的回复:
我遇到了相同的问题,用手机运行进入APP就显示加载失败,但是用模拟器就没问题。 百度找了有一会,没有相关的解决问题。后来我想了一下,手机版本Android 9.0 模拟器andoird 5.0 有关于okHttp的参数设置不一样。 参考我写的问题二!!! 解决方法。 https://github.com/MomentOfTime/coolweather.git
非常非常感谢您酷欧天气的回答,解决了我一天的疑问,一定要表示深深的感谢!!
Liangyl8818 2019-11-06
  • 打赏
  • 举报
回复
我遇到了相同的问题,用手机运行进入APP就显示加载失败,但是用模拟器就没问题。 百度找了有一会,没有相关的解决问题。后来我想了一下,手机版本Android 9.0 模拟器andoird 5.0 有关于okHttp的参数设置不一样。 参考我写的问题二!!! 解决方法。 https://github.com/MomentOfTime/coolweather.git
nknk233 2018-12-11
  • 打赏
  • 举报
回复
引用 9 楼 edcSam 的回复:
我也遇到类似的问题。但是我的是运行程序能够读取省份列表,然后点击listview的子项显示加载失败,请问你知道是什么原因吗?
wo

引用 9 楼 edcSam 的回复:
我也遇到类似的问题。但是我的是运行程序能够读取省份列表,然后点击listview的子项显示加载失败,请问你知道是什么原因吗?

我也是,市级数据加载失败

蒙奇_爱可乐 2016-10-12
  • 打赏
  • 举报
回复
你也是天真 13年的书 天气接口早过期了 自己去网上找新的接口替换
edcSam 2016-08-17
  • 打赏
  • 举报
回复
我也遇到类似的问题。但是我的是运行程序能够读取省份列表,然后点击listview的子项显示加载失败,请问你知道是什么原因吗?
大树学长 2016-07-30
  • 打赏
  • 举报
回复
问题已解决,不懂看博客
SDYYY_FAN 2016-07-30
  • 打赏
  • 举报
回复
引用 7 楼 bigtree_mfc 的回复:
问题已解决,不懂看博客
原来是没连网。。。
SDYYY_FAN 2016-07-28
  • 打赏
  • 举报
回复
我的可以正常运行,楼主是不是代码下得不全,我把我的发给你,留邮箱
大树学长 2016-07-28
  • 打赏
  • 举报
回复
引用 1 楼 helloguoqijun 的回复:
为什么不贴出log
缺少libmaliinstr.so包
大树学长 2016-07-28
  • 打赏
  • 举报
回复
大树学长 2016-07-28
  • 打赏
  • 举报
回复

package activity;

import java.util.ArrayList;
import java.util.List;

import model.City;
import model.County;
import model.Province;
import util.HttpCallbackListener;
import util.HttpUtil;
import util.Utility;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
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 com.example.coolweather.R;

import db.CoolWeatherDB;

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;
	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;
	// 是否从WeatherActivity中跳转过来。
	private boolean isFromWeatherActivity;

	@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)) {
			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);
		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);
					queryCities();
				} else if (currentLevel == LEVEL_CITY) {
					selectedCity = cityList.get(index);
					queryCounties();
				} else if (currentLevel == LEVEL_COUNTY) {
					String countyCode = countyList.get(index).getCountyCode();
					Intent intent = new Intent(ChooseAreaActivity.this,
					WeatherActivity.class);
					intent.putExtra("county_code", countyCode);
					startActivity(intent);
					finish();
				}
			}
		});
		queryProvinces(); // 加载省级数据
	}

	/**
	 * 查询全国所有的省,优先从数据库查询,如果没有查询到再去服务器上查询。
	 */
	private void queryProvinces() {
		provinceList = coolWeatherDB.loadProvinces();
		if (provinceList.size() > 0) {
			dataList.clear();
			for (Province province : provinceList) {
				dataList.add(province.getProvinceName());
			}
			adapter.notifyDataSetChanged();
			listView.setSelection(0);
			titleText.setText("中国");
			currentLevel = LEVEL_PROVINCE;
		} else {
			queryFromServer(null, "province");
		}
	}

	/**
	 * 查询选中省内所有的市,优先从数据库查询,如果没有查询到再去服务器上查询。
	 */
	private void queryCities() {
		cityList = coolWeatherDB.loadCities(selectedProvince.getId());
		if (cityList.size() > 0) {
			dataList.clear();
			for (City city : cityList) {
				dataList.add(city.getCityName());
			}
			adapter.notifyDataSetChanged();
			listView.setSelection(0);
			titleText.setText(selectedProvince.getProvinceName());
			currentLevel = LEVEL_CITY;
		} else {
			queryFromServer(selectedProvince.getProvinceCode(), "city");
		}
	}

	/**
	 * 查询选中市内所有的县,优先从数据库查询,如果没有查询到再去服务器上查询。
	 */
	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 queryFromServer(final String code, final String type) {
		String address;
		if (!TextUtils.isEmpty(code)) {
			address = "http://www.weather.com.cn/data/list3/city" + code + ".xml";
		} else {
			address = "http://www.weather.com.cn/data/list3/city.xml";
			//http://www.weather.com.cn/weather1d/101190401.shtml#search 苏州
			//http://www.weather.com.cn/weather1d/101220101.shtml#search 合肥
		}
		showProgressDialog();
		HttpUtil.sendHttpRequest(address, new HttpCallbackListener() {
			@Override
			public void onFinish(String response) {
				boolean result = false;
				if ("province".equals(type)) {
					result = Utility.handleProvincesResponse(coolWeatherDB,
							response);
				} else if ("city".equals(type)) {
					result = Utility.handleCitiesResponse(coolWeatherDB,
							response, selectedProvince.getId());
				} else if ("county".equals(type)) {
					result = Utility.handleCountiesResponse(coolWeatherDB,
							response, selectedCity.getId());
				}
				if (result) {
					// 通过runOnUiThread()方法回到主线程处理逻辑
					runOnUiThread(new Runnable() {
						@Override
						public void run() {
							closeProgressDialog();
							if ("province".equals(type)) {
								queryProvinces();
							} else if ("city".equals(type)) {
								queryCities();
							} else if ("county".equals(type)) {
								queryCounties();
							}
						}
					});
				}
			}

			@Override
			public void onError(Exception e) 
			{
				// 通过runOnUiThread()方法回到主线程处理逻辑
				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();
		}
	}

	/**
	 * 捕获Back按键,根据当前的级别来判断,此时应该返回市列表、省列表、还是直接退出。
	 */
	@Override
	public void onBackPressed() {
		if (currentLevel == LEVEL_COUNTY) {
			queryCities();
		} else if (currentLevel == LEVEL_CITY) {
			queryProvinces();
		} else {
			if (isFromWeatherActivity) {
				Intent intent = new Intent(this, WeatherActivity.class);
				startActivity(intent);
			}
			finish();
		}
	}
}
大树学长 2016-07-28
  • 打赏
  • 举报
回复
引用 5 楼 SDYYY_FAN 的回复:
我的可以正常运行,楼主是不是代码下得不全,我把我的发给你,留邮箱
我网上下载的,下载过几分都是一样,我照书上写的也是一样的问题,还是libmaliinstr.so没有 could not disable core file generation for pid 7713: Operation not permitted Failed sending reply to debugger: Broken pipe Debugger has detached; object registry had 1 entries : success to get AllImpl object and return.... : successes to get AllImpl object and return.... HwSensorManager version: 1.0.0 library "libmaliinstr.so" not found error: Enabling debug mode 0
放狼的爷们 2016-07-27
  • 打赏
  • 举报
回复
为什么不贴出log

80,351

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧