Java 在最后一个数组中拾取数据(android)

Java 在最后一个数组中拾取数据(android),java,android,arrays,json,android-edittext,Java,Android,Arrays,Json,Android Edittext,我需要帮助来选取最后一个数组中的数据,然后在编辑文本中显示,以下是我的代码: izinnfullday.java(主) 活动_izinnfullday.xml(xml) 我想在编号为pengajuan的edittext中显示该数据,这是最后一个数组 你们能解决吗?我很感激…修复强制关闭而不是使用(您不能直接将整数值设置为edittext) 使用 将try块更改为低于1 try { JSONObject obj = new JSONObject(response); JS

我需要帮助来选取最后一个数组中的数据,然后在编辑文本中显示,以下是我的代码:

izinnfullday.java(主)

活动_izinnfullday.xml(xml)


我想在编号为pengajuan的edittext中显示该数据,这是最后一个数组


你们能解决吗?我很感激…

修复强制关闭而不是使用(您不能直接将整数值设置为edittext)

使用

将try块更改为低于1

try {
     JSONObject obj = new JSONObject(response);
     JSONArray movieArray = obj.getJSONArray("data");
     for (int i = 0; i < movieArray.length(); i++) {
         JSONObject movieObject = movieArray.getJSONObject(i);
         postnonfullmodel nomor = new postnonfullmodel(movieObject.getInt("no_pengajuan_non_full"));
         no_pengajuan.add(nomor);
     }
     // To get the last time from list
     postnonfullmodel item = no_pengajuan.get(no_pengajuan.size()-1)
     // Set value to edit text
     nopengajuan.setText(String.valueOf(item.getNo_pengajuan_non_full()));
} catch (JSONException e) {
   e.printStackTrace();
}
试试看{
JSONObject obj=新的JSONObject(响应);
JSONArray movieArray=obj.getJSONArray(“数据”);
对于(int i=0;i
您是否收到任何错误?是的,不显示+强制关闭强制关闭,因为这行`nopengajuan.setText(nomor.getNo_pengajuan_non_full())`您不能直接将整数值设置为editText尝试使用`nopengajuan.setText(String.valueOf(nomor.getNo_pengajuan_non_full())`在edittexti中没有显示任何数据,但它没有显示数据,但强制关闭解决了,对吗?是的,它在所有情况下都起作用尝试调试并检查从API响应中获得的数据,并将数据设置为编辑文本从for循环外部移动代码,我必须从for循环外部放置编辑文本?我试过了,但它总是保持红色

public class postnonfullmodel {
    Integer no_pengajuan_non_full;

    public postnonfullmodel(Integer no_pengajuan_non_full){
        this.no_pengajuan_non_full = no_pengajuan_non_full;
    }
    public Integer getNo_pengajuan_non_full() {return no_pengajuan_non_full; }
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".izinnonfullday">
    <TextView
        android:id="@+id/nonfullday"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="25dp"
        android:textColor="@color/colorPrimaryDark"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="32dp"
        android:text = "Izin Non Full Day" />

    <Button
        android:id="@+id/list_data"
        android:layout_width="wrap_content"
        android:layout_height="36dp"
        android:layout_centerHorizontal="true"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="35dp"
        android:layout_toRightOf="@+id/nonfullday"
        android:text="list data" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="No.pengajuan"
        android:editable="false"
        android:layout_marginLeft="12dp"
        android:layout_marginTop="32dp"
        android:layout_below="@id/nonfullday"
        android:textColor="#000000"
        android:textSize="20dp"/>
    <EditText
        android:id="@+id/nopengajuan"
        android:layout_width="241dp"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/textView1"
        android:layout_marginLeft="23dp"
        android:layout_marginTop="95dp"
        android:hint="nomor pengajuan"
        android:textColor="#000000"
        android:selectAllOnFocus="true"/>

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Mulai Tanggal"
        android:layout_marginLeft="12dp"
        android:layout_marginTop="22dp"
        android:layout_below="@id/nopengajuan"
        android:textColor="#000000"
        android:textSize="20dp"/>
    <EditText
        android:id="@+id/tanggalizinnonfull"
        android:layout_width="241dp"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/textView2"
        android:layout_marginLeft="23dp"
        android:layout_below="@id/nopengajuan"
        android:layout_marginTop="5dp"
        android:hint="tanggal pengajuan"
        android:clickable="true"
        android:focusable="false"
        android:inputType="datetime"
        android:textColor="#000000"
        android:selectAllOnFocus="true"/>

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Jenis Izin"
        android:layout_marginLeft="12dp"
        android:layout_marginTop="22dp"
        android:layout_below="@id/textView2"
        android:textColor="#000000"
        android:textSize="20dp"/>
    <Spinner
        android:id="@+id/jenisizin"
        android:layout_width="241dp"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/textView3"
        android:layout_below="@id/tanggalizinnonfull"
        android:hint="jenis izin"
        android:layout_marginTop="10dp"
        />

    <TextView
        android:id="@+id/textView4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Keterangan Tambahan"
        android:layout_marginLeft="12dp"
        android:layout_marginTop="22dp"
        android:layout_below="@id/jenisizin"
        android:textColor="#000000"
        android:textSize="20dp"/>
    <EditText
        android:id="@+id/keterangan"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/textView4"
        android:ems="1000"
        android:inputType="text"
        android:hint="keterangan"
        android:text="" />

    <Button
        android:id="@+id/pengajuan"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/keterangan"
        android:layout_centerHorizontal="true"
        android:text="pengajuan"
        android:layout_marginTop="15dp" />
</RelativeLayout>
nopengajuan.setText(nomor.getNo_pengajuan_non_full());
nopengajuan.setText(String.valueOf(nomor.getNo_pengajuan_non_full()));
try {
     JSONObject obj = new JSONObject(response);
     JSONArray movieArray = obj.getJSONArray("data");
     for (int i = 0; i < movieArray.length(); i++) {
         JSONObject movieObject = movieArray.getJSONObject(i);
         postnonfullmodel nomor = new postnonfullmodel(movieObject.getInt("no_pengajuan_non_full"));
         no_pengajuan.add(nomor);
     }
     // To get the last time from list
     postnonfullmodel item = no_pengajuan.get(no_pengajuan.size()-1)
     // Set value to edit text
     nopengajuan.setText(String.valueOf(item.getNo_pengajuan_non_full()));
} catch (JSONException e) {
   e.printStackTrace();
}