achartengine demo compiling, but runtime error - android

I followed demo instructions on page http://www.achartengine.org/content/goodies.html
i successfully imported the demo project, but every chart give throws
a NoClassDefFoundError at runtime, similar to this:
java.lang.NoClassDefFoundError:
org.achartengine.model.XYMultipleSeriesDataset
achartengine-1.0.0.jar is on build path, and it is reported under
'Referenced Libraries'. I guess this is a newbie problem, but I
decided to report it since I just imported the demo project 'as is'
and tried to run it on my phone.
Do I need other steps, not listed on 'goodies' page?

I found a good answer on google groups, tested it and it seems to be working:
The only thing that I have ever came across in this case is the export of the jar ... if that makes sense.
In Eclipse:
Right click your project - go to build path - select Configure build
path
go to the "Order and Export" tab
Check the "achartengine-1.0.0.jar box and then single click its name
move it up so its right below the Android dependancies (sometimes this can make a difference if you have multiple Jars)
click ok then clean your project. (Project -> Clean...)

Remind to change the "lib" directory to "libs" first !
Then CHECK the box of achartengine-1.0.0.jar and move it over the Android Dependencies in the "Configure build path" - "Order and Export" tab"!

The error (NoClassDefFoundError) you are seeing is runtime error. Referenced library solves only compile time error not runtime error. Add those jars to lib folder of your project. Those jars should be available at runtime also.

The answer from 'Shine' worked with the addition of removing import of android.R from PieChartBuilder and removing two #Overrides from PieChartBuilder and XY_ChartBuilderbefore Eclipse would agree to compile.

You need simply to add your jar files to the Libraries folder. It should work fine.

Related

Android Eclipse NoClassDefFoundError for external .jar files

I have come across a strange error. I have an Android project that uses external libraries, in particular:
android-support-v4.jar (for Fragment support in Android 1.6)
GoogleAdMobAdsSdk-4.3.1.jar (for ads)
The project ran fine until I updated some aspects of the plugin (can't recall the specifics as I did not pay too much attention to it) and after that, whenever I try to use any class from the above .jar files (or any of its subclasses, even ones defined by me), I would get a java.lang.NoClassDefFoundError. I could not find the answer after much searching, so I am really stumped.
I believe this problem is related to how my IDE is set up and it has little to do with actual code, so I will not post any unless if it's absolutely necessary.
You need to read this - Dealing with dependencies in Android projects.
This link is also useful - ClassDefNotFoundError with ADT 17
Basically, create a folder called libs and place all of your jar files inside. The recent update will automatically take care of the rest for you. You don't need to edit your path anymore.
Android does not support Java1.7 up to now. Jars built with compliance level 1.7 cannot be used in Android Applications. Rebuild your Java project with compliance level 5.0 or 6.0 before exporting the jar file.
I found this post via google and answers above didn't solve my problem. Hope what I say will be helpful to others.
If you see NoClassDefFoundError after upgrading to ADT 22, try this in Eclipse:
Go to Project Properties → Java Build Path → Order and Export tab.
Check the Android Private Libraries option.
Also a warning to others who have updated to r17 with many dependencies. I had a another referenced project on my build path and it still did not work after following ALL the directions on this r17 issue on the internet.
Found out after an hour that my referenced project used an older version of an external Jar than my main project did. When trying to compile the main project, Eclipse would give up due to this jar version difference and I never noticed the warning message in Console.
Solution was to copy the newer version external jar file to the referenced project's libs directory.
Wow - such a productivity killer.....
I ran into this error today too, because of updating to the Android SDK, r17. What the links that #aneal pointed out do not discuss is how to handle external runtime libraries (such as those imported under their own heading - not an imported user library).
The easiest way to solve this problem is to change the build order in the build path. Simply right click on your project and select Properties. From here, select Java Build Path. At the top of the display, choose the tab order and export and move GoogleAdMobAdsSdk-4.3.1.jar above Android X (replacing x with the version you are using). Next, clean your project and run it. You should be good to go!
The way I solved it was by : Right clicking on the project and selecting build path. Select configure build path in the selections that appear. After that see if your libraries are there in the libraries folder and then select the order and export tab and over there select all your jar files. Then select ok and run your project.
If you're using Eclipse with Maven IDE (m2e) go to "Java Build Path" then "Order and Export" and finally check the item "Maven Dependencies" and pull it down to the BOTTOM of the list. You should do the same with project references in the same workspace.
Every time I setup the project in a new computer that happens.

Unable to Debug Library Projects with ADT v14 - Source Not Found

Ever since upgrading my current projects to use the new R14 Tools in Eclipse, I'm now unable to debug any code that exists in my library projects.
When I hit a break point in my library project code, instead of Eclipse opening the original source file, it opens up the read-only copy of the source file contained within the JAR with the message "Source not found".
I've searched around for a solution to this, but have yet to come across anything. Does anybody else have any suggestions? It's quite a pain not being able to debug.
EDIT
The issue has came back and I'm no longer able to debug. I haven't changed any project settings around or anything. Very frustrating.
Tried all of the above and it did not work for me, however the workaround detailed here did.
http://code.google.com/p/android/issues/detail?id=20731
Start debugging, and run until you hit a breakpoint (and precisely get a .class file instead of the .java you would like to have)
Right click in the Debug view of the Debug perspective (for example on the call stack), and choose "Edit Source Lookup Path"
Add all your projects above "Default", via "Add..." > "Java project" > "Select All"
(I'm using ADT 15.0.2 preview from http://tools.android.com/download)
After having this issue as well and doing a little research, I came across this thread and another one that tipped me off. I was pulling my hair out already.
It turns out that the problem is with the build order of your projects (mine was anyway). Since ADT/SDK v14 changed the way library projects are referenced, the build order needs to be correct. Make sure all of the libraries your app uses are built first. I just moved the "src" and "gen" folders for each of my projects to the bottom and now it builds the library first and I am able to debug it and view the source of my library files through the main project.
In case someone doesn't know where to do this, in Eclipse, right click on your project and "Build Path" and then click "Configure Build Path". Then, on the "Order and Export" tab, move the two folders for your project to the bottom of the list below your libraries. I did this for all of my projects and the library projects.
You can also do it globally in Eclipse from Windows->Preferences->General->Workspace->Build Order and moving your library projects to the top. I think the build order defined in each project will override this though, so you may want to do it in both places to solve the issue now and for future projects.
I had the same problem in a project today. The project consists of an app which has two library dependencies. I could not see code during debugging and when using auto-completion when overriding methods Eclipse was unable to deduce proper argument names.
First of all, the problem manifested itself by showing the the 'gen' folder was used as the one that contained the source. To check whether this is the same issue go to your app project, open the Android dependencies and have a look at the properties of the your library dependencies. Location path said /libraryprojectname/gen.
If this is also your problem then go to the 'Order and Export' tab of each library project and move the 'gen' item below the 'src' item. As soon as you click OK Eclipse will work a bit and when you check the Android dependency properties the location path should say: /libraryprojectname/src. Open click the dependency and open any class inside the jar. It should show the source.
I am using ADT plugin 20.0.3 with Android SDK Tools 20.0.3 and Android SDK Platform Tools 14.
The following worked for me on Eclipse Juno:
In Project Properties/Java Build Path:
In the Projects tab, added my library projects.
In the Order and Export tab, moved my library projects to the top, and checked them
Not sure if it's relevant, but Android SDK tools is rev 20.0.3 and Android SDK platform tools is 14.
I assume you are opeining library project and there you put brakepoint.
Try this: On main project open Library Projects->[yourlibrary.jar]->[yourfile.class] from Package Explorer, and then in .class file put brakepoints.
This works for me at least :)
Sometimes this happens to me. Not sure about the reason but the way I solve is:
Remove the main project from eclipse. -- Closs Eclipse -- Delete the jar file in the library project -- Open Eclipse -- Wait for the library project to compile -- Import the main project
This problem also occurs with release 21 of ADT inside Juno. As a workaround, in the "debug" view of the debug perspective (where you see threads and method invocation traces), right click and edit source lookup path.

"Conversion to Dalvik format failed with error 1" after update to ADT 14

After updating to the latest developer tools, ADT 14, my Android project that includes library projects will no longer run producing the error:
Dx UNEXPECTED TOP-LEVEL EXCEPTION: ... already added: ...
...
Conversion to Dalvik format failed with error 1
The other threads describing this issue with solutions that include removing and re-adding the projects do not work.
This problem is listed as a known issue of ADT 14. Here's the quote from the Android Tools Project Site:
Project not building with error
[2011-10-20 23:32:04 - MyApp] Dx UNEXPECTED TOP-LEVEL EXCEPTION:<class>: already added: <class>
This is due to a failure to remove previous library source folders from the
main project. Incidentally, the fragility around those linked source
folders is one of the reason we are moving away from this mechanism
(see more info at
http://tools.android.com/recent/buildchangesinrevision14). The
solution is to remove those <libraryname>_src source folders from
your projects. Just right click them and choose Build Path > Remove
from Build Path. You should also be prompted to remove the linked
folder which you should do. If you're not prompted, remove it
manually. You can see some screenshot of the problem in this great
post:
http://android.foxykeep.com/dev/fix-the-conversion-to-dalvik-format-failed-with-error-1-with-adt-14
Solution:
As it says, the solution is to remove the <libraryname>_src source folders from your projects. You can do this by right clicking them and choose "Build Path -> Remove from Build Path" or in your project properties (Java Build Path -> Source tab).
I also ran into this problem, but none of the above fixed it:
Tried removing/re-adding libraries with clean builds along the way
Tried deleting and re-importing projects
No dice. Still the "Conversion to Dalvik format failed with error 1" was staring me in the face every time I tried to export to an apk.
I could tell the problem was related to ProGuard, because when I commented out this line in my project.properties file, everything worked fine:
proguard.config=proguard.cfg
However, I wasn't able to solve the problem until I found this post by David M Young. Apparently, ADK/ADT 14 shipped with an incorrect version of ProGuard (oops!). I downloaded ProGuard version 4.6. Replaced the android-sdk\android-sdk\tools\proguard\lib directory contents with proguard4.6.zip\proguard4.6\lib (3 *.jar files), restarted Eclipse and export to apk worked again!
To solve you should:
Right click on your project>Properties>Java Build Path and remove all libs but the one Android I.J (depending on your version)
Project>Clean
Add back the libs you've removed
If the problem comes back another times it's useful to put the libs outside your project and import them as "External JARs"
Hello thought I'd throw my two cents in here. as I did do that,
"_src -> Remove from path"
Then I cleaned it and rebuilt and I could get it to run in debug mode on my phone just fine. I could also export it; but only if I disabled proguard. of course I couldn't leave it like that with my code open for all to see. so it was quite madding. but I Finally found a cure, oddly enough they had the same problem (and fix) with r12 as they do with this one.
it's in: [Android SDK Installation Directory]\tools\proguard\bin\proguard.bat
Change
call %java_exe% -jar "%PROGUARD_HOME%"\lib\proguard.jar %*
to
call %java_exe% -jar "%PROGUARD_HOME%"\lib\proguard.jar %1 %2 %3 %4 %5 %6 %7 %8 %9
I tried tons of other stuff but this is what did it for me.
This is a known problem with the android sdk. Check out this blogpost for a fix.
I used a library for my project and had the same error - it was solved by removing library and src-folder, cleaning and adding it back and cleaned again.
Remove
Project properties -> Android: Remove libs, 'Apply'
Remove included library src-folder
better clean,
Add again
Project properties -> Android: Add libs again, 'Apply'
Clean project
Just had this problem come back again (fixed first time by removing the _src items as mentioned in other answers) - this time there were no _src files to remove. The error was relating the android-support-v4.jar which was included as part of a linked library project as well as part of the main project itself.
Error Dx UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.IllegalArgumentException: already added: Landroid/support/v4/content/ModernAsyncTask$WorkerRunnable;
Problem went away after removing the android-support-v4.jar file from the build path for the main project. Don't think I came across this as possible cause to the errors.
Go to Project » Properties » Java Build Path » Libraries and remove all except the "Android X.Y" (in my case Android 1.5). click OK. Go to Project » Clean » Clean projects selected below » select your project and click OK. That should work.
It is also possible that you have a JAR file located somewhere in your project folders (I had copied the Admob JAR file into my src folder) and THEN added it as a Java Path Library. It does not show up under the Package Explorer, so you don't notice it, but it does get counted twice, causing the dreaded Dalvik error 1.
Another possible reason could be package name conflicts. Suppose you have a package com.abc.xyz and a class named A.java inside this package, and another library project (which is added to the dependency of this project) which contains the same com.abc.xyz.A.java, then you will be getting the exact same error. This means, you have multiple references to the same file A.java and can't properly build it.
I had the same issue, I'm using the ADT 20.0.3.
Steps I followed to resolve this.
Remove all the jar in project/lib folder and reference them as external jars.
Check android dependencies/reference libraries in project for duplicates,
I've dealt with this problem when using Sherlock ActionBar library in my project. You could do the following step, it's work for me.
Right click to your project, select properties.
A dialog will show up, select 'Java build path' on the left menu.
Remove 'Android dependencies' and 'Android private libraries' on the right panel then click OK
Clean your project (select menu Project --> Clean)
Right click your project, select Android Tools -> Fix project properties
Clean project once again.
Restart your computer
Open eclipse and Export apk
Hope that will help you.

How to import an existing android Project into another android project

i want to import an existing Android Project(a small App that should be added to another Android Project soon) into another Android Project in order to test.
I tried several things for example:
export the first project als jar and add the external jar to build path of the second
added the first project to the second in the build path of the second project
but nothing worked
and i did not forget to mark the checkbox at "order and Export"
i'll be very happy, if anyone could help me ;)
hannes
Right click on your project Build Path>Configure Build Path> "Select prject tab"
then add the project :D
Hope it helps
Have fun
there are a couple of different solutions imo.
If applicable - you could mark the first small project as a library and just add it to the newer project (properties -> android -> checkbox/add lib)
OR
You access the app if its already installed on the device
OR
You copy the source code/package to the new project
OR
You compile the old project to a dex file and load the classes/methods via the DexClassLoader
OR
export as JAR file, as you already tried - but you cant export any resources (although there are workarounds if there arent many resources)
Thats all I can think of right now, if you have more specific question to one of the solutions, just ask =)

In eclipse, unable to reference an android library project in another android project

As I was writing up this question I managed to solve it so repeat it here for the benefit of others. Here is the initial problem:
I have created a very simple library project which I want to reference in another project. I have done this previously with no problems so not really sure why it is not working this time. I have:
Flagged the library project via project properties. The default.properties file has this set : android.library=true
In my other project added reference to my library project via project properties. The default.properties file has the reference added as expected ie android.library.reference.1=K:/android_test_ws/applicationRegistrar
The green tick against the referenced library project starts off green and then changes to a red cross.
This implies that there must be something wrong / missing from the library project but I don't know what. My library project on this occasion is MUCH simpler than the previous one I created.
OK Here is the solution which I found when I was looking for the default.properies file of the referencing project (not the library) in my file system. Although the referencing project was in the same eclipse workspace as the library project, the actual files were somewhere else in the file system ie they were'nt in the same parent folder of the library project. As soon as I placed the referencing project in the same physical folder as the library project it all went fine.
I guess that this must be something to do with android using ant underneath the covers.
Edit: The project name needs match the folder name on the file system. What you are seeing in the Project Properties->Android->Library Reference is a relative file system path.
Make Sure both the projects are present in same work space.
To Do it, while importing the projects make sure "copy project into work space" check box is checked.
the same problem will occur if your library project is in different partition from your current workspace. I have the same problem just now. My git source is in C: and I just move my workspace to D: and everything start to collapse.
Simplest way to get the library paths paths correct is to use the GUI from Eclipse to add the library as shown in the following screenshot and let Eclipse take care of putting the correct relative paths in project.properties. Its a common setup to have your library projects hosted at directories vastly different than your main projects that uses the library. This method will work if the "libary project" and the project using it are in the same eclipse "workspace" (they "need not" be in same parent folder):
Please ensure that the library project is marked as "Is Library" - right click on the library project - properties - Android - mark the "Is Library" checkbox - in project.properties of the library project you should have a new entry:"android.library=true. Now add it into the project you want as described in the post below.(the post with image integrated - from Nilesh Pawar).
This bug is referenced several times here 27199, 35786, 36460 & 38052
Maybe by voting for them, it will be fixed one day...
Yet another observation on the same issue.
For me the two projects where on the same parent folder, and were both local inside the workspace. Even then the issue was still happening.
The I edited the "project.properties" file and put the absolute path(with forward slashes '/' for seperator) of the library project. Saved and closed it. Then went to the project properties dialog, removed the library(which was still showing the cross icon but with abs path) and added it back as usual.
Surprisingly the issue is resolved, and the project compiles and runs.
This is really strange and must be a bug with the ADT.
I am using ADT version 20.0.2
when developer referencing the facebook or any other library project then first of all clean the project from eclipse->project->clean project.
that want allow the error of red cross in referencing screen.
For me, I just restart the eclipse and the added library works fine.
I mean first time it showing red marks after adding the library project.
Though eclipse main project and library project are in same workspace folder and no resources files are in outside of the project folder.
So, you can try with to restart your eclipse. Happy coding....
Workaround for me was to
Create a new workspace
Import Library Project in that workspace
Import The desired project in that workspace
Having both project and library project the same target Android OS version
Reference library project in my project
solved my problem
i had the same problem there when i try to change my workspace so this my solution:
import and copy all project data including library project into workspace
delete the old project reference by Right-click on the project-->Properties-->Android-->Library, and select corrupted library(so that waht i call it) and choose Remove
clean project first (to refresh ur project properties)
go to library project Properties-->Android-->Library and check the is library if it does'nt click Apply then OK
if the library project is library is already checked, first Unchecked it then Clean the library project after that do the Step 4 again
go to project that u want the library are in then Right-click on the project-->Properties-->Android-->Library, Add then choose the library project (it should be there) and click Apply then OK
if still doesn't appear clean the project once more time and that should do
Just restart your eclipse. It's solve my problem
When you have a look at the reference-path before and after, it comes from i.e. "C:/workspace/mylib" and goes to "../../mylib" when copied to the correct location, quite interesting.
FYI,
What worked for me was to delete the 'library' projects (the actual projects) from my workspace (without deleting the files), and then re-importing them using the wizard (import existing android project from source code).
Thanks for posting the question.
I had exactly the same problem while integrating Facebook with my Android application. I fixed the issue by moving my development project to the same Windows drive in which library project was located. Somehow Eclipse is unable to read the library project's location properly from default.properties file if it is in a different drive.
Similar to Sufi Khan's post I also solved this issue with a reboot. My case differed in that when I first accessed Properties->Android and added the library I got a lovely green checkmark. When I closed the dialog Eclipse was still showing class-not-found type errors. When I checked the properties again I saw the red X. But Mr. Kahn's solution (delete the bad lib, restart Eclipse, add the lib again) worked fine.
I'm using the 0702 version of the ADT bundle (starts with "cluster", rhymes with "duck").
I followed the accepted answer but also had to make sure my "project.properties" file was readable.
If the file is readonly (checked into source control) eclipse will not edit it. Adding the library reference will succeed, but the change won't be persisted after hitting OK.
If closing the preferences window and reopening in again removes the library you just added, this may be your solution.
In case your library project still doesn't show up try adding library flag in your library project properties
Add android.library=true
project.properties
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system edit
# "ant.properties", and override values to adapt the script to your
# project structure.
#
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
# Project target.
target=android-17
android.library=true

Categories

Resources