0

このコードで特に実行時エラーが発生するため、 asynctaskon に問題があります。doInBackground

ConnectivityManager connectivity = (ConnectivityManager) content.getSystemService(Context.CONNECTIVITY_SERVICE);

((画像を表示したいのですinamgeviewが、最初に接続がアクティブかどうかを確認します。これらの操作は、アクティビティを拡張しない別のクラスで実行されます)):

これが主な活動です:

public class TelevideoInternationalActivity extends Activity implements OnClickListener {
/** Called when the activity is first created. */

String loc = "Nazionale";
static String home_page = "http://www.televideo.rai.it/televideo/pub/tt4web/Nazionale/16_9_page-100.png";
WorkAsyncIta wai = new WorkAsyncIta();
static String but = "";
Context content;
/************DECLARES**************/
 RelativeLayout relativeLayout1;
 ImageView imgpag;
 ProgressBar probar;
/**********INITIALIZES**************/



@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    imgpag = (ImageView)findViewById (R.id.imgpag); 
    relativeLayout1 = (RelativeLayout) findViewById(R.id.RelativeLayout1);
    probar = (ProgressBar) findViewById (R.id.probar);

    wai.execute("http://www.televideo.rai.it/televideo/pub/tt4web/Nazionale/16_9_page-100.png" );


}

private class WorkAsyncIta extends AsyncTask<String, Void, Bitmap> 
{
    @Override
    protected void onPreExecute()
    {

        probar.setVisibility(0);
    }
   @Override
   protected Bitmap  doInBackground(String... url) {

         return ItaliaTelevideo.setHomePage(url[0], content);


     }
   @Override
   protected void onPostExecute(Bitmap result) {

         probar.setVisibility(1);
         imgpag.setImageBitmap(result);
         imgpag.setScaleType(ScaleType.FIT_XY);
     }  
}

}

エラーを修正しましたが、デバッグ ビューに次のように表示されます。

Thread [<17> AsyncTask #1] (Stepping)   
ThreadPoolExecutor$Worker.run() line: 672   
Thread.run() line: 1060 

imageview画面をタッチすると何も表示されず、次のように返されます。

Thread [<3> main] (Suspended (exception IllegalStateException))
ViewRoot.handleMessage (Message) line: 1704
ViewRoot (Handler). DispatchMessage (Message) line: 99
Looper.loop () line: 123
ActivityThread.main (String []) line: 4203
Method.invokeNative (Object, Object [], Class, Class [], Class, int, boolean) line:   not available [native method]
Method.invoke (Object, Object ...) line: 521
ZygoteInit MethodAndArgsCaller.run $ () line: 791
ZygoteInit.main (String []) line: 549
NativeStart.main (String []) line: not available [native method]
4

2 に答える 2

1

contentnull であるため、NullPointerException が発生します。にコンテキストを割り当てる必要がありcontentます。おそらく、次のようにアクティビティ自体を割り当てることができます。

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    content = this; // this is the important line
    // The rest goes here...
}
于 2011-10-28T14:38:30.540 に答える
1

で gui を行うことはできずdoInBackground()、Toast メッセージを表示する funciton を呼び出しています。AsyncTask のドキュメントを確認してください。

于 2011-10-28T14:40:26.657 に答える