简体   繁体   English

我如何在另一个类中调用此函数?

[英]How I can call this function in another class?

this is the MainActivity.Java. 这是MainActivity.Java。 This function I want to call in another class 我想在另一个班级中调用的函数

// Method to connect to FTP server: //连接FTP服务器的方法:

public static boolean ftpConnect(String host, String username,
        String password, int port) {
    try {
        mFTPClient = new FTPClient();
        mFTPClient.connect(host, port);
        if (FTPReply.isPositiveCompletion(mFTPClient.getReplyCode())) {
            boolean status = mFTPClient.login(username, password);
            mFTPClient.enterLocalPassiveMode();
            mFTPClient
                    .setFileTransferMode(org.apache.commons.net.ftp.FTP.BINARY_FILE_TYPE);

            return status;
        }
    } catch (Exception e) {
        Log.d(TAG, "Error: could not connect to host " + host);
    }

    return false;
}

The general way to call these sorts of functions is to use the class name before the method. 调用这些函数的一般方法是在方法之前使用类名。

Let's say that this method exists in a class called FTPHelper. 假设此方法存在于名为FTPHelper的类中。 To call this piece of code, you would use 要调用这段代码,您将使用

FTPHelper.ftpConnect(host, username,password,port);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM