在本文中,我们将给您介绍关于输入字符串“1”的java.lang.NumberFormatException的详细内容,并且为您解答输入一个字符串java的相关问题,此外,我们还将为您提供关于"xce
在本文中,我们将给您介绍关于输入字符串“ 1”的java.lang.NumberFormatException的详细内容,并且为您解答输入一个字符串java的相关问题,此外,我们还将为您提供关于"xception in thread "main" java.lang.NumberFormatException: For input string: "20、
- 输入字符串“ 1”的java.lang.NumberFormatException(输入一个字符串java)
- "xception in thread "main" java.lang.NumberFormatException: For input string: "20
- 抛出 java.lang.NumberFormatException:对于输入字符串:“titre”">
- 抛出 java.lang.NumberFormatException:对于输入字符串:“titre”
- android – java.lang.NumberFormatException:无效的int:“”EXCEPTION
- java – 从字符串转换为字节时的NumberFormatException
输入字符串“ 1”的java.lang.NumberFormatException(输入一个字符串java)
所以,我有一个问题真的困扰我。我有一个用Java开发的简单解析器。这是相关代码:
while( (line = br.readLine())!=null){ String splitted[] = line.split(SPLITTER); int docNum = Integer.parseInt(splitted[0].trim()); //do something}
输入文件是CSV文件,文件的第一项是整数。当我开始解析时,我立即得到这个异常:
Exception in thread "main" java.lang.NumberFormatException: For input string: "1"at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)at java.lang.Integer.parseInt(Integer.java:580)at java.lang.Integer.parseInt(Integer.java:615)at dipl.parser.TableParser.parse(TableParser.java:50)at dipl.parser.DocumentParser.main(DocumentParser.java:87)
我检查了文件,它的第一个值确实为1(该字段中没有其他字符),但仍然收到消息。我认为这可能是由于文件编码所致:它是UTF-8,带有Unix终端。该程序在Ubuntu
14.04上运行。欢迎寻找问题的任何建议。
答案1
小编典典您在该编号前面有一个BOM;如果我复制"1"
问题中的内容并将其粘贴到中vim
,则会看到您前面有一个FE
FF(例如BOM)。从该链接:
构成BOM的确切字节将是该转换格式将Unicode字符U + FEFF转换为的字节。
这就是问题所在,使用适当的读取器消耗文件以进行编码文件的转换(UTF-8,UTF-16大端,UTF-16小端等)。另请参阅此问题及其答案,以获取有关在Java中读取Unicode文件的更多信息。
"xception in thread "main" java.lang.NumberFormatException: For input string: "20
spark.SparkContext: Registered listener com.cloudera.spark.lineage.ClouderaNavigatorListener
"xception in thread "main" java.lang.NumberFormatException: For input string: "20
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:492)
at java.lang.Integer.valueOf(Integer.java:582)
at com.xiaodao.spark.examples.ml.AdaoKMeanService.main(AdaoKMeanService.java:166)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.spark.deploy.SparkSubmit$.org$apache$spark$deploy$SparkSubmit$$runMain(SparkSubmit.scala:730)
at org.apache.spark.deploy.SparkSubmit$.doRunMain$1(SparkSubmit.scala:181)
at org.apache.spark.deploy.SparkSubmit$.submit(SparkSubmit.scala:206)
at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:121)
at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)
17/10/12 17:42:02 INFO spark.SparkContext: Invoking stop() from shutdown hook
17/10/12 17:42:02 INFO ui.SparkUI: Stopped Spark web UI at http://192.168.1.30:4041
17/10/12 17:42:02 INFO spark.MapOutputTrackerMasterEndpoint: MapOutputTrackerMasterEndpoint stopped!
17/10/12 17:42:02 INFO storage.MemoryStore: MemoryStore cleared
抛出 java.lang.NumberFormatException:对于输入字符串:“titre”" alt="
抛出 java.lang.NumberFormatException:对于输入字符串:“titre”">
您有一个错误,因为您将一组书籍发送到 JSP 文件,但您试图将其用作单本书。
在您的 servlet 中,您正在执行:
request.setAttribute("livre",tableLivres.recupererLivres());
tableLivres.recupererLivres()
方法返回一个 List<Livres>
。这是一本书的合集,而不是一本书。但是在您的 JSP 中,您将此集合视为一本书并执行 ${livre.titre}
。
顺便说一句,你真的应该把单复数 Livre
弄得一团糟。你的类应该叫Livre
而不是Livres
,因为它只是一本书。当您将集合发送到 JSP 时,它应该被称为 livres
,因为还有更多,如下所示:
request.setAttribute("livres",tableLivres.recupererLivres());
一旦你这样做了,那么在 JSP 中你需要把数据当作一个列表。在您的代码中,您将其视为一本书,EL 表达式引擎可能会尝试使用 titre
属性来索引列表,并从这里开始您的 NumberFormatException
。将 JSP 中的数据按原样处理:列表。 JSTL 可以帮助循环列表。如果您还没有它,请将其添加到您的项目中,然后在您的 JSP 中循环遍历列表,如下所示:
<ul>
<c:forEach items="${livres}" var="unLivre">
<li>
<c:out value="${unLivre.titre}" />
</li>
</c:forEach>
</ul>
请注意,我将属性名称更改为 livres
,因为它应该根据您正在执行的操作命名。
android – java.lang.NumberFormatException:无效的int:“”EXCEPTION
错误就行了
if (a=="" && b=="")
并且也在线
int result = Integer.parseInt(a) + Integer.parseInt(b); t1.setText(Integer.toString(result));
Calci.java
package com.example.calculator; import android.app.Activity; import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; import android.os.Bundle; import android.view.View; import android.view.inputmethod.InputMethodManager; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; public class Calci extends Activity { TextView t1; EditText e1,e2; Button add,sub,mul,div; Context c=this; String b,a; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_calci); e1 = (EditText) findViewById(R.id.EditText01); e2 = (EditText) findViewById(R.id.EditText02); add = (Button) findViewById(R.id.add); sub = (Button) findViewById(R.id.sub); mul = (Button) findViewById(R.id.mul); div = (Button) findViewById(R.id.div); t1 = (TextView) findViewById(R.id.textView1); a = e1.getText().toString(); b = e2.getText().toString(); add.setonClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { if (a=="" && b==""){ AlertDialog.Builder a1 = new AlertDialog.Builder(c); // Setting Dialog Title a1.setTitle("Alert Dialog"); // Setting Dialog Message a1.setMessage("PLEASE ENTER SOMETHING"); a1.setPositiveButton("yes",new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog,int button1) { // if this button is clicked,close // current activity dialog.cancel(); } }); // Showing Alert Message AlertDialog alertDialog = a1.create(); a1.show(); } else{ int result = Integer.parseInt(a) + Integer.parseInt(b); t1.setText(Integer.toString(result)); InputMethodManager imm = (InputMethodManager)getSystemService( Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(add.getwindowToken(),0); } } }); } }
logcat的:
03-19 15:42:21.165: E/Trace(25381): error opening trace file: Permission denied (13) 03-19 15:42:21.165: D/ActivityThread(25381): setTargetHeaputilization:0.25 03-19 15:42:21.165: D/ActivityThread(25381): setTargetHeapIdealFree:8388608 03-19 15:42:21.165: D/ActivityThread(25381): setTargetHeapConcurrentStart:2097152 03-19 15:42:21.385: D/libEGL(25381): loaded /system/lib/egl/libEGL_adreno200.so 03-19 15:42:21.465: D/libEGL(25381): loaded /system/lib/egl/libGLESv1_CM_adreno200.so 03-19 15:42:21.475: D/libEGL(25381): loaded /system/lib/egl/libGLESv2_adreno200.so 03-19 15:42:21.475: I/Adreno200-EGL(25381): <qeglDrvAPI_eglInitialize:299>: EGL 1.4 QUALCOMM build: (Merge) 03-19 15:42:21.475: I/Adreno200-EGL(25381): Build Date: 07/09/13 Tue 03-19 15:42:21.475: I/Adreno200-EGL(25381): Local Branch: AU_41 03-19 15:42:21.475: I/Adreno200-EGL(25381): Remote Branch: 03-19 15:42:21.475: I/Adreno200-EGL(25381): Local Patches: 03-19 15:42:21.475: I/Adreno200-EGL(25381): Reconstruct Branch: 03-19 15:42:21.675: D/Openglrenderer(25381): Enabling debug mode 0 03-19 15:42:24.325: D/AndroidRuntime(25381): Shutting down VM 03-19 15:42:24.325: W/dalvikvm(25381): threadid=1: thread exiting with uncaught exception (group=0x41972378) 03-19 15:42:24.395: E/AndroidRuntime(25381): FATAL EXCEPTION: main 03-19 15:42:24.395: E/AndroidRuntime(25381): java.lang.NumberFormatException: Invalid int: "" 03-19 15:42:24.395: E/AndroidRuntime(25381): at java.lang.Integer.invalidInt(Integer.java:138) 03-19 15:42:24.395: E/AndroidRuntime(25381): at java.lang.Integer.parseInt(Integer.java:359) 03-19 15:42:24.395: E/AndroidRuntime(25381): at java.lang.Integer.parseInt(Integer.java:332) 03-19 15:42:24.395: E/AndroidRuntime(25381): at com.example.calculator.Calci$1.onClick(Calci.java:67) 03-19 15:42:24.395: E/AndroidRuntime(25381): at android.view.View.performClick(View.java:4147) 03-19 15:42:24.395: E/AndroidRuntime(25381): at android.view.View$PerformClick.run(View.java:17161) 03-19 15:42:24.395: E/AndroidRuntime(25381): at android.os.Handler.handleCallback(Handler.java:615) 03-19 15:42:24.395: E/AndroidRuntime(25381): at android.os.Handler.dispatchMessage(Handler.java:92) 03-19 15:42:24.395: E/AndroidRuntime(25381): at android.os.Looper.loop(Looper.java:213) 03-19 15:42:24.395: E/AndroidRuntime(25381): at android.app.ActivityThread.main(ActivityThread.java:4787) 03-19 15:42:24.395: E/AndroidRuntime(25381): at java.lang.reflect.Method.invokeNative(Native Method) 03-19 15:42:24.395: E/AndroidRuntime(25381): at java.lang.reflect.Method.invoke(Method.java:511) 03-19 15:42:24.395: E/AndroidRuntime(25381): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789) 03-19 15:42:24.395: E/AndroidRuntime(25381): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556) 03-19 15:42:24.395: E/AndroidRuntime(25381): at dalvik.system.NativeStart.main(Native Method) 03-19 15:42:25.685: I/Process(25381): Sending signal. PID: 25381 SIG: 9
任何人都知道如何解决这些堆栈跟踪错误.
解决方法
a = e1.getText().toString().trim(); b = e2.getText().toString().trim(); if (a.equals("") && b.equals("") ){ }
java – 从字符串转换为字节时的NumberFormatException
String s = "01001100"; byte b = Byte.parseByte(s);
但为什么会这样呢?而在一个字节中我们可以存储最大数量.最多127和分钟高达-128.
并且上述数字的十进制等值是76,完全在该范围内.
我得到的特殊例外是:
java.lang.NumberFormatException:值超出范围.值:01001100基数:10
有没有办法摆脱它.是的,我必须使用字节,因为我只是逐字节地提取存储在图像中的数据.
谢谢.
解决方法
String s = "01001100"; byte b = Byte.parseByte(s,2);
今天关于输入字符串“ 1”的java.lang.NumberFormatException和输入一个字符串java的介绍到此结束,谢谢您的阅读,有关"xception in thread "main" java.lang.NumberFormatException: For input string: "20、
本文标签: