我正在尝试制作一个程序,显示多个带有图片的标题。我查看了stackoverflow,并且无法获得任何适合我的建议。我的所有错误都在私有的无效ShowJSON
中package br.exemplozxingintegration;
import android.annotation.SuppressLint;
import android.app.ProgressDialog;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
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.squareup.picasso.Picasso;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
public class ForthActivty extends AppCompatActivity implements View.OnClickListener {
private EditText pastetext;
private ClipboardManager myClipboard;
private ClipData myClip;
private Button btn;
private Button btn2;
private EditText textView1;
private Button buttonGet;
private TextView textViewResult;
private ImageView ImageView1;
private ProgressDialog loading;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_forth_activty);
myClipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
pastetext = (EditText) findViewById(R.id.textView1);
btn = (Button)findViewById(R.id.buttonPaste);
btn.performClick();
textView1 = (EditText) findViewById(R.id.textView1);
buttonGet = (Button) findViewById(R.id.buttonGet);
textViewResult = (TextView) findViewById(R.id.textViewResult);
ImageView1= (ImageView) findViewById(R.id.imageView1);
buttonGet.setOnClickListener(this);
btn2 = (Button)findViewById(R.id.buttonGet);
btn2.performClick();
}
@SuppressLint("NewApi")
public void paste(View view) {
ClipData cp = myClipboard.getPrimaryClip();
ClipData.Item item = cp.getItemAt(0);
String text = item.getText().toString();
pastetext.setText(text);
Toast.makeText(getApplicationContext(), "",
Toast.LENGTH_SHORT).show();}
private void getData() {
String qrcode = textView1.getText().toString().trim();
if (qrcode.equals("")) {
Toast.makeText(this, "", Toast.LENGTH_LONG).show();
return;
}
loading = ProgressDialog.show(this,"Please wait...","Fetching...",false,false);
String url = ConfigRec.DATA_URL+textView1.getText().toString().trim();
StringRequest stringRequest = new StringRequest(url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
loading.dismiss();
showJSON(response);
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(ForthActivty.this,error.getMessage().toString(),Toast.LENGTH_LONG).show();
}
});
RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(stringRequest);
}
private void showJSON(Integer response){
String title="";
String image = "";
try {
JSONArray jarray=new JSONArray(response);
for( response = 0;response<jarray.length();response++){
JSONObject jsonObject = new JSONObject(response);
JSONArray result = jsonObject.getJSONArray(ConfigRec.JSON_ARRAY);
JSONObject androidData = result.getJSONObject(0);
title = androidData.getString(ConfigRec.KEY_TITLE);
image = androidData.getString(ConfigRec.KEY_IMAGE);
}} catch (JSONException e) {
e.printStackTrace();
}
textViewResult.setText(title);//+"\nImagine :\t"+ image);
//int id = >getResources().getIdentifier("http://192.168.1.254/2015/380panel/uploads/images>/sm/"+ image, null, null);
//ImageView1.setImageURI(id);
>Picasso.with(this).load("http://192.168.1.254/2015/380panel/uploads/images/sm/+ image).into(ImageView1);
}
我的错误是:
Cannot resolve constructor JSONobject(java.lang.Integer)
它在JSONObject jsonObject = new JSONObject(response);
答案 0 :(得分:0)
将showJson(整数响应)更改为
showJson(String response){
String title="";
String image = "";
try {
JSONArray jarray=new JSONArray(response);
for( int i= 0;i<jarray.length();i++){
JSONObject jsonObject = jarray.getJSONObject(i);
JSONArray result = jsonObject.getJSONArray(ConfigRec.JSON_ARRAY);
JSONObject androidData = result.getJSONObject(0);
title = androidData.getString(ConfigRec.KEY_TITLE);
image = androidData.getString(ConfigRec.KEY_IMAGE);
}} catch (JSONException e) {
e.printStackTrace();
}
textViewResult.setText(title);//+"\nImagine :\t"+ image);
//int id = >getResources().getIdentifier("http://192.168.1.254/2015/380panel/uploads/images>/sm/"+ image, null, null);
//ImageView1.setImageURI(id);
>Picasso.with(this).load("http://192.168.1.254/2015/380panel/uploads/images/sm/+ image).into(ImageView1);
}