Android 开发 FTP 客户端

Android development FTP Client

我最近制作了一个运行良好的 FTP 服务器。 我可以通过使用笔记本电脑和智能手机浏览来连接到该服务器。 现在我希望通过我在 java 中自制的应用程序建立相同的连接。 所以我从 'commons.apache.org' 下载了一个库,其中包含一个 class FTPClient,我应该可以使用它来建立连接。 在我的程序中,我创建了这个 class 的对象,并调用了一个连接函数,它以 ip 和端口作为参数。这是我的代码:

    public class MainActivity extends ActionBarActivity
    {
        TextView textView;
        FTPClient ftpClient;
        String ip = "192.168.1.136";
        int port = 21;

        @Override
        protected void onCreate(Bundle savedInstanceState)
        {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);

            textView = (TextView)findViewById(R.id.textField_id);
            ftpClient = new FTPClient();
            try{
                this.ftpClient.connect(ip,port);
            }catch(Exception e){
                textView.setText("Failed: " + e.getMessage());
            }
        }

错误消息一直告诉我 'null' (nullpointerexpception)

我做错了什么?

将此添加到您的 onCreate 方法中

StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(policy);