aspose file tools*
The moose likes Android and the fly likes Ill-advised or mistaken usage of a core class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Mobile » Android
Bookmark "Ill-advised or mistaken usage of a core class" Watch "Ill-advised or mistaken usage of a core class" New topic
Author

Ill-advised or mistaken usage of a core class

David Freitag
Greenhorn

Joined: May 28, 2011
Posts: 13

For starters this is what was dumped into my console:
Conversion to Dalvik format failed with error 1
trouble processing "java/nio/CharBuffer.class":

Ill-advised or mistaken usage of a core class (java.* or javax.*)
when not building a core library.

This is often due to inadvertently including a core library file
in your application's project, when using an IDE (such as
Eclipse). If you are sure you're not intentionally defining a
core class, then this is the most likely explanation of what's
going on.

However, you might actually be trying to define a class in a core
namespace, the source of which you may have taken, for example,
from a non-Android virtual machine project. This will most
assuredly not work. At a minimum, it jeopardizes the
compatibility of your app with future versions of the platform.
It is also often of questionable legality.

If you really intend to build a core library -- which is only
appropriate as part of creating a full virtual machine
distribution, as opposed to compiling an application -- then use
the "--core-library" option to suppress this error message.

If you go ahead and use "--core-library" but are in fact
building an application, then be forewarned that your application
will still fail to build or run, at some point. Please be
prepared for angry customers who find, for example, that your
application ceases to function once they upgrade their operating
system. You will be to blame for this problem.

If you are legitimately using some code that happens to be in a
core package, then the easiest safe alternative you have is to
repackage that code. That is, move the classes in question into
your own package namespace. This means that they will never be in
conflict with core system classes. JarJar is a tool that may help
you in this endeavor. If you find that you cannot do this, then
that is an indication that the path you are on will ultimately
lead to pain, suffering, grief, and lamentation.


Since i have been developing with Android and Eclipse i have noticed a bunch of small hiccups, whether it is ADB, Eclipse, or my Droid that is causing issues.
One such issue is this one, which by the way left me at my knees for over an hour... but it could have been worse, all of my code is in-tact, no major problems, but the most major as of yet.

I just wanted to document what i did to solve this problem, so others can figure it out on their own, being that some developers (Like myself are not complete experts) and may run into this problem...

Essentially this is what happened, as i mentioned before, there are hiccups in the process, one such hiccup seems to be a loss in the link between my Android project, and the "Android X.Y" library.
At which time was not immediately bad, it was only until i saved what i was currently working on that i noticed a problem, as Eclipse (Being as awesome as it is) Ran an automatic build, this prompted a window letting me know that the link to the library was lost, and that i needed to tell eclipse what android library my project should build under.

Being that my development just a few months ago amounted to notepad and command prompt, the learning curve on my own has been quite steep. Also being that i have been awake now for just over 24 hours made figuring this one out a bit of a daunting task.

When this dialog came up, i neglected to pay attention to exactly what it was going to do when i mindlessly clicked "Ok", i just clicked "Ok". That is when the error hit. Because i did neglect to actually read the dialog, i immediately went through the list of things i do to try and solve these seemingly useless, random errors. Unplug and plug in phone, restart Eclipse, restart ADB and finally Reboot... After all that no dice.

It took some Googling, but i managed to narrow it down to a few handfuls of problems. (Most of which involved things above my intelligence level currently...)
Either the message is true, and i am trying to add java core packages to my build path (Which i would never do... because that just seems like a massive waste of time and CPU...)
Or there is a problem with my Build Path.

Being that i went from Command prompt and Notepad, my knowledge of stuff like this is still extremely lacking. From what i understand a Build Path is exactly what it says, the path your linker looks through to build your applications.. IE the link to the "Android X.Y" Library. When it hit me, that dialog asked me to modify the Android Library location.

I opened my Current project's properties, and referenced what was under the "Libraries" tab in the "Build Path" tab to other perfectly functioning projects in my workspace, and sure enough there was a stray "Android.jar" that was pointing at the jar where i have android installed on this box. My guess is somehow Eclipse lost the ability to find that "Android X.Y" library, had me mindlessly add this "Android.jar" to my build path, and seeing as that probably uses core java stuff, it thought i was trying to. At some point (My guess is when i restarted Eclipse) Eclipse realized that it was in fact an android project, and added the "Android X.Y" library to the build path...

Once i removed the stray "Android.jar" and did a refresh to run the automatic build everything was fine again. This just goes to show, ALWAYS read stray error dialogs, no matter how short your attention span.

Hopefully this will help someone in the future, because there are probably other developers like me (Still a noob) trudging their way through developing...
Mike Valentin
Greenhorn

Joined: Jun 27, 2011
Posts: 1
Hi David,

I am just reading my first Android programming tutorial book and am that noob/greenhorn you are talking about.
Your post really helped me, since, after correcting many other errors in my puny Android example, this was one more
error I encountered, with the very impressive error message from Java Eclipse (".. will ultimately lead to pain, suffering, grief, and lamentation.")

So I was very relieved when, after googling, I found your message and it solved my problem. I have now one more small error, but it has nothing to do with the Build Path.

And yes, one should first get well accustomed with Java or, at least with the Java IDE, before trying to use it (clever, huh ?!). The idea had crossed my mind,
but somehow I didn't find the time to do that. This obviously has consequences.


Thanks & best regards,


Mike
Malcolm Gorman
Greenhorn

Joined: Mar 29, 2007
Posts: 1
I had the same problem. Your instructions helped me fix it in less the 5 minutes.

Here's what I did (in Eclipse):

1. Right-clicked the project name -> Build Path -> Configure Build Path ... -> Libraries

2. Looked at the list of libraries included in my (non-working) project, and noticed that android.jar was there, but wasn't in another (working) project.

3. Removed android.jar


I think the console error message could be improved, suggesting where to look and what to look for.
Ac Aco
Greenhorn

Joined: Jan 20, 2012
Posts: 1
I just open an account here to say Thank you!!!

this post save me hours of my time

thanks again
David
Juan Zepeda
Greenhorn

Joined: Mar 11, 2012
Posts: 1
Just Created an account to say Thank you! I had been working on this for a day! I found yours and it worked!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Ill-advised or mistaken usage of a core class