0

I have reached the second exercise in the tutorial on android.com called "Adding the action bar". It seems that you are not supposed to create a new project in this exercise, but rather continue with the one from the first exercise. I am using Android 2.3.6, and choose path accordingly. The tutorial then describes some changes to be made:

public class MainActivity extends ActionBarActivity { ... }

in MainActivity.java. This seems to be in conflict with how MainActivity is defined earlier, as an extension of activity. It also renders the content of the class seemingly meaningless.

The tutorial now tells me to enter this into AndroidManifest.xml

<manifest ... >
    <uses-sdk android:minSdkVersion="7"  android:targetSdkVersion="18" />
    ...
</manifest>

android:minSdkVersion is previously set to 8. Is this important?

This method should be added to something, To what exactly?

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu items for use in the action bar
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.main_activity_actions, menu);
    return super.onCreateOptionsMenu(menu);
}

There are another few methods like this. I don't know where they are supposed to go. They seem more optional, though.

This renders an ocean of errors. Virtually nothing can be resolved to a type.

Update (by OP - was a suggested edit to Nezam's answer): I get the following errors: 1. "ActionBarActivity cannot be resolved to a type". 2. "The method OnCreate(Bundle) of type MainActivity must override or implement a supertype method". Doesn't the @override before the function declaration care for that? (I'm new to this. I'm not even quite sure what an override is.) 3. "ActionBarActivity cannot be resolved to a type". 4. "The method setContentView" is undefined for main activity".

(I get more errors, this is just a start)

What is clean supposed to do? When I try to run it, something called aapt.exe crashes. – user2536262 2 days ago

Follow my edit.. – Nezam 2 days ago

I've been working further with the tutorial, among other things trying to confirm that the library is properly included. I try to install the Android Support Library as described in the tutorial. The SDK manager eventually lets me know nothing can be downloaded or installed because I'm trying to contact the unknown host dl-ssl.google.com. How can you proceed from here? – user2536262 2 days ago

thats a different issue altogether.You should mark this questions solution and move on to :stackoverflow.com/questions/15796780/… – Nezam 2 days ago

The SDK manager problem is now fixed. The other problems remain. – user2536262 yesterday

You better start a fresh thread to resolve the other problems.The problem in the original post is solved right? – Nezam yesterday

The "ocean of errors" remain. The problem has not been solved, it has been redefined. I guess that calls for a new post. – user2536262 19 hours ago

chiccodoro
  • 14,407
  • 19
  • 87
  • 130
user2536262
  • 279
  • 2
  • 8
  • 22
  • Dear user, welcome to StackOverflow! You have additional questions which you tried to incorporate into @Nezam's answer by editing it - I have rejected your edit. If you want to elaborate on your question you can add comments to Nezam's anwer or edit your own question to add the details. – chiccodoro Jan 17 '14 at 10:44
  • For your convenience I have added your text to your own question so it is not lost. You may still want to review and edit it. – chiccodoro Jan 17 '14 at 10:46

2 Answers2

2

This method should be added to something, To what exactly?

to the MainActivity Class

android:minSdkVersion is previously set to 8. Is this important?

No.

This renders an ocean of errors. Virtually nothing can be resolved to a type.

In such cases you should Project --> Clean

EDIT:

"ActionBarActivity cannot be resolved to a type"

Follow this link which would let you add correct libraries and organize imports

Community
  • 1
  • 1
Nezam
  • 4,122
  • 3
  • 32
  • 49
  • The MainActivity class looks like this: public class MainActivity extends ActionBarActivity{ public final static String EXTRA_MESSAGE = "com.example.myfirstapp.MESSAGE"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } ... } – user2536262 Jan 14 '14 at 16:20
  • I get the following errors: 1. "ActionBarActivity cannot be resolved to a type". 2. "The method OnCreate(Bundle) of type MainActivity must override or implement a supertype method". Doesn't the @override before the function declaration care for that? (I'm new to this. I'm not even quite sure what an override is.) 3. "ActionBarActivity cannot be resolved to a type". 4. "The method setContentView" is undefined for main activity". What is clean supposed to do? When I try to run it, something called aapt.exe crashes. – user2536262 Jan 14 '14 at 16:21
  • I've been working further with the tutorial, among other things trying to confirm that the library is properly included. I try to install the Android Support Library as described in the tutorial. The SDK manager eventually lets me know nothing can be downloaded or installed because I'm trying to contact the unknown host dl-ssl.google.com. How can you proceed from here? – user2536262 Jan 15 '14 at 10:10
  • thats a different issue altogether.You should mark this questions solution and move on to :http://stackoverflow.com/questions/15796780/failed-to-fetch-url-http-dl-ssl-google-com-android-eclipse-addon-xm – Nezam Jan 15 '14 at 10:26
  • The SDK manager problem is now fixed. The other problems remain. – user2536262 Jan 15 '14 at 13:19
  • You better start a fresh thread to resolve the other problems.The problem in the original post is solved right? – Nezam Jan 15 '14 at 14:22
  • The "ocean of errors" remain. The problem has not been solved, it has been redefined. I guess that calls for a new post. – user2536262 Jan 16 '14 at 14:36
  • It would be better if you add this comment text as an edit to the question. – Nezam Jan 16 '14 at 14:50
0

Use actionbar sherlock library for low android version(lower than Android 3.0.) see following links

http://actionbarsherlock.com/

https://github.com/JakeWharton/ActionBarSherlock

Also see example . Now u have to extend SherlockActivity in place of Activity .

keshav
  • 3,235
  • 1
  • 16
  • 22
  • 3
    How is "use this library instead" a valid response to confusion about a tutorial? – thegrinner Jan 14 '14 at 14:22
  • I wouldn't say you're *wrong*, just that suggesting he use a different library will only compound his confusion with the tutorial. In a case like this, I'd suggest answering his question and then include a bit at the end suggesting he use another library instead when he is working on an actual app - that way you help him now and in the future. – thegrinner Jan 14 '14 at 14:34
  • tutorials like this helps to understand conception of "ActionBar" and basic use of it. ActionBarSherlock was used before because older Android versions like "Gingerbread" doesn't have ActionBar support. But Google released new AppCompat library that gived a possibility to use ActionBar for older version of Android. – Arshak92 Jan 14 '14 at 14:36