gpt4 book ai didi

在 targetSdkVersion 8 上运行 AsyncTask 时 Android 崩溃

转载 作者:行者123 更新时间:2023-11-29 14:53:25 25 4
gpt4 key购买 nike

当我设置 android:targetSdkVersion="8" 时我的应用程序崩溃了,但是当我将它设置为 android:targetSdkVersion="11" 时一切正常。请查看 logcat,我真的不知道我的代码有什么问题。看起来任何使用低于 11 的 SDK 的设备都会遇到这个问题。我的最小 sdk 是 7。如果我继续交付我的应用程序,我可能会遇到很多麻烦。

public class SingleMenuItemActivity  extends Activity {

// XML node keys
static final String KEY_TITLE = "title";
static final String KEY_ARTIST = "artist";
static final String KEY_THUMB_URL = "thumb_url";
private ProgressDialog pDialog;
String title;
String artist;
String image_url;
ImageView view;
Intent intent;
Context context;
ShareActionProvider mShareActionProvider;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.single_list_item);
new loadSingleView().execute();




view = (ImageView) findViewById(R.id.single_image);

}

public class loadSingleView extends AsyncTask<String, String, String> {

@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(
SingleMenuItemActivity.this);
pDialog.setMessage("Connecting to Server ...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();
}
@Override
protected String doInBackground(String... args) {
// updating UI from Background Thread


Intent in = getIntent();

image_url = in.getStringExtra(KEY_THUMB_URL);
title = in.getStringExtra(KEY_TITLE);
artist = in.getStringExtra(KEY_ARTIST);

return null;

}
@Override
protected void onPostExecute(String args) {
// dismiss the dialog after getting all products

ImageLoader imgLoader = new ImageLoader(getApplicationContext());

imgLoader.DisplayImage(image_url, view);

TextView lblName = (TextView) findViewById(R.id.name_title);
TextView lblCost = (TextView) findViewById(R.id.name_artist);



lblName.setText(title);
lblCost.setText(artist);

ActionBar ab = getActionBar();
ab.setTitle(title);

pDialog.dismiss();

}


}

日志:

08-19 02:19:03.351: E/AndroidRuntime(22761): FATAL EXCEPTION: main
08-19 02:19:03.351: E/AndroidRuntime(22761): java.lang.NullPointerException
08-19 02:19:03.351: E/AndroidRuntime(22761): at com.example.androidhive.SingleMenuItemActivity$loadSingleView.onPostExecute(SingleMenuItemActivity.java:88)
08-19 02:19:03.351: E/AndroidRuntime(22761): at com.example.androidhive.SingleMenuItemActivity$loadSingleView.onPostExecute(SingleMenuItemActivity.java:1)
08-19 02:19:03.351: E/AndroidRuntime(22761): at android.os.AsyncTask.finish(AsyncTask.java:602)
08-19 02:19:03.351: E/AndroidRuntime(22761): at android.os.AsyncTask.access$600(AsyncTask.java:156)
08-19 02:19:03.351: E/AndroidRuntime(22761): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:615)
08-19 02:19:03.351: E/AndroidRuntime(22761): at android.os.Handler.dispatchMessage(Handler.java:99)
08-19 02:19:03.351: E/AndroidRuntime(22761): at android.os.Looper.loop(Looper.java:137)
08-19 02:19:03.351: E/AndroidRuntime(22761): at android.app.ActivityThread.main(ActivityThread.java:4512)
08-19 02:19:03.351: E/AndroidRuntime(22761): at java.lang.reflect.Method.invokeNative(Native Method)
08-19 02:19:03.351: E/AndroidRuntime(22761): at java.lang.reflect.Method.invoke(Method.java:511)
08-19 02:19:03.351: E/AndroidRuntime(22761): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:982)
08-19 02:19:03.351: E/AndroidRuntime(22761): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:749)
08-19 02:19:03.351: E/AndroidRuntime(22761): at dalvik.system.NativeStart.main(Native Method)

最佳答案

SDK 8 没有ActionBar。您将不得不使用类似 ActionBarSherlock 库的东西来为 SDK < Honeycomb 提供 ActionBar 支持。

关于在 targetSdkVersion 8 上运行 AsyncTask 时 Android 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12021170/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com