Importing Java Library JAR into eclipse - android

I'm currently trying to implement a browser with pipelining feature in it. The problem is in order to code the HTTP pipeline, i need the support of a library. I tried to import it to my workspace by using Project - > properties -> Java build path ->addJar. And I was able to add it successfully. But now my problem is, even though it is added to my workspace it doesnt let me run this code. It gives me errors as if I have not imported the library:
package com.test.download;
import java.util.Collections;
import org.factor45.*;
public class Example {
// Execute the request
HttpRequestFuture<String> future = client.execute("hotpotato.factor45.org", 80, request,
new BodyAsStringProcessor());
future.addListener(new HttpRequestFutureListener<String>() {
#Override
public void operationComplete(HttpRequestFuture<String> future) throws Exception {
System.out.println(future);
if (future.isSuccessfulResponse()) {
System.out.println(future.getProcessedResult());
}
client.terminate();
}
});
}
This is available in the same website which provided me the library for the above code. "Here" is the website for your reference. Also you can find the JAR file inside this website.
Please help me to figure out the problem. If you solve this you are a life saver! Thanks in advance!

Try this:
Properties >> Java Build Path >> Libraries >> Add External JARs... Then select the library

Related

Trying to use code from another project by including it in my build path

I'm trying to figure out a way to share code across projets. this is what i did
created a project called sharecode and made the following class
package codelib.com;
public class cShape {
}
made a android project called testsharecode
whent to properties->java build path and clicked on projects at the top.
clicked add, and added sharecode
created a class to try include the cShape class from the sharecode project
package com.example.testsharecode;
import codelib.com
public class parent {
cShape test;
}
On my import i get a error saying
"only a type can be imported, cadelib resolves to a package"
on cShape i get a error saying the def does not exist.
How can project testsharecode use the code in projetc sharecode?
have you tried the following method :
right click on the distination projet, Build Path -> configure build path
chose project then select testsharecode
back in your distiation project now you should be able to use your public classes.
hope this helps

How to setup alljoyn sdk in android?

I am trying to setup two android devices to communicate with each other through wifi. Some of the links I have gone through suggest alljoyn sdk in order to accomplish this.
There is an sdk download but there is no documentation for how to setup environment.
Here is how to set up an AllJoyn SDK development environment with android studio:
Download the SDK from this page. Go for Android Core SDK - release (or debug).
Create a new blank android project.
Create directory <project>/app/src/main/jniLibs and <project>/app/src/main/jniLibs/armeabi.
From alljoyn-15.09.00-rel/java/jar copy alljoyn.jar and from alljoyn-15.09.00-rel/java/lib copy liballjoyn_java.so. The directory to copy from might differ depending on the current version and your release/debug choice.
Put alljoyn.jar in /jniLibs and put liballjoyn_java.so in /jniLibs/armeabi. Should look like this
Right click project -> Open Module Settings -> app -> Dependencies.
With the green [+] button, add a file dependency.
Navigate to <project>/app/src/main/jniLibs/alljoyn.jar and select that jar.
This will add a line in your gradle (compile files('src/main/jniLibs/alljoyn.jar')) that will allow for code completion etc.
In the file where you want to use alljoyn code, include this snippet
/* Load the native alljoyn_java library. */
static {
System.loadLibrary("alljoyn_java");
}
for example:
public class MainActivity extends AppCompatActivity {
/* Load the native alljoyn_java library. */
static {
System.loadLibrary("alljoyn_java");
}
#Override
public void onCreate(Bundle savedInstanceState) {
...
}
}
You can now use the alljoyn SDK. Import classes with
import org.alljoyn.bus.BusAttachment;
import org.alljoyn.bus.BusException;
import org.alljoyn.bus.BusListener;
etc.
If you're more of an eclipse guy, check this official documentation page on how to setup an eclipse environment.

Not able to solve import on com.google.appengine.tools.cloudstorage.GcsFilename Eclipse

I am trying to serve a blob , which take objects from GCS and serve it . In my servlet I need to import:
import com.google.appengine.tools.cloudstorage.GcsFileOptions;
import com.google.appengine.tools.cloudstorage.GcsFilename
I have downloaded Cloud Storage API from this link: https://code.google.com/p/google-api-java-client/wiki/APIs#Cloud_Storage_API
But somehow I am not able to compile my servlet. What am I missing here!!..Can anyone please tell me the steps on how to add this library in web application in Eclipse?
Code which I need to compile:
private GcsFilename getFileName(HttpServletRequest req) {
String[] splits = req.getRequestURI().split("/", 4);
if (!splits[0].equals("") || !splits[1].equals("gcs")) {
throw new IllegalArgumentException("The URL is not formed as expected. " +
"Expecting /gcs/<bucket>/<object>");
}
return new GcsFilename(splits[2], splits[3]);
}
the import is not in any of those jar files but this might help to download the library
https://developers.google.com/appengine/docs/java/googlecloudstorageclient/migrate

Could not find class XXX referenced from method XXX.<YYY>

I'm working on a libGDX project and I have a class called CheerVArachnids that has another inline class which is an event listener. When I run this project on the desktop it works fine. BUT when I run on my Android device, it can't find that inline class and I get the following error:
Could not find class 'com.bbj.cva.CheerVArachnids$PlaceUnitListener', referenced from method com.bbj.cva.CheerVArachnids.<init>
Here are the important parts of my class:
package com.bbj.cva;
public class CheerVArachnids implements ApplicationListener {
class PlaceUnitListener implements EventSubscriber<PlaceUnitEvent> {
#Override
public void onEvent(PlaceUnitEvent event)
{
//
}
}
public CheerVArachnids() {
EventBus.subscribe(PlaceUnitEvent.class, new PlaceUnitListener());
EventBus.subscribe(RemoveScreenObjectEvent.class,
new RemoveScreenObjectListener());
}
}
Any ideas why on Android, at runtime it can't find that inline class?
Since some ADT-Version you have to set which libraries / projects should be exported too.
Project-Propiertes -> Java Build Path -> Order and Export -> Check your Sources and other Libraries you are using.
Do these Export-Settings for your Core- and Android-Project.
Then it should work fine on Android.
In my case, everything worked fine until I installed the new updates for the SDK and Eclipse.
I got an error: "Could not find class..."
I found solution in another stackoverflow site.
I have a similar problem when using external jar (in my case openCSV). The reason I had a problem was due to a change in ADT 17 (or above). What I needed to do to resolve the problem was
In Eclipse go to Properties -> Java build path -> Order and export.
Mark my jar.
Move jar to top of the list.
The solution was found in the following page which reference to a very good article.
First you should: import XXX(Class).java,
If you added external library jar file import them to the LIB folder.
After that:
Right Click to your Project -> Properties -> Java Build Path -> Order and Export(tab) -> select All -> press OK -> Clean your Project.
Hope this solve this issue

Unable to run Bitmap sample code for Android

I am trying to run the sample from :
http://developer.android.com/training/displaying-bitmaps/display-bitmap.html
However I encountered lots of errors like:
Description Resource Path Location Type
BuildConfig cannot be resolved to a variable ImageGridFragment.java /ImageGridActivity/src/com/example/android/bitmapfun/ui line 124 Java Problem
Description Resource Path Location Type
SuppressLint cannot be resolved to a type Utils.java /ImageGridActivity/src/com/example/android/bitmapfun/util line 99 Java Problem
I ran thru Google but could get nothing. Adjusted the android build target to 4.0.3 (15) but still no clue. Anyone ran this sample successfully?
Thanks.
Here is my solution:
1.Create a new class:
package com.example.android.bitmapfun;
public class BuildConfig {
public static final boolean DEBUG = true;
}
2.Comment the lines that contain "SuppressLint":
//import android.annotation.SuppressLint;
// #SuppressLint("NewApi")
Android developer tools r17 brings a feature to Eclipse where a class is auto built at build-time, called BuildConfig, which contains a constant that can be used by the app developer to sense whether the build is a dev build or a production build. This feature appears to be in the Eclipse integration support, so when using IntelliJ, this useful feature is not available
In gen folder with R.java there should be BuildConfig.java if your program compiled successfully.
/** Automatically generated file. DO NOT MODIFY */
package com.example.android.bitmapfun;
public final class BuildConfig {
public final static boolean DEBUG = true;
}
Clean your project and try to launch it again.
It worked for me.
For me also it is not running directly import to eclipse. Just i put comments which lines is showing errors then it is working fine for me. May be it is not a right answer but we can see the application functionality by running the code so i did like that.

Categories

Resources