程序无法访问,一直有错。
package com.fjq.android_async_http_demo;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.Toast;
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.BinaryHttpResponseHandler;
import com.loopj.android.http.TextHttpResponseHandler;
import org.apache.http.Header;
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
public static final String TAG = "MainActivity";
private ImageView imgView;
private WebView webView;
//图片地址
final String imgUrl = "http://img1.imgtn.bdimg.com/it/u=4208467321,1884355786&fm=21&gp=0.jpg";
//网页地址
final String webUrl = "http://blog.csdn.net/wangwei_cq/article/details/9453345";
private static AsyncHttpClient client=new AsyncHttpClient();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById();
Init();
setListener();
}
/*界面的初始化工作*/
private void Init() {
}
/*为控件设置事件监听*/
private void setListener() {
findViewById(R.id.img_btn).setOnClickListener(this);
findViewById(R.id.web_btn).setOnClickListener(this);
}
/*实例化布局文件的控件*/
private void findViewById() {
imgView = (ImageView) findViewById(R.id.img_view);
webView = (WebView) findViewById(R.id.web_view);
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.img_btn:
//点击获取图片资源
imgView.setVisibility(View.VISIBLE);
webView.setVisibility(View.GONE);
haveImg(imgUrl);
break;
case R.id.web_btn:
//点击获取网页资源
imgView.setVisibility(View.GONE);
webView.setVisibility(View.VISIBLE);
haveWeb(webUrl);
break;
}
}
private void haveWeb(final String webUrl){
client.get(webUrl, new TextHttpResponseHandler() {
@Override
public void onFailure(int i, Header[] headers, String s, Throwable throwable) {
Log.d(TAG,throwable+"");
Toast.makeText(MainActivity.this,"对不起 读取失败 状态码为"+i,Toast.LENGTH_LONG).show();
}
@Override
public void onSuccess(int i, Header[] headers, String s) {
webView.getSettings().setJavaScriptEnabled(true);//是否动态加载js
webView.getSettings().setDefaultTextEncodingName("UTF-8");//设置编码
//使网页自适应
webView.getSettings().setUseWideViewPort(true);
webView.getSettings().setLoadWithOverviewMode(true);
webView.loadData(s,"text/html;charset=UTF-8",null);
}
});
}
private void haveImg(String imgUrl){
client.get(imgUrl, new BinaryHttpResponseHandler() {
@Override
public void onSuccess(int i, Header[] headers, byte[] bytes) {
//解析图片
Bitmap b = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
imgView.setImageBitmap(b);
}
@Override
public void onFailure(int i, Header[] headers, byte[] bytes, Throwable throwable) {
Log.d(TAG,throwable+"");
Toast.makeText(MainActivity.this,"对不起 读取失败 状态码为"+i,Toast.LENGTH_LONG).show();
}
});
}
}
03-22 07:12:57.175 2090-2126/? W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xdad1e8a0, error=EGL_SUCCESS
03-22 07:13:00.636 2090-2126/? E/Surface: getSlotFromBufferLocked: unknown buffer: 0xeb1256b0
03-22 07:13:03.959 2155-2155/? D/AndroidRuntime: >>>>>> START com.android.internal.os.RuntimeInit uid 0 <<<<<<
03-22 07:13:03.960 2155-2155/? D/AndroidRuntime: CheckJNI is OFF
03-22 07:13:03.977 2155-2155/? D/ICU: No timezone override file found: /data/misc/zoneinfo/current/icu/icu_tzdata.dat
03-22 07:13:03.991 2155-2155/? E/memtrack: Couldn't load memtrack module (No such file or directory)
03-22 07:13:03.991 2155-2155/? E/android.os.Debug: failed to load memtrack module: -2
03-22 07:13:03.994 2155-2155/? I/Radio-JNI: register_android_hardware_Radio DONE
03-22 07:13:04.002 2155-2155/? D/AndroidRuntime: Calling main entry com.android.commands.am.Am
03-22 07:13:04.006 676-1639/? I/ActivityManager: Force stopping com.fjq.android_async_http_demo appid=10067 user=0: from pid 2155
03-22 07:13:04.006 676-1639/? I/ActivityManager: Killing 2090:com.fjq.android_async_http_demo/u0a67 (adj 0): stop com.fjq.android_async_http_demo
03-22 07:13:04.013 676-720/? W/InputDispatcher: channel '8ef4e92 com.fjq.android_async_http_demo/com.fjq.android_async_http_demo.MainActivity (server)' ~ Consumer closed input channel or an error occurred. events=0x9
03-22 07:13:04.013 676-720/? E/InputDispatcher: channel '8ef4e92 com.fjq.android_async_http_demo/com.fjq.android_async_http_demo.MainActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
03-22 07:13:04.013 676-1052/? D/GraphicsStats: Buffer count: 3
03-22 07:13:04.013 676-1052/? I/WindowState: WIN DEATH: Window{8ef4e92 u0 com.fjq.android_async_http_demo/com.fjq.android_async_http_demo.MainActivity}
03-22 07:13:04.013 676-1052/? W/InputDispatcher: Attempted to unregister already unregistered input channel '8ef4e92 com.fjq.android_async_http_demo/com.fjq.android_async_http_demo.MainActivity (server)'
03-22 07:13:04.047 676-1639/? W/ActivityManager: Force removing ActivityRecord{42585df u0 com.fjq.android_async_http_demo/.MainActivity t275}: app died, no saved state
03-22 07:13:04.079 2155-2155/? D/AndroidRuntime: Shutting down VM
03-22 07:13:04.117 676-1331/? W/ActivityManager: Spurious death for ProcessRecord{7ed0ecb 0:com.fjq.android_async_http_demo/u0a67}, curProc for 2090: null
03-22 07:13:04.293 1763-1776/? W/EGL_emulation: eglSurfaceAttrib not implemented
03-22 07:13:04.293 1763-1776/? W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xeeb53500, error=EGL_SUCCESS
03-22 07:13:04.433 676-809/? W/InputMethodManagerService: Got RemoteException sending setActive(false) notification to pid 2090 uid 10067
03-22 07:13:04.760 2164-2164/? D/AndroidRuntime: >>>>>> START com.android.internal.os.RuntimeInit uid 0 <<<<<<
03-22 07:13:04.761 2164-2164/? D/AndroidRuntime: CheckJNI is OFF
03-22 07:13:04.765 2168-2168/? D/AndroidRuntime: >>>>>> START com.android.internal.os.RuntimeInit uid 0 <<<<<<
03-22 07:13:04.768 2168-2168/? D/AndroidRuntime: CheckJNI is OFF
03-22 07:13:04.789 2164-2164/? D/ICU: No timezone override file found: /data/misc/zoneinfo/current/icu/icu_tzdata.dat
03-22 07:13:04.803 2168-2168/? D/ICU: No timezone override file found: /data/misc/zoneinfo/current/icu/icu_tzdata.dat
03-22 07:13:04.820 2164-2164/? E/memtrack: Couldn't load memtrack module (No such file or directory)
03-22 07:13:04.820 2164-2164/? E/android.os.Debug: failed to load memtrack module: -2
03-22 07:13:04.821 2164-2164/? I/Radio-JNI: register_android_hardware_Radio DONE
03-22 07:13:04.829 2168-2168/? E/memtrack: Couldn't load memtrack module (No such file or directory)
03-22 07:13:04.829 2168-2168/? E/android.os.Debug: failed to load memtrack module: -2
03-22 07:13:04.831 2164-2164/? D/AndroidRuntime: Calling main entry com.android.commands.wm.Wm
03-22 07:13:04.831 2168-2168/? I/Radio-JNI: register_android_hardware_Radio DONE
03-22 07:13:04.832 2164-2164/? D/AndroidRuntime: Shutting down VM
03-22 07:13:04.845 2168-2168/? D/AndroidRuntime: Calling main entry com.android.commands.am.Am
03-22 07:13:04.850 676-1331/? I/ActivityManager: START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.fjq.android_async_http_demo/.MainActivity} from uid 0 on display 0
03-22 07:13:04.901 661-661/? E/EGL_emulation: tid 661: eglCreateSyncKHR(1215): error 0x3004 (EGL_BAD_ATTRIBUTE)
03-22 07:13:05.014 676-695/? W/art: Long monitor contention event with owner method=android.graphics.Bitmap com.android.server.wm.WindowManagerService.screenshotApplicationsInner(android.os.IBinder, int, int, int, boolean) from WindowManagerService.java:6223 waiters=0 for 161ms
03-22 07:13:05.026 2168-2168/? D/AndroidRuntime: Shutting down VM
03-22 07:13:05.035 2184-2184/? I/art: Late-enabling -Xcheck:jni
03-22 07:13:05.049 676-1150/? I/ActivityManager: Start proc 2184:com.fjq.android_async_http_demo/u0a67 for activity com.fjq.android_async_http_demo/.MainActivity
03-22 07:13:05.124 2184-2184/? W/System: ClassLoader referenced unknown path: /data/app/com.fjq.android_async_http_demo-2/lib/x86
03-22 07:13:05.141 1763-1776/? E/Surface: getSlotFromBufferLocked: unknown buffer: 0xe00c7310
03-22 07:13:05.184 2184-2184/? V/WebViewFactory: webViewPackageName: com.android.webview
03-22 07:13:05.185 2184-2184/? I/WebViewFactory: Loading com.android.webview version 40 (1808730-x86) (code 400007)
03-22 07:13:05.187 2184-2184/? E/webviewchromiumloader: Failed to open relro file /data/misc/shared_relro/libwebviewchromium32.relro: No such file or directory
03-22 07:13:05.187 2184-2184/? W/WebViewFactory: failed to load with relro file, proceeding without
03-22 07:13:05.196 2184-2184/? W/System: ClassLoader referenced unknown path: /system/app/webview/lib/x86
03-22 07:13:05.211 2184-2184/? I/LibraryLoader: Time to load native libraries: 13 ms (timestamps 1198-1211)
03-22 07:13:05.213 2184-2184/? I/LibraryLoader: Expected native library version number "",actual native library version number ""
03-22 07:13:05.235 2184-2184/? I/WebView: com.android.webview versionName=40 (1808730-x86) versionCode=400007 sRenderingMethod=HARDWARE
03-22 07:13:05.235 2184-2184/? V/WebViewChromiumFactoryProvider: Binding Chromium to main looper Looper (main, tid 1) {70807a5}
03-22 07:13:05.235 2184-2184/? I/LibraryLoader: Expected native library version number "",actual native library version number ""
03-22 07:13:05.235 2184-2184/? I/chromium: [INFO:library_loader_hooks.cc(108)] Chromium logging enabled: level = 0, default verbosity = 0
03-22 07:13:05.239 2184-2184/? I/BrowserStartupController: Initializing chromium process, singleProcess=true
03-22 07:13:05.239 2184-2184/? W/art: Attempt to remove non-JNI local reference, dumping thread
03-22 07:13:05.245 2184-2200/? W/chromium: [WARNING:dns_config_service_posix.cc(293)] Failed to read DnsConfig.
03-22 07:13:05.270 2184-2204/? W/AudioManagerAndroid: Requires BLUETOOTH permission
03-22 07:13:05.285 2184-2184/? W/chromium: [WARNING:resource_bundle.cc(304)] locale_file_path.empty()
03-22 07:13:05.285 2184-2184/? I/chromium: [INFO:aw_browser_main_parts.cc(63)] Load from apk succesful, fd=29 off=48104 len=3229
03-22 07:13:05.285 2184-2184/? I/chromium: [INFO:aw_browser_main_parts.cc(76)] Loading webviewchromium.pak from, fd:30 off:239276 len:1143511
03-22 07:13:05.312 2184-2184/? D/libEGL: loaded /system/lib/egl/libEGL_emulation.so
03-22 07:13:05.314 2184-2184/? D/libEGL: loaded /system/lib/egl/libGLESv1_CM_emulation.so
03-22 07:13:05.328 2184-2184/? D/libEGL: loaded /system/lib/egl/libGLESv2_emulation.so
03-22 07:13:05.521 2184-2184/? W/chromium: [WARNING:data_reduction_proxy_settings.cc(328)] SPDY proxy OFF at startup
03-22 07:13:05.538 2184-2184/? W/art: Attempt to remove non-JNI local reference, dumping thread
03-22 07:13:05.543 2184-2184/? W/AwContents: onDetachedFromWindow called when already detached. Ignoring
03-22 07:13:05.563 2184-2221/? D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
03-22 07:13:05.822 2184-2221/? I/OpenGLRenderer: Initialized EGL, version 1.4
03-22 07:13:05.908 2184-2221/? W/EGL_emulation: eglSurfaceAttrib not implemented
03-22 07:13:05.908 2184-2221/? W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xdbc78ac0, error=EGL_SUCCESS
03-22 07:13:06.322 676-695/? I/ActivityManager: Displayed com.fjq.android_async_http_demo/.MainActivity: +1s299ms
03-22 07:15:04.574 100-100/? D/Genyd: Received Set Clipboard
03-22 07:15:04.574 100-100/? D/Genymotion: Received Set Clipboard
03-22 07:15:53.953 676-692/? E/BluetoothAdapter: Bluetooth binder is null
03-22 07:16:35.830 100-100/? D/Genyd: Received Set Clipboard
03-22 07:16:35.830 100-100/? D/Genymotion: Received Set Clipboard
03-22 07:17:01.139 676-689/? I/UsageStatsService: User[0] Flushing usage stats to disk
03-22 07:20:30.608 100-100/? D/Genyd: Received Set Clipboard
03-22 07:20:30.608 100-100/? D/Genymotion: Received Set Clipboard
03-22 07:20:54.391 676-692/? E/BluetoothAdapter: Bluetooth binder is null
03-22 07:22:55.638 100-100/? D/Genyd: Received Set Clipboard
03-22 07:22:55.638 100-100/? D/Genymotion: Received Set Clipboard
03-22 07:23:04.007 676-692/? E/BluetoothAdapter: Bluetooth binder is null
人生最曼妙的风景,竟是内心的淡定与从容!