我使用這個代碼:FTP使用哪個IP?
ftpClient.connect(InetAddress.getByName(10.0.0.100));
ftpClient.login(user, password);
ftpClient.changeWorkingDirectory(serverRoad);
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
BufferedInputStream buffIn=null;
buffIn=new BufferedInputStream(new FileInputStream(file));
ftpClient.enterLocalPassiveMode();
ftpClient.storeFile("test.txt", buffIn);
buffIn.close();
ftpClient.logout();
ftpClient.disconnect();
而且我的項目中出現死機此行
ftpClient.connect(InetAddress.getByName(server));
所以服務器的IP是是假的,我用從PC的IP服務器所在運行。 IP:10.0.0.100 這個IP有什麼問題?
順便說一下我使用Apache的百科全書
然後拋出我:
D: [NET] android_getaddrinfofornet+,hn 16(0x6674703a2f2f31),sn(),hints(known),family 0,flags 4
D: [NET] android_getaddrinfofornet-, err=8
W: android.os.NetworkOnMainThreadException
W: at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1155)
W: at java.net.InetAddress.lookupHostByName(InetAddress.java:418)
W: at java.net.InetAddress.getAllByNameImpl(InetAddress.java:252)
W: at java.net.InetAddress.getByName(InetAddress.java:305)
W: at com.example.mathias.newproject.MainActivity.connnectingwithFTP(MainActivity.java:89)
W: at com.example.mathias.newproject.MainActivity$2.onClick(MainActivity.java:52)
W: at android.view.View.performClick(View.java:4785)
W: at android.view.View$PerformClick.run(View.java:19858)
W: at android.os.Handler.handleCallback(Handler.java:739)
W: at android.os.Handler.dispatchMessage(Handler.java:95)
W: at android.os.Looper.loop(Looper.java:155)
W: at android.app.ActivityThread.main(ActivityThread.java:5696)
W: at java.lang.reflect.Method.invoke(Native Method)
W: at java.lang.reflect.Method.invoke(Method.java:372)
W: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1028)
W: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)
清單:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mathias.newproject" >
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
你有互聯網的權限在您的清單?請分享logcat – Santiago
分享日誌以及您已經聲明變量'server'的片段 – darthvading
添加了logcat和manifest @Santiago – Ribisl