gpt4 book ai didi

java - Android应用程序无法连接到外部apache mysql服务器

转载 作者:行者123 更新时间:2023-12-01 17:36:09 29 4
gpt4 key购买 nike

所以我有一个具有注册功能的应用程序,当用户单击注册时,程序应该连接到 Apache MySQL 服务器并将数据插入 phpMyadmin 数据库,但是我收到下面所述的错误。

logcat:

2020-04-04 21:43:52.035 28854-28854/com.example.blooddonorsystem I/AssistStructure: Flattened final assist data: 3736 bytes, containing 1 windows, 16 views
2020-04-04 21:44:17.157 28854-28854/com.example.blooddonorsystem I/AssistStructure: Flattened final assist data: 3736 bytes, containing 1 windows, 16 views
2020-04-04 21:44:17.407 28854-28854/com.example.blooddonorsystem W/System.err: com.android.volley.NoConnectionError: java.net.SocketException: socket failed: EPERM (Operation not permitted)
2020-04-04 21:44:17.407 28854-28854/com.example.blooddonorsystem W/System.err: at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:177)
2020-04-04 21:44:17.407 28854-28854/com.example.blooddonorsystem W/System.err: at com.android.volley.NetworkDispatcher.processRequest(NetworkDispatcher.java:120)
2020-04-04 21:44:17.407 28854-28854/com.example.blooddonorsystem W/System.err: at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:87)
2020-04-04 21:44:17.407 28854-28854/com.example.blooddonorsystem W/System.err: Caused by: java.net.SocketException: socket failed: EPERM (Operation not permitted)
2020-04-04 21:44:17.407 28854-28854/com.example.blooddonorsystem W/System.err: at java.net.Socket.createImpl(Socket.java:492)
2020-04-04 21:44:17.407 28854-28854/com.example.blooddonorsystem W/System.err: at java.net.Socket.getImpl(Socket.java:552)
2020-04-04 21:44:17.407 28854-28854/com.example.blooddonorsystem W/System.err: at java.net.Socket.setSoTimeout(Socket.java:1180)
2020-04-04 21:44:17.407 28854-28854/com.example.blooddonorsystem W/System.err: at com.android.okhttp.internal.io.RealConnection.connectSocket(RealConnection.java:143)
2020-04-04 21:44:17.407 28854-28854/com.example.blooddonorsystem W/System.err: at com.android.okhttp.internal.io.RealConnection.connect(RealConnection.java:116)
2020-04-04 21:44:17.407 28854-28854/com.example.blooddonorsystem W/System.err: at com.android.okhttp.internal.http.StreamAllocation.findConnection(StreamAllocation.java:186)
2020-04-04 21:44:17.407 28854-28854/com.example.blooddonorsystem W/System.err: at com.android.okhttp.internal.http.StreamAllocation.findHealthyConnection(StreamAllocation.java:128)
2020-04-04 21:44:17.407 28854-28854/com.example.blooddonorsystem W/System.err: at com.android.okhttp.internal.http.StreamAllocation.newStream(StreamAllocation.java:97)
2020-04-04 21:44:17.407 28854-28854/com.example.blooddonorsystem W/System.err: at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:289)
2020-04-04 21:44:17.407 28854-28854/com.example.blooddonorsystem W/System.err: at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:232)
2020-04-04 21:44:17.407 28854-28854/com.example.blooddonorsystem W/System.err: at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:465)
2020-04-04 21:44:17.407 28854-28854/com.example.blooddonorsystem W/System.err: at com.android.okhttp.internal.huc.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:131)
2020-04-04 21:44:17.407 28854-28854/com.example.blooddonorsystem W/System.err: at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:262)
2020-04-04 21:44:17.407 28854-28854/com.example.blooddonorsystem W/System.err: at com.android.volley.toolbox.HurlStack.addBody(HurlStack.java:259)
2020-04-04 21:44:17.407 28854-28854/com.example.blooddonorsystem W/System.err: at com.android.volley.toolbox.HurlStack.addBodyIfExists(HurlStack.java:247)
2020-04-04 21:44:17.407 28854-28854/com.example.blooddonorsystem W/System.err: at com.android.volley.toolbox.HurlStack.setConnectionParametersForRequest(HurlStack.java:219)
2020-04-04 21:44:17.407 28854-28854/com.example.blooddonorsystem W/System.err: at com.android.volley.toolbox.HurlStack.executeRequest(HurlStack.java:97)
2020-04-04 21:44:17.407 28854-28854/com.example.blooddonorsystem W/System.err: at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:131)
2020-04-04 21:44:17.407 28854-28854/com.example.blooddonorsystem W/System.err: ... 2 more

这是连接到服务器的代码:

//taken out the real url for obvious reasons
static String URL_REGIST = "http://192.xxx.xxx.xxx/android/register.php";



@Override
public void onClick(View view) {
if(!validate()) return;
Register();
}

private void Register()
{
//make button invisible and make loading widget visible
loading.setVisibility(View.VISIBLE);
registerButton.setVisibility(View.GONE);

//get inputs and convert to strings
final String name = this.nameInput.getText().toString().trim();
final String emailAddress = this.emailAddressInput.getText().toString().trim();
final String password = this.passwordInput.getText().toString().trim();
// final String confirmPassword = this.confirmPasswordInput.getText().toString().trim();
final String postalAddress = this.addressInput.getText().toString().trim();
final String phoneNumber = this.nameInput.getText().toString().trim();
// final int phoneNumber = Integer.parseInt(this.nameInput.getText().toString().trim());
final String bloodType = bloodTypeInput.getSelectedItem().toString().trim();

//start sending data to the database
StringRequest stringRequest = new StringRequest(Request.Method.POST, URL_REGIST,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try
{
JSONObject jsonObject = new JSONObject(response);
String success = jsonObject.getString("success");
if(success.equals("1"))
{
Toast.makeText(RegisterActivity.this, "Registration Successful", Toast.LENGTH_SHORT).show();
}
} catch (JSONException e) {
e.printStackTrace();
Toast.makeText(RegisterActivity.this, "Registration Error! Error inserting values to db" + e.toString(), Toast.LENGTH_SHORT).show();
loading.setVisibility(View.GONE);
registerButton.setVisibility(View.VISIBLE);
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(RegisterActivity.this, "Registration Error! error connecting to db " + error.toString(), Toast.LENGTH_SHORT).show();
error.printStackTrace();
loading.setVisibility(View.GONE);
registerButton.setVisibility(View.VISIBLE);
}
})
{
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String,String> params = new HashMap<>();
params.put("name",name);
params.put("emailAddress",emailAddress);
params.put("password",password);
params.put("postalAddress",postalAddress);
params.put("phoneNumber",phoneNumber);
params.put("bloodType",bloodType);

return params;
}
};

我已经添加到我的 AndroidManifest 文件中。

我正在使用 digital ocean ubuntu Droplet 来托管服务器,除了允许通过防火墙访问之外,是否还需要更改其他设置。

最佳答案

我希望您已在 list 中添加了互联网权限。如果没有请添加

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

如果您正在模拟器中运行应用程序,请卸载并重新安装该应用程序。

请检查这是否适合您。

关于java - Android应用程序无法连接到外部apache mysql服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61034685/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com