简体   繁体   中英

Method called recursive onResume Activity java.lang.StackOverflowError: stack size 8MB

I am getting this exception in datetimeformat and it runs multiple ti

public String parseDateToddMMyyyy(String time) {
    String inputPattern = "yyyy-MM-dd";
    String outputPattern = "dd-MM-yyyy";
    SimpleDateFormat inputFormat = new SimpleDateFormat(inputPattern);
    SimpleDateFormat outputFormat = new SimpleDateFormat(outputPattern);

    Date date = null;
    String str = null;

    try {
        date = inputFormat.parse(time);
        str = outputFormat.format(date);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return str;
}

i am getting below exception

Fatal Exception: java.lang.StackOverflowError: stack size 8MB
   at com.pixako.trackn.BaseActivity.parseDateToddMMyyyy(Unknown Source)
   at com.pixako.trackn.BaseActivity.parseDateToddMMyyyy(Unknown Source)
   at com.pixako.trackn.BaseActivity.parseDateToddMMyyyy(Unknown Source)
   at com.pixako.trackn.BaseActivity.parseDateToddMMyyyy(Unknown Source)
   at com.pixako.trackn.BaseActivity.parseDateToddMMyyyy(Unknown Source)
   at com.pixako.trackn.BaseActivity.parseDateToddMMyyyy(Unknown Source)
   at com.pixako.trackn.BaseActivity.parseDateToddMMyyyy(Unknown Source)
   at com.pixako.trackn.BaseActivity.parseDateToddMMyyyy(Unknown Source)
   at com.pixako.trackn.BaseActivity.parseDateToddMMyyyy(Unknown Source)
   at com.pixako.trackn.BaseActivity.parseDateToddMMyyyy(Unknown Source)
   at com.pixako.trackn.JobListTest.onResume(Unknown Source)
   at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1277)
   at android.app.Activity.performResume(Activity.java:7142)
   at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3850)
   at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3914)
   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3070)
   at android.app.ActivityThread.-wrap14(ActivityThread.java)
   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1659)
   at android.os.Handler.dispatchMessage(Handler.java:102)
   at android.os.Looper.loop(Looper.java:154)
   at android.app.ActivityThread.main(ActivityThread.java:6823)
   at java.lang.reflect.Method.invoke(Method.java)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1563)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1451)

Here i am calling it

public void orderingResult(JSONArray Result) {    
for (int i = 0; i < Result.length(); i++) {
try {
     JSONObject jobj = Result.getJSONObject(i);
     try{               jobj.put("ausTimeJobDate",parseDateToddMMyyyy(jobj.getString("Job_Date")));
     }catch(Exception ex){
           ex.printStackTrace(); 
     }
  }catch(Exception ex){
       ex.printStackTrace();
  }

}

I am not able to understand why this function is calling multiple time

Note: this function is not recursive

How many times do you call this function? Create a SimpleDateFormat objects once, not every time you call.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM