gpt4 book ai didi

android - 无法解析符号 "Method"

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:02:15 24 4
gpt4 key购买 nike

我尝试在 Android 代码中执行一个简单的 GET 请求,我只是从 Volley 的官方网站复制了代码,但我收到一条错误消息:“无法解析符号“方法””。

我的代码是这样的:

public void onReceive(final Context context, Intent intent) {
// Instantiate the RequestQueue.
RequestQueue queue = Volley.newRequestQueue(context);
String url = ***** ; // my URL

// Request a string response from the provided URL.
StringRequest stringRequest = new StringRequest(DownloadManager.Request.Method.GET, url,
new Response.Listener<String>() { //the error is in THIS line
@Override
public void onResponse(String response) {
// Display the first 500 characters of the response string.
Toast.makeText(context, "Response is: " + response.substring(0,500), Toast.LENGTH_LONG).show();

}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(context, "error", Toast.LENGTH_LONG).show();
}
});

//将请求添加到 RequestQueue。 queue.add(stringRequest);

对于导入,我有这些行(我手动写的):

 import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;

我试图包含这一行:“import com.android.volley.Request.Method;”但它没有改变任何东西。我仍然遇到同样的错误

我该如何解决这个问题?

最佳答案

你正在使用

DownloadManager.Request.Method.GET

代替

 com.android.volley.Request.Method.GET

关于android - 无法解析符号 "Method",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32228877/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com