当前位置: 首页 > 知识库问答 >
问题:

代号一-NetworManager

向安福
2023-03-14

每次调用请求时,我都会收到一个错误。当我用请求评论这行时。setPost(false),我从服务器得到一些响应。请解释出现此错误的原因。

线程"Thread-6"中的异常java.lang.IllegalStateException: Request方法(post/get)不能修改一个参数

<pre>
<code>
public static void MyVimeo(final String file) {
new Thread(new Runnable() {
public void run() {
Log.p("File Name : " + file);
String consumer_key = "";
String consumer_secret = "";
String vimeoAPIURL = "http://vimeo.com/api/rest/v2";
String reqTokenEP = "http://vimeo.com/oauth/request_token";
String AUTHORIZATION_URL = "http://vimeo.com/oauth/authorize?oauth_token=";
String accTokenEP = "http://vimeo.com/oauth/access_token";
String accToken = "";
String accTokenPass = "";

NetworkManager networkManager = NetworkManager.getInstance();
networkManager.start();
networkManager.addErrorListener(new ActionListener() {

public void actionPerformed(ActionEvent evt) {
NetworkEvent n = (NetworkEvent) evt;
n.getError().printStackTrace();
}
});

ConnectionRequest request = new ConnectionRequest() {
int chr;
StringBuffer sb = new StringBuffer();
String response = "";

protected void readResponse(InputStream input) throws IOException {
// do something with input stream
while ((chr = input.read()) != -1) {
sb.append((char) chr);
// System.out.println("reading...");
}
response = sb.toString();
Log.p("Response->" + response);
if (response.equals("OK")) {
Dialog.show("Response", "Authenticated", "Ok", null);
} 
else {
Dialog.show("Response", "Failed", "Ok", null);
}
}

protected void handleException(Exception err) {
// do something with err
Dialog.show("Connection Err!!", "Are you connected to the internet? Check your connection", "Ok", null);
}
};

request.setUrl(vimeoAPIURL);
request.addArgument("format", "xml");
request.addArgument("method", "vimeo.videos.upload.getQuota");
request.addArgument("oauth_consumer_key", consumer_key);
request.addArgument("oauth_version","1.0");
request.addArgument("oauth_signature_method", "HMAC-SHA1");
request.addArgument("oauth_token", accToken);
Log.p("vimeoAPIURL->" + vimeoAPIURL + " called");
request.setPost(false); //error here

networkManager.addToQueue(request);
}
}).start();
}
</code>
</pre>

共有1个答案

司徒炎彬
2023-03-14

必须在添加任何参数之前调用setPost。在所有addArgument调用之前调用它。实际错误是:

"Request method (post/get) can't be modified once arguments have been assigned to the request"

在目前的版本中,有一个拼写错误,它说的是一次而不是一次。

 类似资料:
  • 在无法让sqlite与我的解决方案一起工作后,我决定尝试一下存储类。我已经按照下面的说明进行了操作:https://www.codenameone.com/how-do-i----store-data-to-persistent-storageExternalization.html,并设法将我的数据放入持久存储中。现在我有以下问题: 谢谢

  • 我想知道,有了代号one,你是否可以在设备上创建一个“属性”文件来存储应用程序设置。如果不是这样,使用非云解决方案实现设置的最佳方式是什么?我猜是一个XML文件,可以存储在电话上的应用程序中?

  • 我正在尝试将我的lwuit应用程序移植到codenameone。 我在应用程序中使用了一个json包。(org.json.me)。这个包实际上是json jar的一部分,包含用于操作json文件的类。 当我使用LWUIT进行J2ME构建时,该应用程序运行良好。 在代号为one的emulator中,应用程序也可以正常工作。 当我试图通过右键单击项目并选择“send J2ME build”将J2ME构

  • 我正试图使用 SetBrowserNavigationCallback 然而,这只起作用一次。如果我再次点击加载,什么也不会发生... 这是预期的行为吗? 如果是,从javascript中多次调用java函数的最佳方法是什么?

  • 我们正在尝试在我们的一个应用程序上实现推送通知。 对于Andriod,我们使用Firebase注册,下载google-services.json文件并将其添加到我们的native/Andriod目录。 在模拟器上一切正常,但在Andriod设备上,推入注册失败,错误代码为0,INVALID_PARAMETERS(由pushRegistrationError回调方法给出)。

  • 下面的代码在模拟器中工作很好,我听到了音频: 但它在真正的Android设备上根本不起作用。怎么了?在生成的apk上,“notification_sound_bell.mp3”文件放在/res/raw文件夹中。 [EDT]0:0:20,186-代号1修订:3B20Edadec808867AFC2B19774268B66890616AD [EDT]0:0:20,191-Exception:java.