Logcat 출력에 NumberFormatException이 발생했습니다.이를 억제하려고합니다. 외관상으로는이 예외는 Huawei 장치에서만 발생합니다. 어떤 이유로 내 catch() 블록이 실행되지 않습니다. 누군가 제발 도와주십시오 :NumberFormatException을 캐치 할 수 없습니다.
특히, 내 catch() 코드가 호출되지 않은 이유를 알고 싶습니다.
Locale locale = Locale.getDefault();
System.out.println("Locale is : [" + locale + "]"); // make sure there is a default Locale
System.out.printf("==Before try{}\n");
try
{
System.out.printf("---Line44\n");
Calendar c = Calendar.getInstance(locale);
System.out.printf("---Line46\n");
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.printf("---Line48\n");
String formattedDate = df.format(c.getTime());
System.out.printf("---Line50\n");
System.out.printf("Timestamp : %s\n", formattedDate);
System.out.printf("---Line52\n");
}
catch(java.lang.NumberFormatException e)
{
// Ignore stupid exception - Huawei specific apparently..
System.out.printf("HUAWEI bug\n");
}
System.out.printf("==After Entire Block, Line60\n");
은 자세한 내용은 화웨이 버그 here을 언급하지만 확실히 내 시도/catch 문에 문제가있을해야합니까?
10-01 11:07:53.402: I/System.out(1758): ==Before try{}
10-01 11:07:53.402: I/System.out(1758): ---Line44
10-01 11:07:53.432: W/System.err(1758): java.lang.NumberFormatException: Invalid int: ""
10-01 11:07:53.432: W/System.err(1758): at java.lang.Integer.invalidInt(Integer.java:138)
10-01 11:07:53.432: W/System.err(1758): at java.lang.Integer.parseInt(Integer.java:359)
10-01 11:07:53.432: W/System.err(1758): at java.lang.Integer.parseInt(Integer.java:332)
10-01 11:07:53.432: W/System.err(1758): at java.util.Calendar.getHwFirstDayOfWeek(Calendar.java:807)
10-01 11:07:53.432: W/System.err(1758): at java.util.Calendar.<init>(Calendar.java:745)
10-01 11:07:53.432: W/System.err(1758): at java.util.GregorianCalendar.<init>(GregorianCalendar.java:338)
10-01 11:07:53.442: W/System.err(1758): at java.util.GregorianCalendar.<init>(GregorianCalendar.java:314)
10-01 11:07:53.442: W/System.err(1758): at java.util.Calendar.getInstance(Calendar.java:1098)
10-01 11:07:53.442: W/System.err(1758): at com.example.test.MyApplication.onCreate(MyApplication.java:45)
10-01 11:07:53.442: W/System.err(1758): at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:969)
10-01 11:07:53.442: W/System.err(1758): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3954)
10-01 11:07:53.442: W/System.err(1758): at android.app.ActivityThread.access$1300(ActivityThread.java:123)
10-01 11:07:53.442: W/System.err(1758): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1185)
10-01 11:07:53.442: W/System.err(1758): at android.os.Handler.dispatchMessage(Handler.java:99)
10-01 11:07:53.442: W/System.err(1758): at android.os.Looper.loop(Looper.java:137)
10-01 11:07:53.442: W/System.err(1758): at android.app.ActivityThread.main(ActivityThread.java:4424)
10-01 11:07:53.442: W/System.err(1758): at java.lang.reflect.Method.invokeNative(Native Method)
10-01 11:07:53.442: W/System.err(1758): at java.lang.reflect.Method.invoke(Method.java:511)
10-01 11:07:53.442: W/System.err(1758): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:787)
10-01 11:07:53.442: W/System.err(1758): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554)
10-01 11:07:53.442: W/System.err(1758): at dalvik.system.NativeStart.main(Native Method)
10-01 11:07:53.442: I/System.out(1758): ---Line46
10-01 11:07:53.452: I/System.out(1758): ---Line48
10-01 11:07:53.462: I/System.out(1758): ---Line50
10-01 11:07:53.462: I/System.out(1758): Timestamp : 2014-10-01 11:07:53
10-01 11:07:53.462: I/System.out(1758): ---Line52
10-01 11:07:53.462: I/System.out(1758): ==After Entire Block, Line61
중복 가능한 [java.lang.NumberFormatException : 잘못된 int : ""] (http://stackoverflow.com/questions/20574141/java-lang-numberformatexception-invalid-int) – Rick77
@ Rick77 : 아니요, 그 아닙니다 가능한 복제본. catch() 블록을 실행하고 싶습니다. 그게 내 문제 야. – SparkyNZ
확인하려면 예외 블록이 표시된 catch 블록에서 확실히 throw되고 있습니다 (44 행). catch 유형을 '예외'로 변경하면 어떻게됩니까? – deyur