因为我使用了Volley Lib。在我的依赖项目
compile 'com.mcxiaoke.volley:library:1.0.19'
这种依赖允许我使用
RequestQueue requestQueue;
这在Google Volley lib依赖项中是不允许的。
但Android Studio build.gradle警告消息为注意:不要放置应用程序依赖项....配置'编译'已经过时,已被“实施”所取代。它将在2018年底删除.Java编译错误。
所以,我在 androidTestImplementation
中搜索这些依赖项或Volley lib依赖项的替代方法这是我的代码。这工作绝对正常,但我需要一个 替换这个lib。
public class LoginActivity extends AppCompatActivity {
private Button admin_login;
private EditText admin_mob, admin_pass;
private RequestQueue requestQueue;
private static final String URL = "https://indinity.com/json_data.php";
private StringRequest request;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
admin_login = findViewById(R.id.button);
admin_mob = findViewById(R.id.editText);
admin_pass = findViewById(R.id.editText2);
requestQueue = Volley.newRequestQueue(this);
admin_login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
request = new StringRequest(Request.Method.POST, URL, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject jsonObject = new JSONObject(response);
if(jsonObject.names().get(0).equals("success"))
{
Toast.makeText(getApplicationContext(),"Success "+jsonObject.getString("success"),Toast.LENGTH_LONG).show();
startActivity(new Intent(getApplicationContext(),OptionActivity.class));
} else {
Toast.makeText(getApplicationContext(),"Error "+jsonObject.getString("error"),Toast.LENGTH_SHORT).show();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
}){
@Override
protected Map<String, String> getParams() throws AuthFailureError {
HashMap<String, String> hashMap = new HashMap<String, String>();
hashMap.put("adminmob", admin_mob.getText().toString());
hashMap.put("password", admin_pass.getText().toString());
return hashMap;
}
};
requestQueue.add(request);
}
});
}
}
答案 0 :(得分:0)
只需更改
compile 'com.mcxiaoke.volley:library:1.0.19'
到
implementation 'com.mcxiaoke.volley:library:1.0.19'