Trying to change string values to check if they're empty on my Android app?

Up vote -1 down vote favorite share g+ share fb share tw.

So, I'm getting a bunch of string values from a JSON object and then I'm printing them all. However, I wanted to put all the values in a String array and check to see if they're empty, and if so... change the value to "N/A" so they're not just blank. However, it recognizes which strings are blank but when I check them in the logcat, it doesn't print the name of the string that's empty.

For instance, I know two strings are going to be empty, but when I check it with this: System.out. Println(nullChecki + "is empty"); "is empty" just shows up twice in the logcat. And even if I want to change the values of ANY of them, it still won't do it.

It retrieves all of the strings that have data in them and prints them out just fine. I might be just overlooking something incredibly easy, but I would appreciate any help. Here's the full snippet for reference: String supplieraddress = ""; String supplierphone = ""; String supplieremail = ""; String supplierfax = ""; String vouchercontact = ""; String supplierid = ""; String suppliername = ""; String servicetype = ""; String serviceid = ""; String vouchernotes = ""; try { voucher = reservation.

GetJSONArray("vouchers"). GetJSONObject(vouchNumber); supplieraddress = voucher. GetString("supplieraddress"); supplierphone = voucher.

GetString("supplierphone"); supplieremail = voucher. GetString("supplieremail"); supplierfax = voucher. GetString("supplierfax"); vouchercontact = voucher.

GetString("vouchercontact"); supplierid = voucher. GetString("supplierid"); suppliername = voucher. GetString("suppliername"); servicetype = voucher.

GetString("servicetype"); serviceid = voucher. GetString("serviceid"); vouchernotes = voucher. GetString("vouchernotes"); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } String nullCheck = {supplieraddress, supplierphone, supplieremail, supplierfax, vouchercontact, supplierid, suppliername, servicetype, serviceid, vouchernotes}; for(int I = 0; I Supplier Address " + supplieraddress + "Supplier Phone " + supplierphone + "Supplier Email " + supplieremail + "Supplier Fax " + supplierfax + "Voucher Contact " + vouchercontact + "Supplier ID " + supplierid + "Supplier Name " + suppliername + "Service Type " + servicetype + "Service ID " + serviceid + "Voucher Notes " + vouchernotes )); } Thanks guys!

Android json for-loop string-array link|improve this question asked 2 days agoOriginJM32.

Also, you're checking for empty strings, but there's nowhere that you're checking if anything is null, so "nullcheck" should really be named "emptyCheck" – Alexander Lucas 2 days ago Yup, sorry buddy. NullCheck was something from another class I just didn't change, sorry for the confusing. I was basically trying to say "why is it not changing it to N/A" but instead I just came off incoherent.

– OriginJM 2 days ago.

Do it in your try block like this: String s = voucher. GetString("supplieraddress"); supplieraddress = TextUtils. IsEmpty(s)?

"N/A" : s; s = voucher. GetString("supplierphone"); supplierphone = TextUtils. IsEmpty(s)?

"N/A" : s; s = voucher. GetString("supplieremail"); supplieremail = TextUtils. IsEmpty(s)?

"N/A" : s; // and so on....

Excellent! Works like a charm, really appreciate it man. – OriginJM 2 days ago Is there a way to do this in a for loop by chance?

– OriginJM 2 days ago no, because you need to fetch each string out from json with a different key-name – Waqas 2 days ago.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions