Convert an java file into android program - java

hi i am a new android developer. When i am searching for a logic related to my app in google, i found a java application which is related to my android app. After making some changes i succeded in getting output, but i need the code to be in an android based project. When i change to convert it i get lot of errors, is there any possible way to convert the java application into an android app by including any external jar file..... The java application is just a part of my android app, based on that i have to develop more so pls help me....
thanx in Advance

If you intend to include external Java code via .jar files, that is supported in Android. Just put the file into the libs/ directory of your Android project and use the classes as you would somewhere else.

If you are using Eclipse IDE, this might help:
After including the .jar files in the libs/ folder, right click on the required .jar file and select "build path", then click on "add to build path". After doing this, u'll notice that the .jar file is added in the "Referenced libraries" in your project. Once done, you are all good to go and import methods from these files. Hope that helps you remove your errors. Happy coding. :)

Related

Jar file from desktop libgdx project in netbeans

How can I get a jar file from a desktop libgdx project in netbeans?
I know it's a bit late and you've probably figured it out by now, but I'll still answer this for those who don't know.
Right click on your desktop project
Go to the "Tasks" menu
Click "dist"
This will create a standalone JAR file in <pathToYourProject>\desktop\build\libs called desktop-1.0.jar (or something like that).
I don't know if that's the proper way to do it, but it's the only one that worked for me.
I have no experience with this but you should be able to unpack/extract the jar file and then load then load the project into Netbeans.
If it's a gradle project.
If it's not search further since I do not know Netbeans.
Import it with Android Studio and work with my favorite IDE. Choose import none android studio project.

How do I add this Change Log library to my current Android project in Eclipse?

Okay, so I'm having difficulties implementing this Change log library into my android app in eclipse: https://github.com/gabrielemariotti/changeloglib
I tried using the clone url and importing the library into eclipse and then going into the properties of my android project and adding it as a library but that didn't work. I do not have Maven installed nor do I know anything about it. Is there a way I can just get a jar of this library somewhere? Can someone please help me? Thank you!
Its most likely not setup as an Android Library project and that is why it can't be accessed that way.
You can create the jar yourself though by using: https://stackoverflow.com/a/11289115/1784299 eclipse itself or running the jar command in a terminal. (Eclipse might be a little more user friendly if you don't use the terminal.
I would however highly recommend learning how to incorporate Maven in your projects because it is a huge time saver. If you migrate to Android Studio then Maven will become your best friend.
I answer here to help other devs with the same issue.
The library is built with the Android Studio folder structure.
I highly recommend to use the gradle build system to work.
Hovewer, you can build it locally with Eclipse.
All required steps are described here:
https://github.com/gabrielemariotti/changeloglib/blob/master/doc/BUILD.md#reference-this-project-as-a-library-in-eclipse.
It can be valid for a lot of libraries.
Eclipse uses src and res as source folders. Android Studio instead uses src/main/java and src/main/res as source folders.
So you have to mark the java folder as source (right click on folder -> Build-Path -> use as source folder)

Adding external package to Android

I have pretty much no experience with Java so I apologies if I'm not too clear.
I'm trying to create an Android application that uses another package. I only have the source code .java files from the package, which are all part of com.X.Y
I have saved this in a folder called "Database" which I have zipped and added to the build path, so it now appears under "referenced libraries" in Eclipse. However I don't know how to include this, it's not finding import com.X.Y, and I am unsure of what to do next.
I'm a little over my depth in this project, any help would be greatly appreciated
Create a folder structure com/X/Y within your source folder and put your .java file inside of that
Step #1: Move the classes out of "Database" and into the main source tree of your project.
Step #2: There is no step #2.
I strongly recommend that you step away from Android for a while and learn Java separately. There are tons and tons of materials to help you learn Java, including lots of free stuff online. Here is a blog post where I point out a number of topics in Java that Android developers need to learn.
If you want to include those files as an external library I would look at creating a proper jar of the compiled code you want to include instead of just zipping up the source. For you the easiest way would probably be to create a second project in Eclipse, compile it and use the resulting jar.
Once you have the jar, put it in the libs subdir of your Android project. I believe that's enough to get the Android ant target to work...although for Eclipse to be happy I believe you will also need to add it to your Java Build Path.
Or if you are hell bent on just including raw source you may as well just copy/paste the entire package source into your android source directory.

Integrating BlackBerry application with Flurry

Has anyone been able to successfully integrate Flurry with a BlackBerry mobile application? I have imported the FlurryAgent.jar into my project, yet when I go to run the application I am given the error "Module 'FlurryAgent' not found." I have tried the following:
Preverifying the .jar file
Adding the .jar file to the build path of a library project (that my main project references)
It is still not working for me after trying the above - I'm getting ready to pull my hair out, there really isn't a helpful guide to do this.
Thanks!
In your project properties, go to the Java Build Path section, and then the Order and Export Tab. Make sure the check box for the Flurry component is checked.
That solved it for me.
Flurry was working fine for me in an application I did a year ago. I just added the FlurryAgent.jar file to the build path and then called FlurryAgent.onEvent(String);
I was using NetBeans IDE with Blackberry JDE 4.5
The supplied jar is already preverified, so that should have no effect. Mugur is right that the flurry jar must be included in the build path of the application project and must be included in the built application.
We (Localytics) provide our client libraries in source code to make integration with BlackBerry much, much easier.
We compete with Flurry, but you might want to give it a try: http://wiki.localytics.com

How can I install httpclient and other libraries in Java so I can use them in Eclipse?

I'm a new Java developer I've only ever done PHP in the past and all the functions I needed to use were built into PHP. This doesn't seem to be the case with Java though!
I downloaded Eclipse and wrote a hello world and some other things and everything is working great for me! I downloaded httpclient (from http://hc.apache.org/downloads.cgi) and I can see two files, httpclient-4.0.2.jar and httpmime-4.0.2.jar but I'm not sure how I can add them into my program and start using them to build something with!
Any help would be appreciated so much and I'm sorry if this comes off as a trolling question of sorts, I'm really new to this!
Hi in any environment weather it be eclipse, jdeveloper, intellj, netbeans or commandline you need to add the downloaded jar files to the classpath/libraries. This is so the JVM know where to look for external libraries.
In Eclipse in the project explorer right click on the root project and go to properties. Then in the left hand list go to Java build path, once selected go to libraries then go to add external libraries. Once selected they should appear in the list next to the button.
hope this helps.
In Eclipse, right click on your project in the Package Explorer and choose Build Path > Add External Archives... Navigate to your jar files, select them, and click Open.

Categories