标记“无效字符”存在语法错误,请删除该标记
我不确定为什么会出现此错误。大括号似乎是正确的。另一件事是,相同的程序可以在 Windows-eclipse 中运行,但不能在 Mac 的 eclipse 中运行。可能是什么原因?
import java.util.Vector;
public class Debug
{
private int something = 0;
private Vector list = new Vector();
public void firstMethod()
{
thirdMethod(something);
something = something + 1;
}
public void secondMethod()
{
thirdMethod(something);
something = something + 2;
}
public void thirdMethod(int value)
{
something = something + value;
}
public static void main(String[] args)
{
Debug debug = new Debug();
debug.firstMethod();
debug.secondMethod();
}
}
I am not sure why is it giving this error. Braces seem to be right. Another thing is that the same program works in Windows-eclipse but not in eclipse for Mac. What could be the reason?
import java.util.Vector;
public class Debug
{
private int something = 0;
private Vector list = new Vector();
public void firstMethod()
{
thirdMethod(something);
something = something + 1;
}
public void secondMethod()
{
thirdMethod(something);
something = something + 2;
}
public void thirdMethod(int value)
{
something = something + value;
}
public static void main(String[] args)
{
Debug debug = new Debug();
debug.firstMethod();
debug.secondMethod();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(11)
我解决这个问题的唯一方法是按 Ctrl+A 选择文件的所有文本,然后按 Ctrl+C 复制它们,然后删除文件并使用 intellij idea 创建新类,然后按 Ctrl+P 将文本粘贴到新文件中。这解决了我的问题,并且编译器在执行此解决方案后永远不会显示错误。
Only way i could resolve this problem was press Ctrl+A to select all text of file then Ctrl+C to copy them then delete file and create new class with intellij idea then Ctrl+P to paste text in new file. this resolve my problem and compiler never show error after do this solution.
当我们复制和粘贴时,就会发生这种情况。当某些字符在一个平台上无法识别但在其他平台上可以识别时,就会发生这种情况。
我建议不要复制,而是尝试自己编写整个代码。应该有效
It can happen when we copy and paste .It happens when there may be some character which is unrecognized in one platform but recognized in other.
I would suggest don't copy rather try to write the entire code by yourself. It should work
当我将在 Mac 中创建的项目导入到 Windows 时,我遇到了同样的错误。正如 @Massimo 所说,Mac 创建 ._filename,java 文件,在 Windows 中运行的 Eclipse 将其视为源文件。这就是导致问题的原因。
它们是隐藏文件,当您在 Windows 计算机的文件夹选项下选择“显示隐藏文件和文件夹”选项时,您可以看到它们。删除这些文件即可解决问题。
I got the same error when I imported a project I created in a Mac, to Windows. As @Massimo says Mac creates ._filename,java files which eclipse running in windows consider as source files. This is what causes the problem.
They are hidden files, which you can see when you select the option, "Show hidden files and folders" under folder options in Windows machine. Deleting these files solves the problem.
我尝试从 tRunJob 组件调用子作业时收到此消息。在 tRunJob 中,我既选中了“传输整个上下文”,又在参数/值框中列出了各个参数。一旦我删除了附加参数,它就起作用了。
I got this message trying to call a subjob from a tRunJob component. In the tRunJob I had both checked "transmit whole context" AND listed individual parameters in the parameters/values box. Once I removed the additional parameters it worked.
行中可能有隐藏的字符。如果您在字符之间移动光标,但光标没有在一个字符中移动,则意味着该行中存在无效字符。删除那些,它应该可以工作。还可以尝试将该行复制并粘贴到十六进制编辑器,您将看到其中的无效字符。
There are probably hidden characters in the line. If you move your cursor through the characters and your cursor doesn't move in one character, that means there is an invalid character in the line. Delete those and it should work. Also try copying and pasting the line to an hex editor and you will see the invalid characters in it.
我在 eclipse 中多次遇到这个问题。我发现选择所有代码 - 使用 Ctrl + x 剪切它,然后保存文件并再次使用 Ctrl + V 粘贴代码。当我从另一个编辑器复制代码时,这对我来说很多次都有效。
i face this problem many times in eclipse . What i found is that select all code - cut it using Ctrl + x and then save the file and again paste the code using Ctrl + V . This works for me many times when i copy the code from another editor.
将代码从一台机器复制到另一台机器时我也遇到了类似的问题。
问题出在 Space 上,您只需要识别 Eclipse 代码中的红色标记。
I also faced similar issue while copying the code from one machine to another.
The issue was with Space only you need to identify the red mark in your eclipse code.
在 Windows 上,如果将源代码复制到记事本 - 保存文件(作为任何内容),确保选择 ASCI 编码 - 字符将转换为问号,然后您可以将其删除 - 然后将代码复制回 Eclipse。
On Windows, if you copy the source to Notepad - save the file (as anything), ensuring ASCI encoding is selected - the character will be converted to a question-mark which you can then delete - then copy the code back to Eclipse.
在eclipse中右键单击该文件->属性->资源
在文本文件编码中选择 US-ASCII
这样您将看到所有特殊字符,然后您可以找到 &代替
然后格式化代码
In eclipse right click on the file -> Properties -> resources
In Text file encoding select US-ASCII
This way you will see all the special char, you can then find & replace
And then format the code
啊,好的 - 它可能是文件末尾的 control-Z 或其他不可打印的字符,在 Windows 中会被忽略,但在 Mac 上不会。您将源从 Windows 复制到 Mac。删除最后几个字符并重新输入它们 - 我认为它会消失。不过,我不使用 Mac——我只是猜测。
Ah, ok - it's probably a control-Z or other unprintable character at the end of the file that is ignored in Windows but not on the Mac. You copied the source from Windows to the Mac. Delete the last few characters and re-enter them - I think it will go away. I don't do Mac, though - I'm just guessing.
我在将项目从 mac 导入到 linux Slackware 时遇到了同样的问题。
Mac OSX 会在所有文件夹中创建一些与文件夹 (._filename) 中的文件同名的临时文件。
通常这些文件在 Mac OSX 中是不可见的,但在其他操作系统中则不可见。
Eclipse 可以找到这些文件并尝试处理类似的源 (._filename.java)。
我解决了删除这些文件。
I had the same problem importing my projects from mac to linux Slackware.
Mac OSX creates some temporary files with the same name of the files in folders (._filename) in all folders.
Usually these files are invisible in Mac OSX, but in the other OSs no.
Eclipse can find these files and tries to handle like sources (._filename.java).
I solved deleting these files.