android - 无法解析符号 "Method"

标签 android android-studio android-volley

我尝试在 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/

相关文章:

android - 在 volley post 请求中发送表单数据

java - 安卓开发 : Can't generate multiple layouts dynamically from an XML template

android - 果冻 bean 通知操作已禁用

android - 如何用旧的方式在 Android Studio 上打开模拟器? (在大黄蜂之前)

android - 如何同时使用新的Android 2.0 Shrinker 和Resource Shrinker?

android - 使用Volley时出现NoConnectionError

android - Google Play 服务 7.5.0 AnalyticsService NPE onStartCommand

java - 访问 .jar API 函数 - 错误 : Cannot make a static reference to the non-static method

java - Google 在 Appcompactivity 中的 AutoCompleteTextView 上放置 api 调用 - Android

php - 我不知道使用 Volley 更新数据库时做错了什么