Can't run the ActionBarCompat sample - java

I am having trouble compiling and running the ActionBarCompat sample of Android 16. I have API level 16 as the build target selected, which seems to build fine, but when I try to debug these errors pop up. Of course I could change the min API level in the manifest, but what would be the point of that? I have made no changes to the sample, so how come it is not working properly?
Class requires API level 14 (current min is 3): android.view.ActionProvider SimpleMenuItem.java /ActionBarCompat/src/com/example/android/actionbarcompat line 129 Android Lint Problem
Class requires API level 14 (current min is 3): android.view.ActionProvider SimpleMenuItem.java /ActionBarCompat/src/com/example/android/actionbarcompat line 134 Android Lint Problem
Class requires API level 14 (current min is 3): android.view.MenuItem.OnActionExpandListener SimpleMenuItem.java /ActionBarCompat/src/com/example/android/actionbarcompat line 155 Android Lint Problem
I am thoroughly confused, any help would be appreciated.
UPDATE:
I have added the #TargetApi(14) annotations, then added Lint suppres newApi to one of the methoeds and now it seems to be running fine. I am even more confused. Could anybody shed some light on what's going on?

Sadly, these samples are not kept up to date for each SDK iteration.
-First thing first, you have setted a min of sdkversion = 3 ? That seems a little low to me. 7 (eclair) is I think the minimum version most projects should focus on.
Lower level versions have a ridiculous market share and it will keep decreasing.
-These are Lint warnings. Lint is kinda new to Android, this is why this sample does not take it into account. It tells you about potential problems in your code. This warning means you are calling a level 14 class in a code that can run on a level 3 terminal. You should try to remove them with an #TargetApi(14) annotation. This annotation tells to Lint that you know what you are doing and this code will only run for sdk version=14 at minimum.
-Also, if you want to use the actionbar with any version of Android, what you really want to use is the open source ActionBar Sherlock library. One step at a time though :-)

In your manifest, you define android:minSdkVersion="3", yet you are making calls to API level 14 classes/methods.
Lint will check these types of API calls and give you a warning.
Obviously in the ActionBarCompat the current API level is checked to ensure it is safe to make the call.
To remove the warning simply add #TargetApi(14) before the method where you make the call.

You need to change the Project build target to API level 14..in (project->properties->Android)
These are their requirments:
Due to the use of the native action bar and its related classes on Ice Cream Sandwich, the library requires that both it and your project are compiled with Android 4.0 or newer. The project also requires that you are compiling with JDK 1.6 in both your editor and any build systems that you may be using.

Related

ConcurrentLinkedDeque in API below 21

In order to resolve a concurrency issue, I'm using ConcurrentLinkedDeque which according to android documentation, is added in API-21.
However, I'm still able to run the code on a device with API-16 without any errors at all. Though it does highlight calls to its methods saying:
Call requires API level 21 (current min is 14):
java.util.concurrent.ConcurrentLinkedDeque#ConcurrentLinkedDeque
but that can be ignored using #SuppressLint("NewApi").
So, why is it possible? Why don't I get a ClassNotFoundException when running it in APIs below 21?

NoSuchMethodError: java.lang.Exception.addSuppressed : Updating from Java 1.6 to 1.7

I started using Java 1.7 and I'm still using Eclipse. In my Project I add extra data to the thrown exception, with handledException.addSuppressed(additionalException); and it was working so far.
But according to my crash reports, some old OS installed devices(Android 2.3.4) are crashing with StackTrace below. But it doesn't occur in my Nexus 5 which has Android 4.4.4.
java.lang.NoSuchMethodError: java.lang.Exception.addSuppressed
I'm not really sure if there is some additional steps needed to update it to Java 1.7.
handledException.addSuppressed was added only in API 19.
You should put if else loop surrounding this piece of code
Android 2.3 uses level 10 API.
addSupressed() was added in level 19. In the future, check what API level was being used during that time (2.3), then check the API to see if it was available during that API level

Errors on building an android project: "isIBSS/frequency cannot be resolved or is not a field"

I am having difficulty building an android app called Commotion Wireless from its source code. This should be a simple matter of importing the project into eclipse and exporting it as an APK.
However upon building I am left with three errors:
two saying "isIBSS cannot be resolved or is not a field" and
one saying "frequency cannot be resolved or is not a field".
The lines of code producing these errors are lines 201, 202 and line 92. If I comment out these lines of code then I can generate an APK just fine, though obviously the app doesn't work as intended with these lines missing.
My impression was that these errors arose due to Android not supporting ad-hoc (IBSS) networks by default (the purpose of this app is to have the android device generating an ad-hoc network). Therefore, the related definitions of isIBSS and frequency seem to be absent from the default version of android.
This app, according to its creators, is intended for use on Cyanogenmod which has been modified to support ad-hoc networks and does have these definitions (see this review).
Therefore my line of thought was that I had to use a modified version of the android SDK based on cyanogenmod that would have these definitions added in order for me to compile the program. However, as far as I can tell, no such thing exists.
Is my line of thought here correct, and does anyone have any solutions to offer for this problem? Please bear in mind I only have a basic understanding of Java and have never tried to compile an android app before.

Basic Android Project: alternating cannot be resolved or is not a field/R cannot be resolved into a variable errors

I am new to Android Development/Java Programming/Eclipse so please bear with me. I've been going through the Android Developer Training (developer.android.com/training) and the Hello Android book by Ed Burnette and keep running into a problem that is making it difficult to move forward. I'll do my best to describe it and am hoping that the community can help me resolve it.
I began seeing this issue with the Android Developer Training (around Adding the Action Bar -> Adding Action Buttons) and it became impossible to circumvent at Hello Android's 3.3 Creating Opening Screen when I tried adding the Sudoku buttons. The only change I made when going through Hello Android was adding the Android Development Toolkit (ADT) for Eclipse. I don't recall this being a required download going through the Android Developer Training page so I am wondering if its addition could have contributed to the problem.
The issue that I keep running into is that when I go to build the project, Eclipse keeps telling me:
action_settings cannot be resolved or is not a field
activity_sudoku cannot be resolved or is not a field
container cannot be resolved or is not a field
fragment_sudoku cannot be resolved or is not a field
sudoku cannot be resolved or is not a field
I've tried several fixes that I saw on in the forum including deleting the import.android.R from the sudoku.java file in my src folder but that brings up a bunch of errors that say R cannot be resolved into a variable. I've tried cleaning and rebuilding and restarting Eclipse, methods that occasionally worked before Hello Android and the plugin, but keep getting the same errors. I've also tried setting to Android 3.0 and higher thinking that might be an issue but there was no change. Occasionally I get another error regarding not being able to find the path for a container but I've been playing around with the IDE for 15 minutes and can't seem to get it to pop up again.
I could really use some help on this.
Hope to hear from you,
Yusif Nurizade
This solution may, first and foremost, demonastrate how green I am with Android programming but I believe I found the solution.
Initially following the Android Developer Tutorial, I downloaded the latest versions - 18, 19, 20, etc. When I was creating the project, however, I was specifying much early versions for compatibility; all the way down to 7 or 8. I looked into this because I remembered seeing a message from the IDE regarding the Action Bar and how some commands weren't supported on Version X.
I went back and downloaded all the versions down to 7 or 8 and set the compatibility accordingly. The example now works with minimal other changes. I realize that I may be overlooking something but this is the only major change I made and it seems to have done the trick.
Hopefully this will help other newbies!
Yusif Nurizade

Android: Master detail project has errors right after creation

I have the android 4.1 and 4.0 SDK installed on my laptop. I've done plenty of projects just using a blank activity, but when I decided to try a "master detail flow" example from within Eclipse (create new Android project, select MasterDetailFlow) the other day it wouldn't even let me build. I have errors right off the bat. Surely this can't be right? Here are the errors:
(1)The method onItemSelected(String) of type ItemListActivity must override a superclass method ItemListActivity.java /Master Detail/src/com/example/master/detail line 39 Java Problem
(2)The method onItemSelected(String) of type new ItemListFragment.Callbacks(){} must override a superclass method ItemListFragment.java /Master Detail/src/com/example/master/detail line 27 Java Problem
I'd like to try and use the master detail forms so I can understand more advanced android layouts. Could anyone point me into a better direction with that as well? Thanks!
Ugh, that's a pain, but it's a pretty simple solution. The rules for when you should/shouldn't use #Override switched from Java 5 to Java 6, so depending on Eclipse's default JDK it'll sometimes yell at you when #Override isn't there but should be, or vice versa.
Set the compiler level in Eclipse to at least JDK 6 and the errors will magically disappear :)

Categories