错误:
Error:(164, 40) error: no suitable constructor found for
JsonObjectRequest(int,String,>,) constructor
JsonObjectRequest.JsonObjectRequest(String,JSONObject,Listener,ErrorListener)
is not applicable (actual argument int cannot be converted to String
by method invocation conversion) constructor
JsonObjectRequest.JsonObjectRequest(int,String,JsONObject,Listener,ErrorListener)
is not applicable (actual and formal argument Lists differ in length)
我相信问题出在class makeJsonObjectRequest上,有人可以帮我吗?
我的课:
<!-- language: java -->public class MainActivity extends ActionBaractivity { public static String API_pvp_net = ".API.pvp.net/API/lol/"; // URL API // Insira a Sua Key depois do sinal de igual exemplo = "?API_key=sua-key-da-riot" public static String DEVELOPMENT_API_KEY = "?API_key=xxxxx-c258-48ab-9f52-af4f52b45e4c"; // Key API RIOT // --------------------------------- public static String summoner_by_name = "v1.4/summoner/by-name/"; // Classe API URL public static String aUrl; // Url public static String Res_Web; // Resultado do Webbroser public static String Nome_Invocador; // Pega o Nome do invocador Do Txt_INVOCADOR private EditText etNick; private String nick; private button btnOk; private Spinner rg; private invocador inv; private TextVIEw tvLevel; private TextVIEw Level; private TextVIEw ID; private static String TAG = MainActivity.class.getSimplename(); private String JsonResponse; private ProgressDialog pDialog; ArrayAdapter<String> adapter; ArrayList<String> arrayInv; Summoner summoner = new Summoner(); private voID preencherInv() { arrayInv.add("BR"); arrayInv.add("EUNE"); arrayInv.add("EUW"); } @OverrIDe protected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.activity_main); pDialog = new ProgressDialog(this); pDialog.setMessage("Please wait..."); pDialog.setCancelable(false); etNick = (EditText) findVIEwByID(R.ID.etNick); btnOk = (button) findVIEwByID(R.ID.btnOk); rg = (Spinner) findVIEwByID(R.ID.spRG); tvLevel = (TextVIEw) findVIEwByID(R.ID.tvLevel); inv = new invocador(); Level = (TextVIEw) findVIEwByID(R.ID.level); ID = (TextVIEw) findVIEwByID(R.ID.ID); arrayInv = new ArrayList<>(); preencherInv(); adapter = new ArrayAdapter<String>( this, androID.R.layout.simple_dropdown_item_1line, arrayInv); rg.setAdapter(adapter); btnOk.setonClickListener(new VIEw.OnClickListener() { @OverrIDe public voID onClick(VIEw v) { inv.setNick(etNick.getText().toString()); inv.setRg((String) rg.getSelectedItem()); RequestQueue mRequestQueue; // Instantiate the cache Cache cache = new diskBasedCache(getCacheDir(), 1024 * 1024); // 1MB cap // Set up the network to use httpURLConnection as the http clIEnt. BasicNetwork network = new BasicNetwork(new HurlStack()); // Instantiate the RequestQueue with the cache and network. mRequestQueue = new RequestQueue(cache, network); // Start the queue mRequestQueue.start(); Pesquisa_invocador(); // Formulate the request and handle the response. makeJsonObjectRequest(); } }); } public voID Pesquisa_invocador() { // Eu tiro os espacos da String do _nome por que nas resposta ela vem [sem espacos e Toda minuscula] Nome_Invocador = inv.getNick().tolowerCase(); // Monto a URL API [CLASSE DA API] com 2 Parametro [Regiao] [NomeInvocador] + [CHAVE DE DESENVolVEDOR] aUrl = "https://" + inv.getRg().tolowerCase() + API_pvp_net + inv.getRg().tolowerCase() + "/" + summoner_by_name + Nome_Invocador + DEVELOPMENT_API_KEY; ; //Abro a URL no Webbroser } private voID makeJsonObjectRequest() { showpDialog(); JsonObjectRequest JsonObjReq = new JsonObjectRequest(Method.GET, aUrl, new Response.Listener<JsONObject>() { @OverrIDe public voID onResponse(JsONObject response) { Log.d(TAG, response.toString()); try { // Parsing Json object response // response will be a Json object String ID = response.getString("ID"); String name = response.getString("name"); String summonerLevel = response.getString("summonerLevel"); JsonResponse = ""; JsonResponse += "name: " + name + "\n\n"; JsonResponse += "Level: " + summonerLevel + "\n\n"; JsonResponse += "ID: " + ID + "\n\n"; tvLevel.setText(JsonResponse); } catch (JsONException e) { e.printstacktrace(); Toast.makeText(getApplicationContext(), "Error: " + e.getMessage(), Toast.LENGTH_LONG).show(); } hIDepDialog(); } }, new Response.ErrorListener() { @OverrIDe public voID one rrorResponse(VolleyError error) { VolleyLog.d(TAG, "Error: " + error.getMessage()); Toast.makeText(getApplicationContext(), error.getMessage(), Toast.LENGTH_SHORT).show(); // hIDe the progress dialog hIDepDialog(); } }); // Adding request to request queue AppController.getInstance().addToRequestQueue(JsonObjReq); } private voID showpDialog() { if (!pDialog.isShowing()) pDialog.show(); } private voID hIDepDialog() { if (pDialog.isShowing()) pDialog.dismiss(); } @OverrIDe public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_main, menu); return true; } @OverrIDe public boolean onoptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroIDManifest.xml. int ID = item.getItemID(); //noinspection SimplifiableIfStatement if (ID == R.ID.action_settings) { return true; } return super.onoptionsItemSelected(item); }}
解决方法:
换线
JsonObjectRequest JsonObjReq = new JsonObjectRequest(Method.GET, aUrl, new Response.Listener<JsONObject>(){
至
JsonObjectRequest JsonObjReq = new JsonObjectRequest(Method.GET, aUrl, null, new Response.Listener<JsONObject>(){
可以将GET请求的aJsonObject保留为空,因为仅在要将数据发送到服务器(例如POST / PUT / PATCH请求)时才需要它,java doc中此参数的描述为:
@param JsonRequest A {@link JsONObject} to post with the request. Null is allowed andindicates no parameters will be posted along with request.
总结 以上是内存溢出为你收集整理的java-未找到适合JsonObjectRequest的构造函数全部内容,希望文章能够帮你解决java-未找到适合JsonObjectRequest的构造函数所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)