称为递归onResume活动java.lang.StackOverflowError的方法:堆栈大小8MB

时间:2018-07-16 14:01:13

标签: java android out-of-memory

我在datetimeformat中遇到此异常,它运行多个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;
}

我正在接受例外

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)

我在这里叫它

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();
  }

}

我不明白为什么该函数多次调用

注意:此函数不是递归的

1 个答案:

答案 0 :(得分:0)

您多次调用此函数?一次创建一个SimpleDateFormat对象,而不是每次都创建一次。