Android Volley没有调用onResponse或onErrorResponse方法

Android Volley没有调用onResponse或onErrorResponse方法,android,android-volley,Android,Android Volley,Volley未在调试和正常运行模式下进入onResponse或onErrorResponse方法。 最后一个日志是: Request is: https://www.google.com/ 这是我的主要活动。课堂 package com.example.myapplication; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; impor

Volley未在调试和正常运行模式下进入
onResponse
onErrorResponse
方法。 最后一个日志是:

Request is: https://www.google.com/
这是我的主要活动。课堂

package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;

import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;

import org.json.JSONObject;

public class MainActivity extends AppCompatActivity {

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

        findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                String urlGoogle = "https://www.google.com/";

                Log.println(Log.INFO, null, "Request is: " + urlGoogle);

                JsonObjectRequest jsonObjectRequest = new JsonObjectRequest
                        (Request.Method.GET, urlGoogle, null, new Response.Listener<JSONObject>() {

                            @Override
                            public void onResponse(JSONObject response) {
                                Log.println(Log.INFO, null, "Response is: " + response.toString());
                            }
                        }, new Response.ErrorListener() {

                            @Override
                            public void onErrorResponse(VolleyError error) {
                                Log.println(Log.INFO, null, "Error response is: " + error.toString());
                            }
                        });
            }
        });
    }
}
日志:

编辑:

我使用返回JSON的站点进行了测试。 例如:

EDIT2:

我用不同的网络交换设备,它是一样的

EDIT3:


我把截击降到了1.0.0版本。没有更改。

您只是创建了一个JsonObjectRequest对象,但没有执行它,要执行请求,您需要将它添加到请求队列中- 在初始化JsonObjectRequest之后添加这两行-

    RequestQueue queue = Volley.newRequestQueue(this);
    queue.add(jsonObjectRequest);

您只是创建了一个JsonObjectRequest对象,但没有执行它,要执行请求,需要将它添加到请求队列中- 在初始化JsonObjectRequest之后添加这两行-

    RequestQueue queue = Volley.newRequestQueue(this);
    queue.add(jsonObjectRequest);

因为你没有从Google.com得到任何回应。尝试实际返回Json或字符串的内容。@Parth我尝试了返回Json的站点,但结果是一样的。@januszj您尝试了哪个站点?你能把它贴出来吗url@varunkr因为你没有从Google.com得到任何回应。尝试实际返回Json或字符串的内容。@Parth我尝试了返回Json的站点,但结果是一样的。@januszj您尝试了哪个站点?你能把它贴出来吗url@varunkr及
04/13 12:50:39: Launching 'app' on Nexus 5X API 29 x86.
$ adb shell am start -n "com.example.myapplication/com.example.myapplication.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Connected to process 30116 on device 'Nexus_5X_API_29_x86 [emulator-5554]'.
Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page.
D/libEGL: Emulator has host GPU support, qemu.gles is set to 1.
W/libc: Unable to set property "qemu.gles" to "1": connection failed; errno=13 (Permission denied)
W/RenderThread: type=1400 audit(0.0:380): avc: denied { write } for name="property_service" dev="tmpfs" ino=8370 scontext=u:r:untrusted_app:s0:c137,c256,c512,c768 tcontext=u:object_r:property_socket:s0 tclass=sock_file permissive=0 app=com.example.myapplication
D/libEGL: loaded /vendor/lib/egl/libEGL_emulation.so
D/libEGL: loaded /vendor/lib/egl/libGLESv1_CM_emulation.so
D/libEGL: loaded /vendor/lib/egl/libGLESv2_emulation.so
W/e.myapplicatio: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed)
W/e.myapplicatio: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed)
D/HostConnection: HostConnection::get() New Host Connection established 0xe0e3cfa0, tid 30149
D/HostConnection: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_vulkan ANDROID_EMU_deferred_vulkan_commands ANDROID_EMU_vulkan_null_optional_strings ANDROID_EMU_vulkan_create_resources_with_requirements ANDROID_EMU_YUV420_888_to_NV21 ANDROID_EMU_YUV_Cache ANDROID_EMU_async_unmap_buffer GL_OES_EGL_image_external_essl3 GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_gles_max_version_3_1 
W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
D/EGL_emulation: eglCreateContext: 0xec56ad20: maj 3 min 1 rcv 4
D/EGL_emulation: eglMakeCurrent: 0xec56ad20: ver 3 1 (tinfo 0xec609c20)
E/eglCodecCommon: glUtilsParamSize: unknow param 0x000082da
    glUtilsParamSize: unknow param 0x000082da
W/Gralloc3: mapper 3.x is not supported
D/HostConnection: createUnique: call
    HostConnection::get() New Host Connection established 0xe0e3e710, tid 30149
D/HostConnection: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_vulkan ANDROID_EMU_deferred_vulkan_commands ANDROID_EMU_vulkan_null_optional_strings ANDROID_EMU_vulkan_create_resources_with_requirements ANDROID_EMU_YUV420_888_to_NV21 ANDROID_EMU_YUV_Cache ANDROID_EMU_async_unmap_buffer GL_OES_EGL_image_external_essl3 GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_gles_max_version_3_1 
D/eglCodecCommon: allocate: Ask for block of size 0x1000
    allocate: ioctl allocate returned offset 0x3ff803000 size 0x2000
D/EGL_emulation: eglMakeCurrent: 0xec56ad20: ver 3 1 (tinfo 0xec609c20)
I/: Request is: https://www.google.com/
    RequestQueue queue = Volley.newRequestQueue(this);
    queue.add(jsonObjectRequest);