I'm getting NumberFormatException: For input string: "4045989016914" while trying to format the string as the following
String.format("%013d", Integer.valueOf(itemMODEL.getCodiceArticolo()))
itemMODEL.getCodiceArticolo is a String that would be a barcode and i would to add 0 if it's shorted than 13 so the code i'm using should be right but i can't get why i'm getting that error.
2018-10-08 16:01:37.420 12670-12670/it.gabtamagnini.realco E/AndroidRuntime: FATAL EXCEPTION: main Process: it.gabtamagnini.realco, PID: 12670 java.lang.NumberFormatException: For input string: "4045989016914" at java.lang.Integer.parseInt(Integer.java:524) at java.lang.Integer.valueOf(Integer.java:611) at it.gabtamagnini.realco.InventarioActivity.Tracciato(InventarioActivity.java:471) at it.gabtamagnini.realco.InventarioActivity$9.onClick(InventarioActivity.java:429) at android.view.View.performClick(View.java:5637) at android.view.View$PerformClick.run(View.java:22433) at android.os.Handler.handleCallback(Handler.java:751) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6130) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Integer.valueOf(). Just use%sand pass the String as an argument to the formatter directly.