尝试使用 volley 连接到 localhost json 服务器时出现问题

如何解决尝试使用 volley 连接到 localhost json 服务器时出现问题

我对如何连接到我的 localhost json 服务器 (localhost:3000) 感到非常困惑。我编码时总是出错:

public void onClick(View v) {
                // Instantiate the RequestQueue.
                RequestQueue queue = Volley.newRequestQueue(MainActivity.this);
                String url ="http://localhost:3000/posts";

// Request a string response from the provided URL.
                StringRequest stringRequest = new StringRequest(Request.Method.GET,url,new Response.Listener<String>() {
                            @Override
                            public void onResponse(String response) {
                                // display the first 500 characters of the response string.
                                mTextViewResult.setText("Response is: "+ response.substring(0,500));
                            }
                        },new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        mTextViewResult.setText("That didn't work!");
                    }
                });

// Add the request to the RequestQueue.
            queue.add(stringRequest);

结果总是“那行不通”。我在我的本地主机中使用了一个认配置正确安装的 json 服务器,并在我的智能手机连接到 PC 的情况下启动了该应用程序。这是日志猫:

2021-06-30 10:36:44.474 27870-27870/? I/issage.version: Late-enabling -Xcheck:jni
2021-06-30 10:36:44.509 27870-27870/? E/issage.version: UnkNown bits set in runtime_flags: 0x8000
2021-06-30 10:36:44.510 27870-27870/? I/issage.version: Reinit property: dalvik.vm.checkjni= false
2021-06-30 10:36:44.534 27870-27870/? E/libc: Access denied finding property "runtime.mmitest.isrunning"
2021-06-30 10:36:44.538 27870-27870/? D/ActivityThread: Attach thread to application
2021-06-30 10:36:44.710 27870-27870/fr.apprentissage.version2 I/issage.version: QarthPatchMonintor::Init
2021-06-30 10:36:44.710 27870-27870/fr.apprentissage.version2 I/issage.version: QarthPatchMonintor::StartWatch
2021-06-30 10:36:44.710 27870-27870/fr.apprentissage.version2 I/issage.version: QarthPatchMonintor::WatchPackage: /data/hotpatch/fwkhotpatch/
2021-06-30 10:36:44.710 27870-27870/fr.apprentissage.version2 I/issage.version: QarthPatchMonintor::CheckAndWatchPatch: /data/hotpatch/fwkhotpatch/fr.apprentissage.version2
2021-06-30 10:36:44.710 27870-27870/fr.apprentissage.version2 I/issage.version: QarthPatchMonintor::CheckAndWatchPatch: /data/hotpatch/fwkhotpatch/all
2021-06-30 10:36:44.710 27870-27870/fr.apprentissage.version2 I/issage.version: QarthPatchMonintor::Run
2021-06-30 10:36:44.711 27870-27904/fr.apprentissage.version2 I/issage.version: QarthPatchMonintor::Reading
2021-06-30 10:36:44.711 27870-27904/fr.apprentissage.version2 I/issage.version: QarthPatchMonintor::CheckNotifyEvent
2021-06-30 10:36:44.711 27870-27904/fr.apprentissage.version2 I/issage.version: QarthPatchMonintor::CheckNotifyEvent before read
2021-06-30 10:36:44.712 27870-27890/fr.apprentissage.version2 I/HwApiCachemangerEx: apicache path=/storage/emulated/0 state=mounted key=fr.apprentissage.version2#10224#256
2021-06-30 10:36:44.712 27870-27890/fr.apprentissage.version2 I/HwApiCachemangerEx: apicache path=/storage/9016-4EF8 state=mounted key=fr.apprentissage.version2#10224#256
2021-06-30 10:36:44.714 27870-27890/fr.apprentissage.version2 I/HwApiCachemangerEx: apicache path=/storage/emulated/0 state=mounted key=fr.apprentissage.version2#10224#0
2021-06-30 10:36:44.714 27870-27890/fr.apprentissage.version2 I/HwApiCachemangerEx: apicache path=/storage/9016-4EF8 state=mounted key=fr.apprentissage.version2#10224#0
2021-06-30 10:36:44.719 27870-27890/fr.apprentissage.version2 I/AwareBitmapCacher: init processName:fr.apprentissage.version2 pid=27870 uid=10224
2021-06-30 10:36:44.745 27870-27905/fr.apprentissage.version2 E/AwareLog: AtomicFileUtils: readFileLines file not exist: android.util.AtomicFile@347be87
2021-06-30 10:36:44.795 27870-27870/fr.apprentissage.version2 V/ActivityThread: callActivityOnCreate
2021-06-30 10:36:44.822 27870-27870/fr.apprentissage.version2 V/HwWidgetFactory: : successes to get AllImpl object and return....
2021-06-30 10:36:44.857 27870-27870/fr.apprentissage.version2 I/OverScrollerOptimization: start init SmartSlideOverScroller and get the overscroller config
2021-06-30 10:36:44.857 27870-27870/fr.apprentissage.version2 I/OverScrollerOptimization: get the overscroller config
2021-06-30 10:36:44.897 27870-27870/fr.apprentissage.version2 W/issage.version: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist,reflection,allowed)
2021-06-30 10:36:44.898 27870-27870/fr.apprentissage.version2 W/issage.version: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist,allowed)
2021-06-30 10:36:45.025 27870-27870/fr.apprentissage.version2 D/ActivityThread: add activity client record,r= ActivityRecord{4615ed2 token=android.os.BinderProxy@1e8aff0 {fr.apprentissage.version2/fr.apprentissage.version2.MainActivity}} token= android.os.BinderProxy@1e8aff0
2021-06-30 10:36:45.069 27870-27916/fr.apprentissage.version2 D/HiTouch_PressGestureDetector: onAttached,package=fr.apprentissage.version2,windowType=1,mHiTouchRestricted=false
2021-06-30 10:36:45.105 27870-27906/fr.apprentissage.version2 I/iGraphics: [0020080c] pn: fr.apprentissage.version2,p: 27870
2021-06-30 10:36:45.105 27870-27906/fr.apprentissage.version2 I/iGraphics: [0030080c] no spt app: fr.apprentissage.version2
2021-06-30 10:36:45.119 27870-27906/fr.apprentissage.version2 D/mali_winsys: EGLint new_window_surface(egl_winsys_display *,void *,EGLSurface,EGLConfig,egl_winsys_surface **,EGLBoolean) returns 0x3000
2021-06-30 10:36:45.141 27870-27906/fr.apprentissage.version2 W/Gralloc3: mapper 3.x is not supported
2021-06-30 10:36:45.267 27870-27870/fr.apprentissage.version2 I/HwViewRootImpl: removeInvalidNode jank list is null
2021-06-30 10:36:46.690 27870-27870/fr.apprentissage.version2 W/Settings: Setting device_provisioned has moved from android.provider.Settings.Secure to android.provider.Settings.Global.
2021-06-30 10:36:46.690 27870-27870/fr.apprentissage.version2 V/HiTouch_HiTouchSensor: User setup is finished.
2021-06-30 10:36:46.795 27870-27870/fr.apprentissage.version2 V/AudioManager: querySoundEffectsEnabled...
2021-06-30 10:36:46.810 27870-27944/fr.apprentissage.version2 D/NetworkSecurityConfig: No Network Security Config specified,using platform default
2021-06-30 10:36:49.722 27870-27870/fr.apprentissage.version2 D/AwareBitmapCacher: handleInit switch not opened pid=27870
2021-06-30 10:36:54.409 27870-27870/fr.apprentissage.version2 I/HwViewRootImpl: removeInvalidNode all the node in jank list is out of time
2021-06-30 10:37:16.712 27870-27870/fr.apprentissage.version2 W/IInputConnectionWrapper: getExtractedText on inactive InputConnection
2021-06-30 10:37:16.716 27870-27870/fr.apprentissage.version2 W/IInputConnectionWrapper: getTextBeforeCursor on inactive InputConnection
2021-06-30 10:37:17.306 27870-27906/fr.apprentissage.version2 W/libEGL: EGLNativeWindowType 0x6f64222450 disconnect Failed
2021-06-30 10:37:17.317 27870-27870/fr.apprentissage.version2 V/ActivityThread: Handle window ActivityRecord{4615ed2 token=android.os.BinderProxy@1e8aff0 {fr.apprentissage.version2/fr.apprentissage.version2.MainActivity}} visibility: false
ntissage.version2 I/HwViewRootImpl: removeInvalidNode all the node in jank list is out of time
    2021-06-30 10:00:38.304 23526-23526/fr.apprentissage.version2 V/AudioManager: querySoundEffectsEnabled...

非常感谢你们!

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?
Java在半透明框架/面板/组件上重新绘画。
Java“ Class.forName()”和“ Class.forName()。newInstance()”之间有什么区别?
在此环境中不提供编译器。也许是在JRE而不是JDK上运行?
Java用相同的方法在一个类中实现两个接口。哪种接口方法被覆盖?
Java 什么是Runtime.getRuntime()。totalMemory()和freeMemory()?
java.library.path中的java.lang.UnsatisfiedLinkError否*****。dll
JavaFX“位置是必需的。” 即使在同一包装中
Java 导入两个具有相同名称的类。怎么处理?
Java 是否应该在HttpServletResponse.getOutputStream()/。getWriter()上调用.close()?
Java RegEx元字符(。)和普通点?