我正在尝试使用 wamp 连接到数据库,但它在 android studio.How 中抛出文件未找到异常来解决这个问题?

i am trying to connect to database using wamp but it throws file not found exception in android studio.How to solve this?

所以我已经配置了 php 文件,我的 wamp 尝试连接到数据库但是它抛出一个错误我什至保留了网络安全证书但仍然抛出错误。

尝试过的解决方案 1.新增android:usesCleartextTraffic="true"。 2.change地址转ipv4地址。 3.Added 安全文件 清单 xml:

android:networkSecurityConfig="@xml/network_security_config";

network_security_config.xml:

<?xml version="1.0" encoding="utf-8"?>
<network-security-config xmlns:android="http://schemas.android.com/apk/res/android">
<debug-overrides>
    <trust-anchors>
        <certificates src="user" overridePins="true"/>
    </trust-anchors>
</debug-overrides>
</network-security-config>

错误:


W/IInputConnectionWrapper: finishComposingText on inactive InputConnection
D/NetworkSecurityConfig: Using Network Security Config from resource network_security_config debugBuild: true
W/System.err: java.io.FileNotFoundException: http://10.0.2.2/login.php
        at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:250)
        at com.example.mysqltest.BackgroundWorker.doInBackground(BackgroundWorker.java:46)
        at com.example.mysqltest.BackgroundWorker.doInBackground(BackgroundWorker.java:19)
        at android.os.AsyncTask.call(AsyncTask.java:304)
        at java.util.concurrent.FutureTask.run(FutureTask.java:237)
        at android.os.AsyncTask$SerialExecutor.run(AsyncTask.java:243)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
        at java.lang.Thread.run(Thread.java:761)
D/EGL_emulation: eglMakeCurrent: 0x9d285120: ver 2 0 (tinfo 0x9d2831f0)
D/EGL_emulation: eglMakeCurrent: 0x9d285120: ver 2 0 (tinfo 0x9d2831f0)
W/InputEventReceiver: Attempted to finish an input event but the input event receiver has already been disposed.
Process 13292 terminated.

您正在尝试连接到 127.0.0.1 而不是 10.0.0.2 10.0.0.2是设备的localhost,显然文件不在设备上

您需要更新 /etc/hosts 文件以反映 localhost as 127.0.0.1 否则设备只会尝试连接到自身

http://10.0.2.2/login.php

而不是使用 10.0.2.2 使用您的 IPv4 地址并添加您的端口号虽然对我有用