1

My app crashed when I set my android:targetSdkVersion="8" but when I set it to android:targetSdkVersion="11" everything goes fine. Please look at logcat, I really dont know whats wrong with my codes. It looks like any device using SDK below 11 will get this problem. My min sdk is 7. I might bump into alot trouble if I continue to deliver my app.

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)
Android Novice
  • 536
  • 3
  • 14
  • 33

3 Answers3

3

SDK 8 does not have ActionBar. You will have to use something like the ActionBarSherlock library to have ActionBar support for SDK < Honeycomb.

tolgap
  • 9,629
  • 10
  • 51
  • 65
2

I think these code lines cause Exception in API 8,

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

Because, ActionBar were added in Android 3.0 (API level 11). From Android Docs..

For you subject concerns..

Please Look at these two SO Questions..

  1. ActionBar pre Honeycomb

  2. How to implement the action bar in api levels less than 11?

Community
  • 1
  • 1
user370305
  • 108,599
  • 23
  • 164
  • 151
  • Also look at [Support Library](http://developer.android.com/tools/extras/support-library.html) IF its help you. – user370305 Aug 18 '12 at 18:38
1

Without knowing which is line 88, the problem is probably here:

ab.setTitle(title);

ActionBar was added in API 11

http://developer.android.com/guide/topics/ui/actionbar.html

User
  • 31,811
  • 40
  • 131
  • 232