如何从另一个类调用活动中的方法?
问题描述:
public class BrokerCommunication {
public String BrokerCommRequest(String url)
{
try
{
}
catch (Exception e) {
// TODO: handle exception
}
return "";
}
public String BrokerRequest(String _reqUrl,String _reqType)
{
try
{
}
catch (Exception e) {
// TODO: handle exception
}
return "";
}
}
所以如何从LoginActivity.java中调用此BrokerRequest
我的尝试:
So how to I Call this BrokerRequest from LoginActivity.java
What I have tried:
BrokerCommunication inst = new BrokerCommunication();
inst.BrokerRequest();
我试过这样但显示更改签名错误。
I tried like this but its showing error of change signature.
答
您当前调用该方法的方式的问题是您没有传递任何参数:BrokerRequest
接受两个String参数,但是您执行inst.BrokerRequest()
所以你没有传递任何东西。
做这样的事情:
The problem with the way you currently call the method, is that you don't pass any arguments:BrokerRequest
takes two String arguments, but you doinst.BrokerRequest()
so you aren't passing anything.
Do something like this:
BrokerCommunication inst = new BrokerCommunication();
inst.BrokerRequest("<your req URL here>", "<your req type here>");