私のデータベースのデータを使ってlistViewにデータを設定しようとしています。私はtableIDとtableCapacityだけでtbl_tableを持っています。私は郵便配達員に私のphpcodeを走らせて、ログにも印刷してみました。問題はないようですので、私はJsonのコードを変換する方法が必要であると考えました。私はこのエラーが発生し続ける。事前のおかげで..アンドロイド4.1.2 APIここでは16ListViewにmySQLデータベースのデータを設定する
FATAL EXCEPTION: main
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was STRING at line 1 column 1
at com.google.gson.Gson.fromJson(Gson.java:815)
at com.google.gson.Gson.fromJson(Gson.java:768)
at com.google.gson.Gson.fromJson(Gson.java:717)
at com.kosalgeek.android.json.JsonConverter.toArrayList(JsonConverter.java:42)
at markjon.nobleza.qaldi.Table.onResponse(Table.java:51)
at markjon.nobleza.qaldi.Table.onResponse(Table.java:20)
で私のコードを実行しているイムは、私のコードです:
Table.class
public class Table extends AppCompatActivity implements Response.Listener<String> {
final String TAG = this.getClass().getSimpleName();
ListView tableLV;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_table);
String URL = "http://192.168.1.10/myDB/table.php";
StringRequest stringRequest = new StringRequest(Request.Method.GET, URL, this, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getApplicationContext(), "Error retrieving data", Toast.LENGTH_SHORT).show();
}
});
MySingleton.getInstance(getApplicationContext()).addToRequestQueue(stringRequest);
tableLV = (ListView)findViewById(R.id.tableList);
}
@Override
public void onResponse(String response) {
Log.d(TAG, response);
ArrayList<myTable> tableList = new JsonConverter<myTable>().toArrayList(response, myTable.class);
BindDictionary<myTable> dict = new BindDictionary<>();
dict.addStringField(R.id.tableNum, new StringExtractor<myTable>() {
@Override
public String getStringValue(myTable item, int position) {
return "" + item.tableID;
}
});
dict.addStringField(R.id.tableCap, new StringExtractor<myTable>() {
@Override
public String getStringValue(myTable item, int position) {
return "" + item.tableCapacity;
}
});
FunDapter<myTable> adapter = new FunDapter<>(getApplicationContext(), tableList, R.layout.table_layout, dict);
tableLV.setAdapter(adapter);
}
}
myTable.class
public class myTable {
@SerializedName("tableID")
public int tableID;
@SerializedName("tableCapacity")
public int tableCapacity;
}
これらの2行のエラーポイント:
public class Table extends AppCompatActivity implements Response.Listener<String>
ArrayList<myTable> tableList = new JsonConverter<myTable>().toArrayList(response, myTable.class);