我的班级:
<!-- 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 onErrorResponse(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可以保留为null,因为只有当您想要向服务器发送数据时才需要它,例如POST/PUT/PATCH请求,java doc对此参数的描述如下:
@param jsonRequest A {@link JSONObject} to post with the request. Null is allowed and
indicates no parameters will be posted along with request.
从javase api 8开始,是不推荐的。因此,动态生成是首选的导出对象方式,如下所示: null 我的问题是,当出现在JavaE8 api中时,为什么编译器会出错?
我正在运行一个应用程序,可以在选择或捕捉它们后查看多个图像。当我运行应用程序时,ImageView部分似乎有问题,它说:
我是一个较大的android我想为移动和电视创建一个应用程序,当我试图建立项目时,我看到错误: 错误:(156,33)错误:没有为HeaderItem(int,String,)构造函数HeaderItem(String)找到合适的构造函数。HeaderItem(String)不适用(实际和正式参数列表长度不同)构造函数HeaderItem(long,String)不适用(实际和正式参数列表长度不同
问题内容: 只有最后一部分(我的意思是我仅对此有问题) 当我编译它时,我没有合适的构造函数错误。为什么是这样??顺便说一下,Spirtokouto类的目的是要增加一个计数值(权重)。我可以将一个班级扩展到> 1个班级吗? 问题答案: Box类有两个构造函数:,但它们都不带四个参数,而您要用四个参数来调用它,因此请更改此参数: 对此: 调用必须首先在构造函数中进行。 我可以将一个班级扩展到 > 1个
问题内容: 我正在实现他们文档中提供的firebase示例。我遇到此错误: com.fasterxml.jackson.databind.JsonMappingException:没有为类型[简单类型,类com.XYZ。$ BlogPost]找到合适的构造函数:无法从JSON对象实例化(需要添加/启用类型信息吗?) 这是我的代码: 我在同一件事上经历了很多问题,说要包含反序列化JSON所需的空构造
问题内容: 我是Java的新手,正在尝试为Minecraft制作一个mod,但我不知道如何解决此错误: 这是我的代码: 这是怎么回事,我正在尝试使字符串“ Username”重定向到另一个类。 问题答案: Java编译器告诉您不能构造对象,因为您对构造函数的调用与任何已知的构造函数都不匹配。 具体来说,编译器发现了两个构造函数: 但您致电给: 都不匹配。