第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定

有人可以給我一份代碼或者幫我查下哪里錯了嗎?我已經(jīng)看了一下午,但是還是沒有找到哪里錯了

ImageText.java
package?com.example.myasynctask;

import?java.io.BufferedInputStream;
import?java.io.IOException;
import?java.io.InputStream;
import?java.net.MalformedURLException;
import?java.net.URL;
import?java.net.URLConnection;

import?android.app.Activity;
import?android.graphics.Bitmap;
import?android.graphics.BitmapFactory;
import?android.os.AsyncTask;
import?android.os.Bundle;
import?android.view.View;
import?android.widget.ImageView;
import?android.widget.ProgressBar;
import?android.widget.Toast;

public?class?ImageText?extends?Activity?{
	private?ImageView?mImageView;
	private?ProgressBar?mprogressBar;
	private?static?String?URL?=?"http://img.my.csdn.net/uploads/201504/12/1428806103_9476.png";

	@Override
	protected?void?onCreate(Bundle?savedInstanceState)?{
		//?TODO?Auto-generated?method?stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.image);
		mImageView?=?(ImageView)?findViewById(R.id.image);
		mprogressBar?=?(ProgressBar)?findViewById(R.id.progressbars);
		Toast.makeText(this,?"呵呵",?1).show();
		new?MyAsyncTask().execute(URL);
	}

	class?MyAsyncTask?extends?AsyncTask<String,?Void,?Bitmap>?{
		@Override
		protected?void?onPreExecute()?{
			super.onPreExecute();
			mprogressBar.setVisibility(View.VISIBLE);

		}

		@Override
		protected?void?onPostExecute(Bitmap?bitmap)?{
			super.onPostExecute(bitmap);
			mprogressBar.setVisibility(View.GONE);
			mImageView.setImageBitmap(bitmap);
		}

		@Override
		protected?Bitmap?doInBackground(String...?params)?{
			String?url=params[0];
			Bitmap?bitmap=null;
			URLConnection?connection;
			InputStream?is;
			try?{
				connection=new?URL(url).openConnection();
				is=connection.getInputStream();
				BufferedInputStream?bis=new?BufferedInputStream(is);
				Thread.sleep(3000);
				bitmap=BitmapFactory.decodeStream(bis);
				is.close();
				bis.close();			
			}?catch?(IOException?e)?{
				e.printStackTrace();
			}?catch?(InterruptedException?e)?{
				//?TODO?Auto-generated?catch?block
				e.printStackTrace();
			}
			return?bitmap;
		}
	}

}
image.xml
<?xml?version="1.0"?encoding="utf-8"?>
<RelativeLayout?xmlns:android="http://schemas.android.com/apk/res/android"
????android:layout_width="match_parent"
????android:layout_height="match_parent"?>

????<ImageView
????????android:id="@+id/image"
????????android:layout_width="match_parent"
????????android:layout_height="match_parent"?/>

????<ProgressBar
????????android:id="@+id/progressbars"
????????android:layout_width="wrap_content"
????????android:layout_height="wrap_content"
????????android:layout_centerHorizontal="true"
????????android:layout_centerVertical="true"
????????android:visibility="gone"?/>

</RelativeLayout>
不知道哪里錯了,我toast在new?MyAsyncTask().execute(URL);就不打印了


正在回答

6 回答

留個郵箱我發(fā)給你

0 回復 有任何疑惑可以回復我~

好的 謝謝你啊


0 回復 有任何疑惑可以回復我~
<?xml?version="1.0"?encoding="utf-8"?>
<LinearLayout?xmlns:android="http://schemas.android.com/apk/res/android"
????xmlns:tools="http://schemas.android.com/tools"
????xmlns:app="http://schemas.android.com/apk/res-auto"?android:layout_width="match_parent"
????android:layout_height="match_parent"
????android:orientation="vertical"
????>
????<Button
????????android:layout_width="wrap_content"
????????android:layout_height="wrap_content"
????????android:text="ImageTest"
????????android:onClick="loadImage"/>
????<Button
????????android:layout_width="wrap_content"
????????android:layout_height="wrap_content"
????????android:text="progressTest"
????????android:onClick="loadProgress"/>
</LinearLayout>
<?xml?version="1.0"?encoding="utf-8"?>
<RelativeLayout?xmlns:android="http://schemas.android.com/apk/res/android"
????android:orientation="vertical"
????android:layout_width="match_parent"
????android:layout_height="match_parent"
????android:padding="16dp">
????<ImageView
????????android:id="@+id/img"
????????android:layout_width="match_parent"
????????android:layout_height="match_parent"?/>
????<ProgressBar
????????android:id="@+id/pg"
????????android:visibility="gone"
????????android:layout_centerInParent="true"
????????android:layout_width="wrap_content"
????????android:layout_height="wrap_content"/>
???
</RelativeLayout>
<?xml?version="1.0"?encoding="utf-8"?>
<RelativeLayout?xmlns:android="http://schemas.android.com/apk/res/android"
????android:orientation="vertical"
????android:layout_width="match_parent"
????android:layout_height="match_parent"
????android:padding="16dp">
????<ProgressBar
????????style="?android:attr/progressBarStyleHorizontal"
????????android:layout_width="match_parent"
????????android:layout_height="wrap_content"
????????android:id="@+id/progressBar"
????????android:layout_centerVertical="true"
????????android:layout_centerHorizontal="true"?/>
</RelativeLayout>
<?xml?version="1.0"?encoding="utf-8"?>
<manifest?xmlns:android="http://schemas.android.com/apk/res/android"
????package="com.demo.linhao.demo1"?>
????<uses-permission?android:name="android.permission.INTERNET"/>
????<application
????????android:allowBackup="true"
????????android:icon="@mipmap/ic_launcher"
????????android:label="@string/app_name"
????????android:supportsRtl="true"
????????android:theme="@style/AppTheme"?>
????????<activity
????????????android:name=".MainActivity"
????????????android:label="@string/app_name"
????????????android:theme="@style/AppTheme.NoActionBar"?>
????????????<intent-filter>
????????????????<action?android:name="android.intent.action.MAIN"?/>
????????????????<category?android:name="android.intent.category.LAUNCHER"?/>
????????????</intent-filter>
????????</activity>
????????<activity?android:name=".ImageTest"></activity>
????????<activity?android:name=".ProgressBarTest"></activity>
????</application>
</manifest>


1 回復 有任何疑惑可以回復我~
import?android.app.Activity;
import?android.graphics.Bitmap;
import?android.graphics.BitmapFactory;
import?android.os.AsyncTask;
import?android.os.Bundle;
import?android.view.View;
import?android.widget.ImageView;
import?android.widget.ProgressBar;
import?java.io.BufferedInputStream;
import?java.io.IOException;
import?java.io.InputStream;
import?java.net.URLConnection;
import?java.net.URL;
/**
?*?Created??on?15/11/23.
?*/
public?class?ImageTest?extends?Activity?{
????private?ImageView?mImageView;
????private?ProgressBar?mProgressBar;
????private?static?String?URL?=?"http://img.my.csdn.net/uploads/201504/12/1428806103_9476.png";
????@Override
????protected?void?onCreate(Bundle?savedInstanceState)?{
????????super.onCreate(savedInstanceState);
????????setContentView(R.layout.image);
????????mImageView?=?(ImageView)?findViewById(R.id.img);
????????mProgressBar?=?(ProgressBar)?findViewById(R.id.pg);
????????new?MyAsyncTask().execute(URL);
????}
????class?MyAsyncTask?extends?AsyncTask<String,Void,Bitmap>
????{
????????@Override
????????protected?void?onPreExecute()?{
????????????super.onPreExecute();
????????????mProgressBar.setVisibility(View.VISIBLE);//顯示進度條
????????}
????????@Override
????????protected?void?onPostExecute(Bitmap?bitmap)?{
????????????super.onPostExecute(bitmap);
????????????mProgressBar.setVisibility(View.GONE);
????????????mImageView.setImageBitmap(bitmap);
????????????//設置傳遞進去的參數(shù)
????????}
????????@Override
????????protected?Bitmap?doInBackground(String...?strings)?{
????????????String?url?=?strings[0];
????????????Bitmap?bitmap?=?null;
????????????URLConnection?connection;
????????????InputStream?is;
????????????try?{
????????????????connection?=?new?URL(url).openConnection();//獲取網(wǎng)絡連接對象
????????????????is?=?connection.getInputStream();
????????????????BufferedInputStream?bis?=?new?BufferedInputStream(is);
????????????????Thread.sleep(3000);
????????????????bitmap?=?BitmapFactory.decodeStream(bis);
????????????????//BitmapFactory?->?Creates?Bitmap?objects?from?various?sources,?including?files,?streams,?and?byte-arrays.
????????????????is.close();
????????????????bis.close();
????????????}?catch?(IOException?e)?{
????????????????e.printStackTrace();
????????????}?catch?(InterruptedException?e)?{
????????????????e.printStackTrace();
????????????}
????????????return?bitmap;
????????}
????}
}
import?android.app.Activity;
import?android.content.Intent;
import?android.os.Bundle;
import?android.view.View;
public?class?MainActivity?extends?Activity?{
????@Override
????protected?void?onCreate(Bundle?savedInstanceState)?{
????????super.onCreate(savedInstanceState);
????????setContentView(R.layout.content_main);
????????MyAsyncTask?task?=?new?MyAsyncTask();
????????task.execute();
????}
????public?void?loadImage(View?v)
????{
????????startActivity(new?Intent(this,?ImageTest.class));
????}
????public?void?loadProgress(View?v)
????{
????????startActivity(new?Intent(this,ProgressBarTest.class));
????}
}
import?android.os.AsyncTask;
import?android.util.Log;
/**
?*?Created??on?15/11/23.
?*/
public?class?MyAsyncTask?extends?AsyncTask<Void,Void,Void>?{
????@Override
????protected?Void?doInBackground(Void...?voids)?{
????????Log.d("xys",?"doInBackground");
????????publishProgress();
????????return?null;
????}
????@Override
????protected?void?onPreExecute()?{
????????Log.d("xys","onPreExecute");
????????super.onPreExecute();
????}
????@Override
????protected?void?onPostExecute(Void?aVoid)?{
????????Log.d("xys","onPostExecute");
????????super.onPostExecute(aVoid);
????}
????@Override
????protected?void?onProgressUpdate(Void...?values)?{
????????Log.d("xys","onProgressUpdate");
????????super.onProgressUpdate(values);
????}
}
import?android.app.Activity;
import?android.os.AsyncTask;
import?android.os.Bundle;
import?android.widget.ProgressBar;
/**
?*?Created?on?15/11/23.
?*/
public?class?ProgressBarTest?extends?Activity?{
????private?ProgressBar?mProgressBar;
????private?MyAsyncTask?mTask;
????@Override
????protected?void?onCreate(Bundle?savedInstanceState)?{
????????super.onCreate(savedInstanceState);
????????setContentView(R.layout.progressbar);
????????mProgressBar?=?(ProgressBar)?findViewById(R.id.progressBar);
????????mTask?=?new?MyAsyncTask();
????????mTask.execute();
????}
????@Override
????protected?void?onPause()?{
????????super.onPause();
????????if?(mTask!=null?&&?mTask.getStatus()==AsyncTask.Status.RUNNING)
????????{
???????????mTask.cancel(true);
????????}
????}
????class?MyAsyncTask?extends?AsyncTask<Void,Integer,Void>
????{
????????@Override
????????protected?Void?doInBackground(Void...?params)?{
????????????for?(int?i=0;i<100;i++)
????????????{
????????????????if?(isCancelled())
????????????????{
????????????????????break;
????????????????}
????????????????publishProgress(i);
????????????????try?{
????????????????????Thread.sleep(300);
????????????????}?catch?(InterruptedException?e)?{
????????????????????e.printStackTrace();
????????????????}
????????????}
????????????return?null;
????????}
????????@Override
????????protected?void?onProgressUpdate(Integer...?values)?{
????????????super.onProgressUpdate(values);
????????????if?(isCancelled())
????????????{
????????????????return;
????????????}
????????????mProgressBar.setProgress(values[0]);
????????}
????}
}


0 回復 有任何疑惑可以回復我~

你方便就在這里吧代碼發(fā)一下嗎?跪謝

0 回復 有任何疑惑可以回復我~

首先感謝你發(fā)了啊,但是我打開還報錯 是什么情況???而且亂起八糟的,實在是慘不忍睹啊

0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消
Android必學-AsyncTask基礎
  • 參與學習       40898    人
  • 解答問題       111    個

了解Android中AsyncTask的使用方法,掌握異步線程的使用

進入課程

有人可以給我一份代碼或者幫我查下哪里錯了嗎?我已經(jīng)看了一下午,但是還是沒有找到哪里錯了

我要回答 關注問題
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號