问题是您试图从非UI线程访问UI元素并对其进行操作。如果您更改
AsyncTask以下内容,我相信您会没事的:
public class ImageLoader extends AsyncTask <Void, Void, Bitmap>{private String URL;private int type;private Context context;private InputStream in;ImageLoader(Context context, String Url, int Type){ URL = Url; type = Type; ImageLoader.this.context = context;}@Overrideprotected void onPreExecute(){ AssetManager assetMgr = context.getAssets(); try { in = assetMgr.open(URL); } catch (IOException e) { e.printStackTrace(); }}@Overrideprotected Bitmap doInBackground(Void... arg0) { Bitmap bitmap = null; try { bitmap = BitmapFactory.depreStream(in); in.close(); } catch (IOException e) { e.printStackTrace(); } return bitmap;}@Overrideprotected void onPostExecute( Bitmap result ) { if (type == 1) Inst1 = result; else if (type == 2) Inst2 = result; else if (type == 3) Inst3 = result;}}还要将您的呼叫更改为
AyncTask以下形式:
task = new ImageLoader(gameContext, "Instructions_2.png", 3);task.execute();



