【发布时间】:2022-01-18 21:40:53
【问题描述】:
我正在 Android Studio 上创建一个从 MYSQL 数据库获取信息的表,它应该返回 2 行,但它返回的是这个错误代码。我需要它能够根据我从数据库获得的行数自动创建行。
请帮忙!
这是来自表 xml 的代码。
<?xml version="1.0" encoding="utf-8"?>
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/table"
tools:context=".foliosMonitor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:layout_editor_absoluteX="1dp"
tools:layout_editor_absoluteY="1dp"
>
<TableRow
android:layout_width="match_parent"
android:layout_height="73dp"
android:background="#205FA1">
<TextView
android:id="@+id/ticketIdName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:fontFamily="@font/raleway"
android:textColor="@color/white"
android:layout_marginRight="8dp"
android:text="TicketId" />
<TextView
android:id="@+id/truckplatesName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:fontFamily="@font/raleway"
android:textColor="@color/white"
android:layout_marginRight="8dp"
android:text="TruckPlates" />
<TextView
android:id="@+id/ecoTruckName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:fontFamily="@font/raleway"
android:textColor="@color/white"
android:layout_marginRight="8dp"
android:text="EcoTruck" />
<TextView
android:id="@+id/statusName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:fontFamily="@font/raleway"
android:textColor="@color/white"
android:layout_marginRight="8dp"
android:text="Status" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="73dp"
android:layout_marginTop="5dp"
android:background="#D8D8D8">
<TextView
android:id="@+id/ticketId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:fontFamily="@font/raleway"
android:text="TicketId"
android:onClick="editTabla"
android:textColor="@color/black" />
<TextView
android:id="@+id/truckplates"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:fontFamily="@font/raleway"
android:text="TruckPlates"
android:textColor="@color/black" />
<TextView
android:id="@+id/ecoTruck"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:fontFamily="@font/raleway"
android:text="EcoTruck"
android:textColor="@color/black" />
<TextView
android:id="@+id/status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:fontFamily="@font/raleway"
android:textColor="@color/black"
android:layout_marginRight="8dp"
android:text="Status" />
</TableRow>
</TableLayout>
这是在活动上创建表格的空白
public void readTable(){
View registro = LayoutInflater.from(this).inflate(R.layout.table_row_monitor, null, false);
String URLFETCHTABLE = "https://www.cedepaser.com.mx/TruckParking/App/php/getTicketTable.php?customerId=" + customerId;
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET,
URLFETCHTABLE,
null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
JSONArray jsonArray = response.getJSONArray("ticket");
for(int i = 0; i<=jsonArray.length() - 1; i++){
Log.d("valueOfI", String.valueOf(i));
Log.d("ARRAYLENGTH", String.valueOf(jsonArray.length()));
JSONObject jsonObject = jsonArray.getJSONObject(i);
TextView ticketId = registro.findViewById(R.id.ticketId);
TextView truckPlates = registro.findViewById(R.id.truckplates);
TextView ecoTruck = registro.findViewById(R.id.ecoTruck);
TextView status = registro.findViewById(R.id.status);
ticketId.setText(jsonObject.getString("ticketId"));
truckPlates.setText(jsonObject.getString("truckPlates"));
ecoTruck.setText(jsonObject.getString("ecoTruck"));
status.setText(jsonObject.getString("idStatus"));
tbUsuarios.addView(registro);
iCount = i;
}
Log.d("iCount", String.valueOf(iCount));
} catch (JSONException e) {
e.printStackTrace();
Log.d("ARRAYLENGTH", "ENTRO AL CATCH");
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
});
requestQueue.add(jsonObjectRequest);
}
【问题讨论】:
标签: android mysql database android-studio row