我正尝试为asterisk-java
运行以下脚本。我添加了一个main
方法并在其中调用了service
方法,如下所示:
import org.asteriskjava.fastagi.AgiChannel;
import org.asteriskjava.fastagi.AgiException;
import org.asteriskjava.fastagi.AgiRequest;
import org.asteriskjava.fastagi.BaseAgiScript;
public class HelloAgiScript extends BaseAgiScript
{
public void service(AgiRequest request, AgiChannel channel)
throws AgiException
{
// Answer the channel...
answer();
// ...say hello...
streamFile("welcome");
// ...and hangup.
hangup();
}
public static void main (String[] args)
{
HelloAgiScript asteriskService = new HelloAgiScript();
asteriskService.service(request, channel);
}
}
当我尝试使用以下命令进行编译时:
javac -cp asterisk-java.jar HelloAgiScript.java
我收到此错误:
HelloAgiScript.java:24: error: cannot find symbol
asteriskService.service(request, channel);
^
symbol: variable request
location: class HelloAgiScript
HelloAgiScript.java:24: error: channel has private access in AgiOperations
asteriskService.service(request, channel);
^
2 errors
如何将参数传递给service
方法内的main
方法的实例?
答案 0 :(得分:2)
您需要将参数作为AgiRequest
和AgiChannel
类的对象传递给service()
方法调用。
与您的情况一样,request
和channel
变量均未创建。这就是为什么出现错误Can't find symbol
您的主要方法应如下:
public static void main (String[] args)
{
HelloAgiScript asteriskService = new HelloAgiScript();
AgiRequest request = new AgiRequest();
AgiChannel channel = new AgiChannel();
asteriskService.service(request, channel);
}
答案 1 :(得分:-1)
您没有从命令行将任何参数放入您的main方法中。你应该写类似
javac -cp asterisk-java.jar par1, par2
但是,首先,您应该定义哪个参数应该是内部参数,例如
public static void main (String[] args)
{
HelloAgiScript asteriskService = new HelloAgiScript();
AgiRequest request = args[0];
AgiChannel channel = args[1];
asteriskService.service(request, channel);
}
看here