gpt4 book ai didi

android - 如何从Android程序将SQLite数据库文件上传到FTP服务器

转载 作者:行者123 更新时间:2023-12-03 18:12:54 25 4
gpt4 key购买 nike

每次调用ftp写操作时APP崩溃。

我在Fragment中有以下2种方法。

public void uploadData () {     


String domain = "10.142.42.10"; // <<< will it work as it is private ip?
String user = "xxxx";
String password = "xxxx";
String serverRoad = "Documents";

File file = new File("/sdcard/bluetooth/NRC_jiten.pdf");
FTPClient ftp = new FTPClient();
try {
ftp.connect(InetAddress.getByName(domain));
//ftp.connect(domain,21);
ftp.login(user, password);

ftp.changeWorkingDirectory(serverRoad);
ftp.setFileType(FTP.BINARY_FILE_TYPE);
FileInputStream is = new FileInputStream(file);
BufferedInputStream buffIn = new BufferedInputStream(is);
ftp.enterLocalPassiveMode();
ftp.storeFile("jiten_pdf.pdf", buffIn);
buffIn.close();

ftp.logout();
ftp.disconnect();
} catch (Exception e) {
Toast.makeText(getActivity(), "err:" + e,
Toast.LENGTH_SHORT).show();
}
}

public void uploadFileBackground () {

new Thread(new Runnable() {
public void run() {

uploadData();

}
}).start();


}


现在,从 Activity鼠标单击按钮时触发 uploadFileBackground

代码有什么问题吗?我已经推荐了该站点,但无法成功。

TIA。



LogCat

            08-25 19:00:56.042  16119-16119/com.sbordolo.potholefinder W/GooglePlayServicesUtil﹕ Google Play services out of date.  Requires 7571000 but found 6774470
08-25 19:00:56.044 16119-16119/com.sbordolo.potholefinder W/GooglePlayServicesUtil﹕ Google Play services out of date. Requires 7571000 but found 6774470
08-25 19:00:56.047 16119-16119/com.sbordolo.potholefinder W/GooglePlayServicesUtil﹕ Google Play services out of date. Requires 7571000 but found 6774470
08-25 19:00:56.047 16119-16119/com.sbordolo.potholefinder W/GooglePlayServicesUtil﹕ Google Play services out of date. Requires 7571000 but found 6774470
08-25 19:00:56.049 16119-16119/com.sbordolo.potholefinder W/GooglePlayServicesUtil﹕ Google Play services out of date. Requires 7571000 but found 6774470
08-25 19:00:56.050 16119-16119/com.sbordolo.potholefinder W/GooglePlayServicesUtil﹕ Google Play services out of date. Requires 7571000 but found 6774470
08-25 19:00:56.051 16119-16119/com.sbordolo.potholefinder W/GooglePlayServicesUtil﹕ Google Play services out of date. Requires 7571000 but found 6774470
08-25 19:00:56.052 16119-16119/com.sbordolo.potholefinder W/GooglePlayServicesUtil﹕ Google Play services out of date. Requires 7571000 but found 6774470
08-25 19:00:56.052 16119-16119/com.sbordolo.potholefinder W/GooglePlayServicesUtil﹕ Google Play services out of date. Requires 7571000 but found 6774470
08-25 19:00:56.056 16119-16119/com.sbordolo.potholefinder W/GooglePlayServicesUtil﹕ Google Play services out of date. Requires 7571000 but found 6774470
08-25 19:00:56.056 16119-16119/com.sbordolo.potholefinder W/GooglePlayServicesUtil﹕ Google Play services out of date. Requires 7571000 but found 6774470
08-25 19:00:56.058 16119-16119/com.sbordolo.potholefinder W/GooglePlayServicesUtil﹕ Google Play services out of date. Requires 7571000 but found 6774470
08-25 19:00:56.079 16119-16138/com.sbordolo.potholefinder D/OpenGLRenderer﹕ Use EGL_SWAP_BEHAVIOR_PRESERVED: true
08-25 19:00:56.080 16119-16119/com.sbordolo.potholefinder D/﹕ HostConnection::get() New Host Connection established 0xb3ffc140, tid 16119
08-25 19:00:56.088 16119-16119/com.sbordolo.potholefinder D/Atlas﹕ Validating map...
08-25 19:00:56.474 16119-16138/com.sbordolo.potholefinder D/﹕ HostConnection::get() New Host Connection established 0xb3ffc3c0, tid 16138
08-25 19:00:56.483 16119-16138/com.sbordolo.potholefinder I/OpenGLRenderer﹕ Initialized EGL, version 1.4
08-25 19:00:56.488 16119-16138/com.sbordolo.potholefinder D/OpenGLRenderer﹕ Enabling debug mode 0
08-25 19:00:56.514 16119-16138/com.sbordolo.potholefinder W/EGL_emulation﹕ eglSurfaceAttrib not implemented
08-25 19:00:56.514 16119-16138/com.sbordolo.potholefinder W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xb3fdb4e0, error=EGL_SUCCESS
08-25 19:00:56.844 16119-16119/com.sbordolo.potholefinder E/WindowManager﹕ android.view.WindowLeaked: Activity com.sbordolo.potholefinder.HomeScreen has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{9052cc6 V.E..... R....... 0,0-1026,591} that was originally added here
at android.view.ViewRootImpl.<init>(ViewRootImpl.java:363)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:271)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:85)
at android.app.Dialog.show(Dialog.java:298)
at com.sbordolo.potholefinder.CoordinateClass.isGooglePlayServicesAvailable(CoordinateClass.java:110)
at com.sbordolo.potholefinder.CoordinateClass.onActivityCreated(CoordinateClass.java:66)
at android.app.Fragment.performActivityCreated(Fragment.java:2061)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:912)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1049)
at android.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:1869)
at android.app.Activity.performCreateCommon(Activity.java:5985)
at android.app.Activity.performCreate(Activity.java:5992)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5257)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

最佳答案

首先,使用Google Play应用更新您的Google Play服务。如您所见:

Google Play services out of date.


过时了

其次,不要像这样使用 Thread在Android上做背景资料,因为


(...)违反了单线程模型的第二条规则:
从UI线程外部访问Android UI工具包。


尝试使用 AsyncTaskServiceHandler

有关线程 here,服务 here和处理程序 here的更多信息。



现在针对您的问题,您将得到以下异常:

android.view.WindowLeaked: Activity com.sbordolo.potholefinder.HomeScreen has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{9052cc6 V.E..... R....... 0,0-1026,591} that was originally added here


WindowLeaked异常是最常见的,因为代码中未排除的 Dialog导致异常。

并且您的logcat跟踪显示对话框正在尝试弹出:

at android.app.Dialog.show(Dialog.java:298)


编辑:所以由于您的 Toast而崩溃。删除它,或尝试上面的解决方案,您应该没问题。

第二次编辑:正如您提到的那样,为了使答案完整,您的ftp服务器需要设置正确的权限,以便您的程序可以在其中写入内容。您的 chmod 777可以工作,但是要小心,因为它使您的服务器保持开放状态,任何人都可以在此处写入。

关于android - 如何从Android程序将SQLite数据库文件上传到FTP服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32204448/

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