简体   繁体   English

在Android Studio中找不到Java类

[英]Java class not found in Android Studio

I am building an app which has to log in on a server, once logged in it will show a webview. 我正在构建一个必须登录服务器的应用程序,登录后将显示一个webview。

This is my first time programming in Android, i managed to get all pieces i need for the app working. 这是我第一次在Android中进行编程,我设法获得了应用程序运行所需的所有组件。 But when i am trying to put my code together in Android Studio, i get some Java errors. 但是,当我尝试将代码放到Android Studio中时,出现了一些Java错误。

I didn't get these errors when i was testing my code in Eclipse IDE, it ran perfect. 我在Eclipse IDE中测试代码时没有得到这些错误,它运行得非常完美。

At first Android Studio couldn't find some classes, so i added the jar i needed (httpclient-4.3.5.jar) to the app/src/lib folder. 起初,Android Studio找不到某些类,因此我将所需的jar(httpclient-4.3.5.jar)添加到了app / src / lib文件夹中。 The errors went away, and i could compile and start the app. 错误消失了,我可以编译并启动该应用程序。

However when my sendPost() method is called, my app crashes and gives me errors in my console. 但是,当我的sendPost()方法被调用时,我的应用程序崩溃了,并在控制台中给了我错误。 The method tries to do a simple HTTP request which works perfectly in Eclipse. 该方法尝试执行一个简单的HTTP请求,该请求在Eclipse中非常有效。 This is the error I get: 这是我得到的错误:

Caused by: java.lang.NoClassDefFoundError: org.apache.http.util.TextUtils
at org.apache.http.impl.client.HttpClientBuilder.split(HttpClientBuilder.java:686)
at org.apache.http.impl.client.HttpClientBuilder.build(HttpClientBuilder.java:702)
at org.apache.http.impl.client.HttpClients.createSystem(HttpClients.java:66)
at com.example.loginscreen2.MainActivity.sendPost(MainActivity.java:106)
at com.example.loginscreen2.MainActivity.login(MainActivity.java:52)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at android.view.View$1.onClick(View.java:3818)
at android.view.View.performClick(View.java:4438)
at android.view.View$PerformClick.run(View.java:18422)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)

The line causing this error is : CloseableHttpClient client = HttpClients.createSystem(); 导致此错误的行是: CloseableHttpClient client = HttpClients.createSystem(); I am puzzled, i added the library, Android Studio put the import lines in for me, still it cant find the class? 我很困惑,我添加了库,Android Studio为我添加了导入行,仍然找不到该类?

Does anyone know what might be the problem? 有谁知道可能是什么问题?

EDIT: these are my apps dependencies in the app's build.gradle dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) } 编辑:这些是我的应用程序在build.gradle dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) }

I installed ADT Bundle for Eclipse, within Android project i'm getting the same error there.... 我在Android项目中为Eclipse安装了ADT Bundle,在那里我遇到了同样的错误。

我使用了构建路径选项来导入库,将其删除并将库文件复制到“ libs”文件夹似乎可以解决问题。

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

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