简体   繁体   English

如何在Eclipse Java Build Path中添加android-async-http.JAR

[英]How to add the android-async-http.JAR in Eclipse Java Build Path

I'm using Eclipse IDE Mars and the ADT android plugin and the sdk 23; 我正在使用Eclipse IDE Mars和ADT android插件以及sdk 23; I'm trying to call a REST web services from an Android application, I'm following this tutorial tutorial-how-to-call-restful-webservice-in-android-part , after I create a class that create this instances 我正在尝试从Android应用程序调用REST Web服务,在创建创建此实例的类之后,我正在遵循本教程教程-how-to-call-restful-webservice-in-android-part

RequestParams params = new RequestParams();
AsyncHttpClient client = new AsyncHttpClient();

client.get("http://192.168.2.2:9999/useraccount/login/dologin",params ,new AsyncHttpResponseHandler() {

I need to do this imports from the library: 我需要从库中导入:

import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;

I get the following errors 我收到以下错误

1) The project was not built since its build path is incomplete. 1)项目没有建成,因为它的构建路径不完整。 Cannot find the class file for cz.msebera.android.httpclient.HttpResponse. 找不到cz.msebera.android.httpclient.HttpResponse的类文件。 Fix the build path then try building this project 修复构建路径,然后尝试构建此项目

2) The type cz.msebera.android.httpclient.HttpResponse cannot be resolved. 2)无法解析类型cz.msebera.android.httpclient.HttpResponse。 It is indirectly referenced from required .class files LoginActivity.java /CallAre/src/com/example/callare line 1 Java Problem 它是从所需的.class文件间接引用的.LogActivity.java / CallAre / src / com / example / callare第1行Java问题

I added the library following this instrucctions in the tutorial 我在本教程中按照这些说明添加了库

Step 2: Add library to project 

Add below third party library into project’s ‘lib’ folder. You can also download it if you don’t have it with you. 

I added the library by right clicking the "libs" folder in my project then selecting import and then I choose the jar from the location I Downloaded it. 我通过右键单击项目中的“libs”文件夹然后选择import来添加库,然后从我下载它的位置选择jar。

When I go to my Java build Path the library is in the tab Libraries in here there are 3 categories: 当我转到我的Java构建路径库时,库在选项卡库中有3个类别:

Android 6.0
Android Dependencies
Android Private Libraries 
   ---android-async-http-1.4.9.jar   <-- this is my library

I tried clicking the library in my project and choose add to build path after I did this I checked the Java Build Path again and my library was inside the folder Android 6.0 like this 我尝试单击我项目中的库并选择添加到构建路径后,我再次检查了Java Build Path,我的库位于Android 6.0文件夹中,就像这样

Android 6.0
   ---android-async-http-1.4.9.jar   <-- this is my library
Android Dependencies
Android Private Libraries 
   ---android-async-http-1.4.9.jar   <-- this is my library

But when I check the package explorer my library wasn't in the android 6.0 folder, it was in a new created folder called Referenced Libraries. 但是当我检查包浏览器时,我的库不在android 6.0文件夹中,它位于一个名为Referenced Libraries的新创建文件夹中。

I checked a few questions and videos about how to add a library in eclipse in an Android project and the method was the same that i followed to added it. 我查看了一些关于如何在Android项目中在eclipse中添加库的问题和视频,方法与我添加它的方法相同。

EDIT 1: 编辑1:

I added this jar httpclient-4.4.1.1.jar from this maven repo https://repo1.maven.org/maven2/cz/msebera/android/httpclient/ and now I have the following problems: 我从这个maven repo https://repo1.maven.org/maven2/cz/msebera/android/httpclient/添加了这个jar httpclient-4.4.1.1.jar,现在我遇到了以下问题:

1) The method onFailure(int, Throwable, String) of type new AsyncHttpResponseHandler(){} must override or implement a supertype method 1)new AsyncHttpResponseHandler(){}类型的onFailure(int,Throwable,String)方法必须覆盖或实现超类型方法

2) The method onSuccess(String) of type new AsyncHttpResponseHandler(){} must override or implement a supertype method 2)new AsyncHttpResponseHandler(){}类型的onSuccess(String)方法必须覆盖或实现超类型方法

3) The type new AsyncHttpResponseHandler(){} must implement the inherited abstract method AsyncHttpResponseHandler.onFailure(int, Header[], byte[], Throwable) 3)新类型AsyncHttpResponseHandler(){}必须实现继承的抽象方法AsyncHttpResponseHandler.onFailure(int,Header [],byte [],Throwable)

4) The type new AsyncHttpResponseHandler(){} must implement the inherited abstract method AsyncHttpResponseHandler.onSuccess(int, Header[], byte[]) 4)新的AsyncHttpResponseHandler(){}类型必须实现继承的抽象方法AsyncHttpResponseHandler.onSuccess(int,Header [],byte [])

I don't know if I still have to add more jars because I'm not using Maven, I would like to know how can I add a dependency from the main library I wanted to install in firts place this one android-async-http.JAR that I downloaded from this page http://loopj.com/android-async-http/ and let maven install the necesary jars, I'm using Eclipse IDE Mars, 我不知道是否还需要添加更多的jar,因为我没有使用Maven,我想知道如何从主库中添加依赖项我想安装在firts这个android-async-http.JAR我从这个页面http://loopj.com/android-async-http/下载并让maven安装必需的jar,我正在使用Eclipse IDE Mars,

How can I do this? 我怎样才能做到这一点? 1) I can't seem to find the dependency so far the website just say this 1)到目前为止,我似乎无法找到依赖性,网站只是这样说

Installation & Basic Usage

Add maven dependency using Gradle buildscript in format

dependencies {
  compile 'com.loopj.android:android-async-http:1.4.9'
}

2) Do I need to install M2Eclipse plugin? 2)我需要安装M2Eclipse插件吗? 3) I already have a Android application project created in eclipse, if I install this plugin I would have to create a new project (it would'nt be a problem because I was doing just a tutorial) 3)我已经在eclipse中创建了一个Android应用程序项目,如果我安装这个插件,我将不得不创建一个新项目(这不会是一个问题,因为我只是在做一个教程)

you must download this jar cz.msebera.android and then import to your project 你必须下载这个jar cz.msebera.android ,然后导入你的项目

if you using android studio just using compile 'cz.msebera.android:httpclient:4.3.6' in your .gradle depedencies 如果你使用android工作室只是在.gradle依赖项中使用编译'cz.msebera.android:httpclient:4.3.6'

hope it help 希望它有所帮助

You need to add all the required jars. 您需要添加所有必需的罐子。 Better use Maven for dependency management. 更好地使用Maven进行依赖关系管理。 The particular class can be found from jar here https://repo1.maven.org/maven2/cz/msebera/android/httpclient/ 特定类可以在jar中找到https://repo1.maven.org/maven2/cz/msebera/android/httpclient/

You might still get error for other classes after the current one is resolved. 解决当前类后,您可能仍会遇到其他类的错误。 Know your dependency and use Maven for better management. 了解您的依赖关系并使用Maven进行更好的管理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM