包org.apache.http.client不存在 [英] package org.apache.http.client does not exist

查看:2000
本文介绍了包org.apache.http.client不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图检查登录凭据,但我再次遇到这些错误,并再次,我已经试过了一切。我是新到Android
任何形式的帮助将是AP preciated。如果有实现相同的其他好办法,想知道如何暗示

错误

 错误:(19 30)错误:包org.apache.http.client不存在
错误:(15,23)错误:包org.apache.http不存在
错误:(16,23)错误:包org.apache.http不存在
错误:(17 23)错误:包org.apache.http不存在
错误:(18 30)错误:包org.apache.http.client不存在
错误:(20,37)错误:包org.apache.http.client.entity不存在
错误:(21 38)错误:包org.apache.http.client.methods不存在
错误:(22 35)错误:包org.apache.http.impl.client不存在
错误:(23 31)错误:包org.apache.http.message不存在
错误:(79,22)错误:无法找到符号类的NameValuePair
错误:(85,49)错误:无法找到符号类DefaultHttpClient
错误:(86,21)错误:无法找到符号类HttpPost
错误:(86,45)错误:无法找到符号类HttpPost
错误:(88 44)错误:无法找到符号类UrlEn codedFormEntity
错误:(90,21)错误:无法找到符号类的Htt presponse
错误:(92 21)错误:无法找到符号类HttpEntity
错误:(105,26)错误:无法找到符号类ClientProtocolException
错误:执行失败的任务:应用程序:compileDebugJavaWithJavac。
>编译失败;详情请参见编译器错误输出。
错误:(85,21)错误:无法找到符号类的HttpClient
错误:(81 40)错误:无法找到符号类BasicNameValuePair
错误:(80,40)错误:无法找到符号类BasicNameValuePair
错误:(79,68)错误:无法找到符号类的NameValuePair

MainActivity.java

 包com.tarun.proxy_maar;进口android.app.Dialog;
进口android.app.ProgressDialog;
进口android.content.Intent;
进口android.os.AsyncTask;
进口android.os.Bundle;
进口android.support.v7.app.AppCompatActivity;
进口android.view.Menu;
进口android.view.MenuItem;
进口android.view.View;
进口android.widget.EditText;
进口android.widget.Toast;进口org.apache.http.HttpEntity;
进口org.apache.http.Htt presponse;
进口org.apache.http.NameValuePair;
进口org.apache.http.client.ClientProtocolException;
进口org.apache.http.client.HttpClient;
进口org.apache.http.client.entity.UrlEn codedFormEntity;
进口org.apache.http.client.methods.HttpPost;
进口org.apache.http.impl.client.DefaultHttpClient;
进口org.apache.http.message.BasicNameValuePair;进口java.io.BufferedReader中;
进口java.io.IOException异常;
进口的java.io.InputStream;
进口java.io.InputStreamReader中;
进口java.io.UnsupportedEncodingException;
进口的java.util.ArrayList;
进口的java.util.List;
公共类MainActivity扩展AppCompatActivity {    私人的EditText editTextUserName;
    私人的EditText editTextPassword;    公共静态最后弦乐USER_NAME =USERNAME;    字符串用户名;
    字符串密码;    @覆盖
    保护无效的onCreate(捆绑savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.activity_main);        editTextUserName =(EditText上)findViewById(R.id.editTextUserName);
        editTextPassword =(EditText上)findViewById(R.id.editTextPassword);
    }    公共无效invokeLogin(查看视图){
        。用户名= editTextUserName.getText()的toString();
        。密码= editTextPassword.getText()的toString();        登录(用户名,密码);    }    私人无效登录(最后弦乐用户名,字符串密码){        类LoginAsync扩展的AsyncTask<弦乐,太虚,字符串> {            私人对话loadingDialog;            @覆盖
            在preExecute保护无效(){
                super.on preExecute();
                loadingDialog = ProgressDialog.show(MainActivity.this,请稍等,载入中...);
            }            @覆盖
            保护字符串doInBackground(字符串... PARAMS){
                字符串的uname =参数[0];
                字符串传递=参数[1];                InputStream为= NULL;
                清单<&的NameValuePair GT; namevaluepairs中=新的ArrayList<&的NameValuePair GT;();
                nameValuePairs.add(新BasicNameValuePair(用户名的uname));
                nameValuePairs.add(新BasicNameValuePair(密码,PASS));
                字符串结果= NULL;                尝试{
                    HttpClient的HttpClient的=新DefaultHttpClient();
                    HttpPost httpPost =新HttpPost(
                            http://shaadi.web44.net/hello.php);
                    httpPost.setEntity(新UrlEn codedFormEntity(namevaluepairs中));                    HTT presponse响应= httpClient.execute(httpPost);                    HttpEntity实体= response.getEntity();                    是= entity.getContent();                    读者的BufferedReader =新的BufferedReader(新的InputStreamReader(是,UTF-8),8);
                    StringBuilder的SB =新的StringBuilder();                    串线= NULL;
                    而((行= reader.readLine())!= NULL)
                    {
                        sb.append(行+\\ n);
                    }
                    结果= sb.toString();
                }赶上(ClientProtocolException E){
                    e.printStackTrace();
                }赶上(UnsupportedEncodingException五){
                    e.printStackTrace();
                }赶上(IOException异常五){
                    e.printStackTrace();
                }
                返回结果;
            }            @覆盖
            保护无效onPostExecute(字符串结果){
                字符串s = result.trim();
                loadingDialog.dismiss();
                如果(s.equalsIgnoreCase(成功)){
                    意向意图=新意图(MainActivity.this,UserProfile.class);
                    intent.putExtra(USER_NAME,用户名);
                    完();
                    startActivity(意向);
                }其他{
                    Toast.makeText(getApplicationContext(),无效的用户名或密码,Toast.LENGTH_LONG).show();
                }
            }
        }        LoginAsync LA =新LoginAsync();
        la.execute(用户名,密码);    }
    @覆盖
    公共布尔onCreateOptionsMenu(菜单菜单){
        //充气菜单;如果是present这增加了项目操作栏。
        。getMenuInflater()膨胀(R.menu.menu_main,菜单);
        返回true;
    }    @覆盖
    公共布尔onOptionsItemSelected(菜单项项){
        //处理动作栏项目点击这里。操作栏会
        //自动处理上点击主页/向上按钮,只要
        //你在AndroidManifest.xml中指定一个父活动。
        INT ID = item.getItemId();        // noinspection SimplifiableIfStatement
        如果(ID == R.id.action_settings){
            返回true;
        }        返回super.onOptionsItemSelected(项目);
    }
}


解决方案

这是添加到您的build.gradle:

 安卓{
    useLibraryorg.apache.http.legacy
}

或者使用 HttpURLConnection类类代替。

I am trying to check log in credentials , But I am getting these errors again and again , I have tried everything. I am new to android Any kind of help will be appreciated. If there is other good way to implement same , want to know how to imply

Error

Error:(19, 30) error: package org.apache.http.client does not exist
Error:(15, 23) error: package org.apache.http does not exist
Error:(16, 23) error: package org.apache.http does not exist
Error:(17, 23) error: package org.apache.http does not exist
Error:(18, 30) error: package org.apache.http.client does not exist
Error:(20, 37) error: package org.apache.http.client.entity does not exist
Error:(21, 38) error: package org.apache.http.client.methods does not exist
Error:(22, 35) error: package org.apache.http.impl.client does not exist
Error:(23, 31) error: package org.apache.http.message does not exist
Error:(79, 22) error: cannot find symbol class NameValuePair
Error:(85, 49) error: cannot find symbol class DefaultHttpClient
Error:(86, 21) error: cannot find symbol class HttpPost
Error:(86, 45) error: cannot find symbol class HttpPost
Error:(88, 44) error: cannot find symbol class UrlEncodedFormEntity
Error:(90, 21) error: cannot find symbol class HttpResponse
Error:(92, 21) error: cannot find symbol class HttpEntity
Error:(105, 26) error: cannot find symbol class ClientProtocolException
Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
Error:(85, 21) error: cannot find symbol class HttpClient
Error:(81, 40) error: cannot find symbol class BasicNameValuePair
Error:(80, 40) error: cannot find symbol class BasicNameValuePair
Error:(79, 68) error: cannot find symbol class NameValuePair    

MainActivity.java

package com.tarun.proxy_maar;

import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;


public class MainActivity extends AppCompatActivity {

    private EditText editTextUserName;
    private EditText editTextPassword;

    public static final String USER_NAME = "USERNAME";

    String username;
    String password;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        editTextUserName = (EditText) findViewById(R.id.editTextUserName);
        editTextPassword = (EditText) findViewById(R.id.editTextPassword);
    }

    public void invokeLogin(View view){
        username = editTextUserName.getText().toString();
        password = editTextPassword.getText().toString();

        login(username,password);

    }

    private void login(final String username, String password) {

        class LoginAsync extends AsyncTask<String, Void, String>{

            private Dialog loadingDialog;

            @Override
            protected void onPreExecute() {
                super.onPreExecute();
                loadingDialog = ProgressDialog.show(MainActivity.this, "Please wait", "Loading...");
            }

            @Override
            protected String doInBackground(String... params) {
                String uname = params[0];
                String pass = params[1];

                InputStream is = null;
                List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
                nameValuePairs.add(new BasicNameValuePair("username", uname));
                nameValuePairs.add(new BasicNameValuePair("password", pass));
                String result = null;

                try{
                    HttpClient httpClient = new DefaultHttpClient();
                    HttpPost httpPost = new HttpPost(
                            "http://shaadi.web44.net/hello.php");
                    httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

                    HttpResponse response = httpClient.execute(httpPost);

                    HttpEntity entity = response.getEntity();

                    is = entity.getContent();

                    BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"), 8);
                    StringBuilder sb = new StringBuilder();

                    String line = null;
                    while ((line = reader.readLine()) != null)
                    {
                        sb.append(line + "\n");
                    }
                    result = sb.toString();
                } catch (ClientProtocolException e) {
                    e.printStackTrace();
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                return result;
            }

            @Override
            protected void onPostExecute(String result){
                String s = result.trim();
                loadingDialog.dismiss();
                if(s.equalsIgnoreCase("success")){
                    Intent intent = new Intent(MainActivity.this, UserProfile.class);
                    intent.putExtra(USER_NAME, username);
                    finish();
                    startActivity(intent);
                }else {
                    Toast.makeText(getApplicationContext(), "Invalid User Name or Password", Toast.LENGTH_LONG).show();
                }
            }
        }

        LoginAsync la = new LoginAsync();
        la.execute(username, password);

    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

解决方案

Add that to your build.gradle:

android {
    useLibrary 'org.apache.http.legacy'
}

Or you use the HttpURLConnection class instead.

这篇关于包org.apache.http.client不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆