Setting json data to a TextView Using Ion library

2019-09-14 19:32发布

I am trying to look for a way of setting data of each object in json to a different TextView , but i don't know how to use the result of Json in the onCompleted method. Below is my JSON sample i want to retrieve.

[
  {
    "progname": "BACHELOR OF BUSINESS ADMINISTRATION",
    "gradSystem": "NCHE 2015",
    "entryno": "00458",
    "regno": "BABA/09/W/J0434",
    "firstname": "CHARLES",
    "dob": "/Date(220136400000)/",
    "gender": "MALE",
    "nationality": "UGANDAN",
    "religion": "-",
    "entrymethod": "DIRECT",
    "progid": "01307",
    "studPhone": "256772372062",
    "email": "-@-",
    "entryyear": 2009,
    "studsesion": "DAY",
    "home_dist": "-",
    "intake": "JANUARY",
    "gradSystemID": 1,
    "othername": "MUTABAZI",
    "duration": 3,
    "photofile": "mutabazi charles.png"
  }
]

This is the ion method

Ion.with(StudentsProfile.this)
                .load(url)
                .asJsonObject()
                .setCallback(new FutureCallback<JsonObject>() {
                    @Override
                    public void onCompleted(Exception e, JsonObject result) {
                        String reg =        result.toString();
                        reg_no.setText(reg);


                    }
                });

This is my full class .

public class StudentsProfile extends AppCompatActivity {


    String username = "username";

    TextView reg_no;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.students_profile);


      reg_no =(TextView) findViewById(R.id.registration_no);

        Intent inn = getIntent();
        if (null != inn) {
            username = inn.getStringExtra(Login.KEY_USERNAME);
            //District = inn.getStringExtra(BuyApartmentsOne.KEY_DISTRICT_NAME);




        }


        String url ="http://192.168.43.104:82:82/COOPERP/Mobile/Default.aspx?DataFormat=StudentBioData&regno="+username;

        Ion.with(StudentsProfile.this)
                .load(url)
                .asJsonObject()
                .setCallback(new FutureCallback<JsonObject>() {
                    @Override
                    public void onCompleted(Exception e, JsonObject result) {
                        // do stuff with the result or error
                       String reg =        result.toString();
                        reg_no.setText(reg);


                    }
                });






    }


    }

If i try to run the project this is the error which comes in the logcat

0-12 15:18:28.416 15645-29090/campus.app.com.newline.campusmobapp E/ProviderInstaller: libgmscore version mismatch (0 vs. 9683)
10-12 15:19:20.717 15645-15645/campus.app.com.newline.campusmobapp E/AndroidRuntime: FATAL EXCEPTION: main
                                                                                     Process: campus.app.com.newline.campusmobapp, PID: 15645
                                                                                     java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.google.gson.JsonObject.toString()' on a null object reference
                                                                                         at campus.app.com.newline.campusmobapp.StudentsProfile$1.onCompleted(StudentsProfile.java:58)
                                                                                         at campus.app.com.newline.campusmobapp.StudentsProfile$1.onCompleted(StudentsProfile.java:51)
                                                                                         at com.koushikdutta.async.future.SimpleFuture.handleCallbackUnlocked(SimpleFuture.java:107)
                                                                                         at com.koushikdutta.async.future.SimpleFuture.setComplete(SimpleFuture.java:141)
                                                                                         at com.koushikdutta.async.future.SimpleFuture.setComplete(SimpleFuture.java:124)
                                                                                         at com.koushikdutta.ion.IonRequestBuilder$1.run(IonRequestBuilder.java:244)
                                                                                         at com.koushikdutta.async.AsyncServer$RunnableWrapper.run(AsyncServer.java:60)
                                                                                         at android.os.Handler.handleCallback(Handler.java:739)
                                                                                         at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                                         at android.os.Looper.loop(Looper.java:211)
                                                                                         at android.app.ActivityThread.main(ActivityThread.java:5389)
                                                                                         at java.lang.reflect.Method.invoke(Native Method)
                                                                                         at java.lang.reflect.Method.invoke(Method.java:372)
                                                                                         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1020)
                                                                                         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:815)

.

0条回答
登录 后发表回答