gpt4 book ai didi

java - E/Android运行时: FATAL EXCEPTION: AsyncTask #1 error after copy file to other PC

转载 作者:行者123 更新时间:2023-12-02 04:01:48 28 4
gpt4 key购买 nike

我只是使用 TortoiseSVN 将我的项目从我的家用笔记本电脑复制到我的办公室 PC。但该项目在我的办公室电脑上运行不佳。

这是我的代码,我被困在这里(我认为)。

public class SyncDatabase extends AsyncTask<String, Void, String> {

Handler mHandler = null;

public void setHandler(Handler handler) {
mHandler = handler;
}

private static final String TAG = "SyncDatabase";
Context mContext;
AlertDialog mAlertDialog;

public SyncDatabase(Context context) {
mContext = context;
}

String post_url = "http://192.168.56.1/php_poedi/progress_business/admin/process/location-Backup.php";

@Override
protected String doInBackground(String... params) {
try{
String txtLatitude = params[0];
String txtLongitude = params[1];
String editUserID = params[2];
String editEmailPHP = params[3];
String tempRadio = params[4];
String editDate = params[5];
String nationality = params[6];

URL url = new URL(post_url);
Log.d(TAG, "checkpost_url: "+ post_url);
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setDoOutput(true);
httpURLConnection.setDoInput(true);
OutputStream outputStream = httpURLConnection.getOutputStream();
Log.d(TAG, "txtLatitude " + txtLatitude + "txtLongitude "+ txtLongitude);
BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputStream, "UTF-8"));
String post_data = URLEncoder.encode("latitude", "UTF-8")+"="+URLEncoder.encode(txtLatitude,"UTF-8")
+"&"+URLEncoder.encode("longitude", "UTF-8")+"="+URLEncoder.encode(txtLongitude, "UTF-8")
+"&"+URLEncoder.encode("username", "UTF-8")+"="+URLEncoder.encode(editUserID, "UTF-8")
+"&"+URLEncoder.encode("email", "UTF-8")+"="+URLEncoder.encode(editEmailPHP, "UTF-8")
+"&"+URLEncoder.encode("gender", "UTF-8")+"="+URLEncoder.encode(tempRadio, "UTF-8")
+"&"+URLEncoder.encode("birthday", "UTF-8")+"="+URLEncoder.encode(editDate, "UTF-8")
+"&"+URLEncoder.encode("nationality", "UTF-8")+"="+URLEncoder.encode(nationality, "UTF-8");
bufferedWriter.write(post_data);
bufferedWriter.close();
outputStream.close();
InputStream inputStream = httpURLConnection.getInputStream();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, "iso-8859-1"));
String result = "";
String line = "";
while ((line = bufferedReader.readLine()) != null) {
result += line;
}
Log.d(TAG, "result: "+ result);
bufferedReader.close();
inputStream.close();
httpURLConnection.disconnect();
return result;
} catch (MalformedURLException e){
e.printStackTrace();
} catch (IOException e){
e.printStackTrace();
}

return null;
}

@Override
protected void onPreExecute() {
mAlertDialog = new AlertDialog.Builder(mContext).create();
mAlertDialog.setTitle("Login Status");
}

@Override
protected void onPostExecute(String s) {
mAlertDialog.setMessage(s);
Log.d(TAG, "onPostExecute: "+ s);

if(mHandler!=null){
Message message = new Message();
message.obj = s;
mHandler.sendMessage(message);
Log.d(TAG, "Message " + message);
}
}
}

这是我的错误。

D/MainActivity: onClick: starts
Date10/5/2009
checkradiobutton Male
D/SyncDatabase: checkpost_url: http://192.168.56.1/php_poedi/progress_business/admin/process/location-Backup.php
D/NetworkSecurityConfig: Using Network Security Config from resource network_security_config debugBuild: true
W/ResourceType: Failure getting entry for 0x7f100000 (t=15 e=0) (error -75)
E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1
Process: org.example.register, PID: 6130
java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:318)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor$1.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)
Caused by: java.lang.RuntimeException: Failed to parse XML configuration from network_security_config
at android.security.net.config.XmlConfigSource.ensureInitialized(XmlConfigSource.java:98)
at android.security.net.config.XmlConfigSource.getPerDomainConfigs(XmlConfigSource.java:65)
at android.security.net.config.ManifestConfigSource.getPerDomainConfigs(ManifestConfigSource.java:49)
at android.security.net.config.ApplicationConfig.ensureInitialized(ApplicationConfig.java:169)
at android.security.net.config.ApplicationConfig.getTrustManager(ApplicationConfig.java:120)
at android.security.net.config.RootTrustManagerFactorySpi.engineGetTrustManagers(RootTrustManagerFactorySpi.java:65)
at javax.net.ssl.TrustManagerFactory.getTrustManagers(TrustManagerFactory.java:285)
at com.android.org.conscrypt.SSLParametersImpl.createDefaultX509TrustManager(SSLParametersImpl.java:933)
at com.android.org.conscrypt.SSLParametersImpl.getDefaultX509TrustManager(SSLParametersImpl.java:922)
at com.android.org.conscrypt.SSLParametersImpl.<init>(SSLParametersImpl.java:156)
at com.android.org.conscrypt.OpenSSLContextImpl.engineInit(OpenSSLContextImpl.java:100)
at javax.net.ssl.SSLContext.init(SSLContext.java:316)
at com.android.okhttp.OkHttpClient.getDefaultSSLSocketFactory(OkHttpClient.java:671)
at com.android.okhttp.OkHttpClient.copyWithDefaults(OkHttpClient.java:630)
at com.android.okhttp.OkUrlFactory.open(OkUrlFactory.java:59)
at com.android.okhttp.OkUrlFactory.open(OkUrlFactory.java:54)
at com.android.okhttp.HttpHandler.openConnection(HttpHandler.java:44)
at java.net.URL.openConnection(URL.java:991)
at org.example.register.SyncDatabase.doInBackground(SyncDatabase.java:66)
at org.example.register.SyncDatabase.doInBackground(SyncDatabase.java:34)
at android.os.AsyncTask$2.call(AsyncTask.java:304)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.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) 
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f100000
at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:190)
at android.content.res.Resources.loadXmlResourceParser(Resources.java:2094)
at android.content.res.Resources.getXml(Resources.java:1160)
at android.security.net.config.XmlConfigSource.ensureInitialized(XmlConfigSource.java:92)
at android.security.net.config.XmlConfigSource.getPerDomainConfigs(XmlConfigSource.java:65) 
at android.security.net.config.ManifestConfigSource.getPerDomainConfigs(ManifestConfigSource.java:49) 
at android.security.net.config.ApplicationConfig.ensureInitialized(ApplicationConfig.java:169) 
at android.security.net.config.ApplicationConfig.getTrustManager(ApplicationConfig.java:120) 
at android.security.net.config.RootTrustManagerFactorySpi.engineGetTrustManagers(RootTrustManagerFactorySpi.java:65) 
at javax.net.ssl.TrustManagerFactory.getTrustManagers(TrustManagerFactory.java:285) 
at com.android.org.conscrypt.SSLParametersImpl.createDefaultX509TrustManager(SSLParametersImpl.java:933) 
at com.android.org.conscrypt.SSLParametersImpl.getDefaultX509TrustManager(SSLParametersImpl.java:922) 
at com.android.org.conscrypt.SSLParametersImpl.<init>(SSLParametersImpl.java:156) 
at com.android.org.conscrypt.OpenSSLContextImpl.engineInit(OpenSSLContextImpl.java:100) 
at javax.net.ssl.SSLContext.init(SSLContext.java:316) 
at com.android.okhttp.OkHttpClient.getDefaultSSLSocketFactory(OkHttpClient.java:671) 
at com.android.okhttp.OkHttpClient.copyWithDefaults(OkHttpClient.java:630) 
at com.android.okhttp.OkUrlFactory.open(OkUrlFactory.java:59) 
at com.android.okhttp.OkUrlFactory.open(OkUrlFactory.java:54) 
at com.android.okhttp.HttpHandler.openConnection(HttpHandler.java:44) 
at java.net.URL.openConnection(URL.java:991) 
at org.example.register.SyncDatabase.doInBackground(SyncDatabase.java:66) 
at org.example.register.SyncDatabase.doInBackground(SyncDatabase.java:34) 
at android.os.AsyncTask$2.call(AsyncTask.java:304) 
at java.util.concurrent.FutureTask.run(FutureTask.java:237) 
at android.os.AsyncTask$SerialExecutor$1.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: 0xb25840c0: ver 2 0 (tinfo 0xb25835d0)

我的项目在我的家用笔记本电脑或我的办公室电脑上都没有编辑。我认为问题出在 Android Studio 设置中,但问题出在哪一部分?我没有任何线索!

这是我的network_security_config.xml

<network-security-config>
<base-config cleartextTrafficPermitted="true">

<trust-anchors>
<certificates src="system" />
</trust-anchors>
</base-config>
</network-security-config>

以及AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.example.register">

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

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:networkSecurityConfig="@xml/network_security_config"
android:supportsRtl="true"
android:theme="@style/AppTheme">

<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_maps_key" />

<activity
android:name=".MapsActivity"
android:label="@string/title_activity_maps">
</activity>
<activity
android:name=".Activity2"
android:label="@string/location_activity"
android:parentActivityName=".MainActivity" />

<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="org.example.register.MainActivity" />

<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />

<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

最佳答案

据我从您的 logcat 中看到,您正在尝试连接到本地服务器以进行某些位置备份,因此您正在调用 API 到位于具有以下 IP 地址 192.168.56.1 的计算机中的服务器。 。

在您的家里,您可能正在运行一个只能在本地网络中通信的服务器应用程序。您的服务器计算机需要有一个公共(public) IP 地址,才能在本地网络(例如您的办公室)之外访问服务器提供的 API。

正如我从 logcat 中看到的,您正在尝试连接到以下主机。

http://192.168.56.1/php_poedi/progress_business/admin/process/locationBackup.php

无法从您的办公室网络访问该地址,因为该 IP 地址是您家中一台计算机的 IP 地址(即本地 IP 地址)。因此,调用此 API 时找不到资源,我的猜测是,当您没有从服务器获取任何内容时,您不会处理响应。

因此我有两个建议。

  • 同时复制您的服务器应用程序并在您办公室的计算机上运行它。获取机器的IP地址,将IP地址代替192.168.56.1 。您也可以考虑将您的家用计算机设置为具有公共(public)IP地址,但是,我认为这需要您自己执行,这需要很长时间。
  • 妥善处理从 API 调用收到的响应。也就是说,当没有响应时,您的代码也应该处理该问题。一般来说,我们可以使用try/catch block 来处理此类情况。当无法解析来自服务器的响应时,您可以在 catch block 中获取该响应并生成 Toast或错误消息。

希望有帮助!

关于java - E/Android运行时: FATAL EXCEPTION: AsyncTask #1 error after copy file to other PC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56729893/

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