0
votes

I am using asyntask to enter value in database. in do in backgroud method i am calling this method.

           private void callLogin() {
             GetDataFromApi getDataFromApi = new GetDataFromApi(url);

             if (!isTableFalse) {
              Log.e("MAI A GAAYA SYNCRONISE DATA BASE MAI", "HA MAI AYA");
             String message = 
   getDataFromApi.postSignIn().toString().trim();
              syncroniseDatabase(message);
              populateChurchListOnValidating
                    .populateChurchList(parseJsonToArrayList());
            } else {
              try {
                 loginValue = 
              Integer.parseInt(getDataFromApi.postSignIn());
                     Log.e("Login VAlue", "" + loginValue);
               } catch (NumberFormatException nfe) {
                 nfe.printStackTrace();
             }
         }
         }

and my syncroniseDatabase(message) is like this

      private void syncroniseDatabase(String mesString) {

Log.e("URL IN SYNCRONISATION", ""+ url);

              try {
               InsertTable insertTable = new InsertTable();
               JSONObject jsonObject = new JSONObject(mesString);
      insertTable.addRowforMemberTable(jsonObject.getString(
      RegistrationAppConstant.MEMBER_ID),

        jsonObject.getString(RegistrationAppConstant.CLIENT_ID),

        jsonObject.getString(RegistrationAppConstant.FIRSTNAME),

        jsonObject.getString(RegistrationAppConstant.SURNAME),

        jsonObject.getString(RegistrationAppConstant.EMAIL_ID),

       jsonObject.getString(RegistrationAppConstant.PASSWORD));
               Log.e("Inserting Data DONE", "" + "Done");
           } catch (JSONException e) {
             // TODO Auto-generated catch block
             e.printStackTrace();
         }
     }

and my class forInsertTable is like this

        public class InsertTable {

       public void addRowforMemberTable(String memberID, 
           String clientID, String 
               firstName,String surName, String emailIDString, String passWordString) 
            {
           Log.e("NAME", "" + memberID + "  " + clientID + " " + firstName + " "
                + surName + " " + emailIDString + " " + 
                  passWordString);

           ContentValues contentValue = new ContentValues();

         contentValue.put(AppConstant.MCM_MEMBER_MEMEBER_ID, memberID);
         contentValue.put(AppConstant.MCM_MEMBER_CLIENT_ID, clientID);
         contentValue.put(AppConstant.MCM_MEMBER_FIRST_NAME, firstName);
          contentValue.put(AppConstant.MCM_MEMBER_LAST_NAME, surName);
          contentValue.put(AppConstant.MCM_MEMBER_EMAIL_ID, emailIDString);
          contentValue.put(AppConstant.MCM_MEMBER_PASSWORD, passWordString);
         Log.e("Cotent value", "" + contentValue);

          try {

      SplashActivity.databaseHelper.insertInToTable(
      SplashActivity.databaseHelper.getWritableDatabase(),
                        AppConstant.MEMBER_TABLE_NAME,  
                            contentValue);
                    }

            catch (Exception e) {
        e.printStackTrace();
          }
       }
       }

this is my json String

[{"MemberId":77,"ClientId":37,"FirstName":"John","SurName":"Banian","Address1":null,"Address2":null,"Street":null,"Town":null,"City":null,"County":null,"State":null,"Country":null,"PostCode":null,"Mobile":null,"HomeTelephone":null,"WorkTelephone":null,"EmailId":"[email protected]","ConfirmEmailId":null,"Password":"123","Age":null,"Sex":null,"Profession":null,"MartialStatus":null,"Nationality":null,"Children":null,"ChurchMembershipId":null,"SecurityQuestion":null,"SecurityAnswer":null,"IsApproved":null,"IsLockedOut":null,"CreateDate":null,"LastLoginDate":null,"LastPasswordChangedDate":null,"LastLogOutDate":null,"FailedPasswordAttemptDate":null,"FailedPasswordAttemptWindowStart":null,"FailedPasswordAnswerAttemptCount":null,"FailedPasswordAnswerAttemptWindowStart":null,"Comment":null,"Active":null,"IsAuthToApproveNewMember":null,"Record_Created":null,"Record_Updated":null,"LastUpdated_LoginUserID":null,"LastUpdated_WindowsUser":null,"ClientAdminEmailId":null,"EmailListForApproval":null,"AppRegistrationStatus":null,"MemberEmailMessage":null,"AdminEmailMessage":null,"PhysicalDeviceId":null,"DeviceOS":null,"DeviceIdFromGCMorAPNS":null,"DeviceType":null}]

but my code will not executing after this line and hence i am not able to insert value.I have bold the log after which its not executing.please tell why its not executing?

1
Have you read logcat? Is any exception here?Divers
there is no exception in logcat.Nirmal
You see this - "URL IN SYNCRONISATION" and don't see this "Inserting Data DONE" as well as no exceptions here? Then it's a miracle and you have to report about it to Pope.Divers
i find something it saying value of type json array cannot be converted to json string. why is that?Nirmal
Add Log.d("JSON string", mesString); and add in question your JSON string.Divers

1 Answers

0
votes

Problem is that you tring to get values from JSONObject, but in reality it's JSON array. (json string starts with [.

Try to do something like this:

      JSONArray jsonArray = new JSONArray(mesString);
      JSONObject jsonObject = jsonArray.get(0);
      insertTable.addRowforMemberTable(jsonObject.getString(RegistrationAppConstant.MEMBER_ID),
jsonObject.getString(RegistrationAppConstant.CLIENT_ID),
.....
.....