我有一个String,我想从中解析一个整数,并且找不到超出此运行时异常的方法.我理解它有时会显示一个parseNUMBERTYPE函数应用于一个不恰当定义的String,并且代码期望数字的空格或字母可以触发它.但是,我用作测试虚拟的字符串就我简单地说数字5.我已经看到了几个建议,以响应其他用户的NumberFormatException问题,主张在解析之前应用trim()函数,我尝试过这个没有成功.
我也尝试用简单的,未存储的值"5"替换我想要解析的String.这与程序似乎报告为相关变量的存储字符串值相同,但在解析该变量时,由于此帖子的同名异常,未存储的值似乎在其位置上运行得非常好.
请注意,String变量由文件扫描程序读取.我必须假设我的问题与未知的,不需要的,"不可见的"字符有关,这些字符除了第五个之外还被读取,但我无法确定为什么会发生这种情况或如何阻止它.该文件格式为.txt
这是我的代码:
Scanner scan = new Scanner(System.in);
System.out.println("Please enter the file name:");
String filename = scan.nextLine();
File tempfile = new File(filename);
Scanner filereader = new Scanner(tempfile);
//this is meant to assign to the String line1 the numerical value (5)
//of the file's first line
String line1 = filereader.nextLine();
//this was added later to determine if line1 held the value I expect
//it outputs the single digit 5, as expected and appropriate
System.out.println(line1);
//this was added to test how …Run Code Online (Sandbox Code Playgroud) 我正在开发一个 Discord.js 机器人,除其他外,我希望它能够发布消息并跟踪添加了多少 :thumbsup: 表情符号作为反应。也就是说,我希望它专门计算 :thumbsup: 表情符号,而不是其他,并且每次删除 :thumbsup: 表情符号作为反应时,我希望它从计数器中删除 1 点。
我不久前为这个功能编写了最初的代码片段,但我为这个功能编写的代码不再有效,如果它确实完全有效的话。我相信我永远无法让反应消除事件正常工作。然而,最近我发现更重要的是,所有表情符号都会触发反应添加事件,而不仅仅是我在这里提到的表情符号。我将不胜感激任何 stackoverflow 能够为我的努力提供的帮助,以按预期完成以下工作。
msgChat.send("MESSAGE CONTENT").then(msgElement => {
const thumbFilter = (reaction) => { return reaction.emoji.name != 'thumbsup' };
const thumbCounter = msgElement.createReactionCollector(thumbFilter, {dispose: true, time: 28800000 });
var thumbCount = 0;
thumbCounter.on('collect', (r, c) => {
if (r.emoji.name == "thumbsup") {
thumbCount++;
if (thumbCount == 6) {
msgChat.send("Six thumbs were gathered");
thumbCounter.stop();
}
}
});
thumbCounter.on('remove', (r, c) => {
if (r.emoji.name == "thumbsup") {
thumbCount--;
}
});
thumbCounter.on('end', …Run Code Online (Sandbox Code Playgroud)