Android Using Jar Files - java

So I'm trying to use the jReddit wrapper class because I am developing a reddit app on the android. Here is what I did:
I first went to jreddit and downloaded as a zip
Then I went to eclipse, made a project and copied the files from the extracted folder into the new project. Here's a picture of what it looks like:
Then I used the build.xml from here and "Ran as Ant" to create a jar file in the dist folder as you can see above
I made my android project and copied the jar file into the lib folder and built the path. The project looks like this:
Finally, here is my MainActivity.java. Sorry, I couldn't format the code properly on here
There are no errors, so I can run it on the android. However, when I click the login button to activate the function call onClickBtn, before it can even get into the function it throws an error saying: Could not find class 'im.goel.jreddit.user.User', referenced from method com.example.reddit.MainActivity.onClickBtn
Did I not import this jar in correctly or am i just not using it properly? Why is it compiling fine like it can see the user class but when run on the android it doesn't know what it is?

Extract the contents to the same folder as your other classes. Usually src.
Or
Go to project properties (Alt + Enter) and select Java Build Path (Left panel). Then select Libraries (Top middle). Click the Add External JARs button and select your jar.

Related

How to import source files in Java to use in another project

I have been writing a project in Java that I've called NHL2 and at this point in the development I've decided to try to incorporate wheels which can be found here. I've downloaded and unzipped the folder, and tried to import the files in several different ways. In Eclipse I've tried right-clicking the NHL2 project and importing it. The files get inserted into certain places in the project but when I type import wheels.etc.* for instance, it gives me an error and says it cannot resolve the import. So I tried deleting the imported files, right-clicking the package containing my files, which is also NHL2, and running the import command through there. Again, same basic problem.
I've also tried just creating a whole separate project titled wheels and importing there. This seems to be fine and the wheels project itself has no errors, but still I cannot import those files in my NHL2 project. I've tried looking up YouTube videos and other stackoverflow questions because this seems like it's just so basic that it should have been answered by now, but I can't find it.
Create a new Folder in your Project, e.g. called "lib"
Copy the wheels.zip into that Folder
Open the properties of your Project (Alt-Enter on the Project)
Select "Java Build Path"
Select the Register Card "Libraries"
Click "Add JARs"
Select "Yourproject/lib/wheels.zip"
Click "OK" then again "OK"
Though it is no jar file (but a zip) it works. I tested it.
This is because the zip contains the class files and the source files as well.

Trouble making executable jar

When I try to make an executable jar in netbeans I get this error
C:\lwjgl\lwjgl-2.8.5\res is a directory or can't be read. Not copying the libraries. Not copying the libraries.The res folder holds files like jpgs and wavs that the program relies on to function. I'm using lwjgl, would that be part of the problem? What could be causing this?
try this
Right click on your project folder and click on >>>>clean and
build<<<<
right click on your project folder click on >>>Properties<<<< you
should see the location of your project folder normally this should
be in your documents folder under NetbeansProject folder. locate
your project name folder inside is a folder called >>>dist<<< in
there you should find your project name with a small java cafe
image which is your jar file.

Use .jar with referenced file paths in other project

I have 2 Java projects, one is a Web Project in NetBeans and the other is a Java Project in Eclipse.
Just to know, the Java Project from Eclipse is used by the Web Project in NetBeans as a library (.jar)
Situation:
1. Java Project from Eclipse has the following structure:
And inside the src, there is a class that uses the file1, file2, etc in some method using global variables like this:
public static final String PATH_ONE = "./files/file1.xml";
public static final String PATH_TWO = "./files/file2.xml";
...
Finally, when I test the method in some main() class everything works good.
2. Web Project from NetBeans has a jar reference to the above library and If everything works good, then the web project will be able to execute the method that uses the global variables without problems from the library project.
Problem:
When I run the web project and I want to invoke the method from my library that uses the above xml files from it, for some reason, NetBeans or the project (I don't certainly know) looks for the path and fails in Exception because the path can not be found (It seems that tries to find the path in the web project and not in the library one).
How can I solve this issue? It sounds simple but I don't want to change my structure, load them as a resource or transfer files from one project to another and use external paths to make this work because I just make a recreation of the situation but I am working with lots of files with different folders and paths too.
If you unzip your jar you can't find your folder file because not is included in your classpath.
You can See .classpath file and the folder isn't. For these reason is FileNotFoudnException.
You can to add how source folder in Eclipse ID:
1. Right click in your project/Build Path/ New source folder
Create the source folder . Then you can add a new package with the name Folder.
Your project:
src
resources
folder
resource1.xml
resource2.xml
2. Modify your java project.
public static final String PATH ="/folder/resource1.xml";
Now, if you try to unzip the jar, you can see that the folder was added in the .classpath.
It works for me. I tried to paste image but i'm new user.

Required imports to execute qrcode?

am trying to encode the values given in an Text View into an QR code at the click of a button.
i downloaded zing 1.6.zip and don't know which one to import among all the folders for my process
i try with this website http://www.onbarcode.com/products/android_barcode/barcodes/qrcode.html
but nothing went good with it, what class files i need to import in order to execute the above code
Add the OnBarcode.AndroidBarcode.jar file to the libs directory of your android project.
Then make sure you add it to your classpath. If you're in eclipse, you can paste the file in the libs directory. Then right click it -> Build Path -> Add to Build Path.
At that point you can start using it:
QRCode barcode = new QRCode();
And again, in eclipse, as long as you have the jar file on your build path, can do a ctrl+shift+O to fix imports and pull in the correct class imports.

Eclipse WTP: "The import ___ cannot be resolved for" error in a JSP file for a class defined in project

A Visual Studio user struggling w/ Eclipse...
I imported a set of servlets/JSPs into a project in Oracle Workshop for Weblogic. /page.jsp has the following import statement:
import="com.foo.bar.*"
Eclipse is displaying an error:
The import com cannot be resolved.
The class that implements the above import is in /WEB-INF/src but I don't know how to build the class in Eclipse to resolve that error. I assumed Eclipse would automagically build the .java file and place the output in /WEB-INF/classes, but it's not doing that.
It could be that I haven't structured my project directories correctly so perhaps that's why Eclipse isn't building my source. Any suggestions? How can I get this to work?
First of all, /WEB-INF/src is a rather strange place to keep your java sources; you may want to move them out of /WEB-INF (into /src in project root, for example)
Either way, you need to tell Eclipse where your sources are and where you want classes built to. It's done in project properties dialog:
Right-click on your project in Eclipse, select Properties
Click on Java Build path on the left
Click source tab on the right
Click Add Folder button and add your source folder (/WEB-INF/src or wherever you moved it to)
Ensure Allow output folders for source folders is checked below
Under newly added source path select output folder and point it to /WEB-INF/classes or other location of your choice.

Categories