当前位置: 首页 > 知识库问答 >
问题:

致命异常:线程-5

暴辰龙
2023-03-14

这段代码在leapdroid中运行良好,但我得到了错误模拟器:

2020-06-25 13:43:36.936 14930-14930/?E/DatabaseLesson:runtime_flags中设置了未知位:0x8000 2020-06-25 13:43:54.808 149 30-14998/com.webstates.databaseLesson2 E/AndroidRuntime:致命异常:Thread-5进程:com.webstates.databaseLesson2,PID:14930 java.lang.NoClassDefoundError:解析:loRg/Apache/HTTP/ProtocolVersion失败;在com.android.volle.toolbox.hurlstack.performRequest(hurlstack.java:109)在com.android.volle.toolbox.basicnetwork.performRequest(basicnetwork.java:97)在com.android.volle.networkdispatcher.run(networkdispatcher.java:114)原因:java.lang.ClassNotFoundException:在路径:dexpathlist[[zip文件“在com.android.volle.toolbox.basicnetwork.performrequest(basicnetwork.java:97) 在com.android.volle.networkdispatcher.run(networkdispatcher.java:114)

我的代码是:

package com.webstates.databaselesson2;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Toast;

import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonArrayRequest;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.Volley;

import org.json.JSONArray;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity
{

    String url="https://restcountries.eu/rest/v2/all";
    ArrayList<Item_Data> arrayList;
    ListView listView;
    Button bt1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ReadObjects();
        bt1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Read_From_Url();
            }
        });
        //



    }

    private void Read_From_Url() {


        RequestQueue requestQueue = Volley.newRequestQueue(this);
        JsonArrayRequest jsonArrayRequest=new JsonArrayRequest(Request.Method.GET, url, (String) null, new Response.Listener<JSONArray>() {
            @Override
            public void onResponse(JSONArray response) {
                Toast.makeText(getApplicationContext(),"done",Toast.LENGTH_LONG).show();
            }
        },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        Toast.makeText(getApplicationContext(),"error "+error.getMessage() ,Toast.LENGTH_LONG).show();
                    }
                }
        );
        requestQueue.add(jsonArrayRequest);



/*
        JsonArrayRequest jsonArrayRequest=new JsonArrayRequest(Request.Method.GET, url, (String) null, new Response.Listener<JSONArray>() {
            @Override
            public void onResponse(JSONArray response) {
                Toast.makeText(getApplicationContext(),"done",Toast.LENGTH_LONG).show();
            }
        },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        Toast.makeText(getApplicationContext(),"error "+error.getMessage() ,Toast.LENGTH_LONG).show();
                    }
                }
        );

        Mysingletone.getSingle(getApplicationContext()).add_to_Req(jsonArrayRequest);
*/
    }

    private void ReadObjects() {
        listView=findViewById(R.id.activity_main_listview);
        bt1=findViewById(R.id.activity_main_bt1);
        arrayList=new ArrayList<Item_Data>();

    }
}

共有1个答案

何飞翰
2023-03-14
    <uses-library
        android:name="org.apache.http.legacy"
        android:required="false" />

关于谷歌为什么做出这一改变的更多信息可以在这里获得。

 类似资料: