設定するとアプリがクラッシュしました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();
}
}
Logcat:
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)