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?
Related
Followed instructions in here https://learn.microsoft.com/en-us/azure/service-bus-messaging/service-bus-java-how-to-use-queues to test a java application to connect, send and recieve the messages
With version of 7.0.2 for azure-messaging-servicebus, all is working okay.
However when I update the version, getting errors either at build time or at run time.
I know it should be backward compatible and guess I am doing something wrong. I tried updating the verion of azure-core as well but no luck. Appreciate if someone could help.
7.3.0 -- java.lang.ClassNotFoundException: com.azure.core.util.AsyncCloseable
7.7.0 -- java.lang.ClassNotFoundException: com.azure.core.client.traits.TokenCredentialTrait
The 'java.lang.ClassNotFoundException' is a Java checked exception that happens when the JVM tries to load a class but cannot locate it in the classpath.
Generally, because the 'ClassNotFoundException' is a checked exception, it must be explicitly handled in methods that can throw it - either via the use of a 'try-catch block' or through the use of the 'throws' clause.
You can refer this similar SO threads for more information.
Reference1 , Reference2
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
I am developing an AppEngine application where I gotta work with Google Calendar API. Because of some reasons, we are not using the lastest version of this API (v3) and we are working with gdata-calendar-v2 which is still working until the next November.
All right, I have two methods where I am using the Calendar Service. For one hand, I am adding a new event on my calendar and I do something like:
CalendarService myService = new CalendarService("my_calendar"); // error on this line
myService.setUserCredentials(EMAIL, PASSWORD);
As I know, it is working fine and I am adding new events on my calendar with no problems.
For another hand, I have another method where I do something different but I am using the same snippet code to connect to Google Calendar. In this case, I get this error:
Caused by: java.lang.NoSuchMethodError: com.google.common.collect.ImmutableSet.copyOf([Ljava/lang/Object;)Lcom/google/common/collect/ImmutableSet;
at com.google.gdata.wireformats.AltFormat$Builder.setAcceptableTypes(AltFormat.java:399)
at com.google.gdata.wireformats.AltFormat$Builder.setAcceptableXmlTypes(AltFormat.java:387)
at com.google.gdata.wireformats.AltFormat.<clinit>(AltFormat.java:49)
at com.google.gdata.client.Service.<clinit>(Service.java:558)
The libraries that I am using with -collections- and you can be interested are:
Guava 11 (I already update to 18 and it's the same problem).
I know there is a very similar thread with the same problem right here but there is one difference: it is working fine in one method of my project and it is not working fine in another.
Can you give me a helping hand?
Thank you in advance,
Diego.
Solution:
I have been searching in Google and I found out this thread
I have changed my Guava to guava-10.0.1.jar and I don't get this error anymore.
The latest version of the gdata client library for java (version 1.46.0 as of this writing, found here: https://code.google.com/p/gdata-java-client/downloads/list) still embeds google-collections-1.0-rc1.jar inside their dependencies, and at this point it's not able to be replaced by the latest guava version.
Most likely you're using two different version of Guava. Add the line
System.out.println(ImmutableSet.class.getClass().getResource("/"));
to the line before the exception to find out where the conflicting version resides.
Current Guava has the method
public static <E> ImmutableSet<E> copyOf(E[] elements) {}
Some older version (e.g., Google collections) do not. It looks like
com.google.gdata.wireformats.AltFormat$Builder
accesses the old version.
I tried to run This example from bigflake and I think that there is a mismatch.
they write "ExtractMpegFramesTest.java (requires 4.1, API 16) " so the minimum API required is 16,
but I look over the code and they use "import android.opengl.EGL14;" which required minimum API 17.
Has anyone encountered this problem and succeeded to solve it?(succeeded to save 10 frames on Android 4.1 device)
I've updated the site to have two copies of the source file, one that uses EGL 1.0 and one that uses EGL 1.4. I did a quick test with the SDK, creating an app for API 16, to confirm that it's no longer using post-4.1 APIs. I haven't tried it on an actual device running 4.1 however.
You can use MediaMetadataRetriever.getFrameAtTime in order to extract frames from a video file. It's available since API level 10.
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.