FTP 使用哪个IP?

FTP which IP to use?

我正在使用此代码:

    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 commons

然后它抛给我这个:

      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.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>

您可能在 AndroidManifest.xml 中错过了此权限。

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

从应用程序中删除 uses-permission 标签并将它们移动到 manifest

check here how a manifest must be written:

<manifest>

    <uses-permission />
    <permission />
    <permission-tree />
    <permission-group />
    <instrumentation />
    <uses-sdk />
    <uses-configuration />  
    <uses-feature />  
    <supports-screens />  
    <compatible-screens />  
    <supports-gl-texture />  

    <application>

            <activity>
            <intent-filter>
                <action />
                <category />
                <data />
            </intent-filter>
            <meta-data />
        </activity>

        <activity-alias>
            <intent-filter> . . . </intent-filter>
            <meta-data />
        </activity-alias>

        <service>
            <intent-filter> . . . </intent-filter>
            <meta-data/>
        </service>

        <receiver>
            <intent-filter> . . . </intent-filter>
            <meta-data />
        </receiver>

        <provider>
            <grant-uri-permission />
            <meta-data />
            <path-permission />
        </provider>

        <uses-library />

    </application>

</manifest>