eclipse 处理重构“重命名包”时捕获异常

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5695835/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 16:11:41  来源:igfitidea点击:

exception has been caught while processing the refactoring 'Rename package'

javaeclipserefactoring

提问by Android Eve

This refactoring function in Eclipse for package names used to work for me fine until... today:

Eclipse 中用于包名称的此重构功能过去一直对我有用,直到……今天:

This is the first time I am receiving this weird Refactoring error, and I have no idea what to make of it:

这是我第一次收到这个奇怪的重构错误,我不知道该怎么做:

An exception has been caught while processing the refactoring 'Rename Package'.

Reason: Problems encountered while moving resources.

Click 'Undo' to undo all successfully executed changes of the current refactoring. Click 'Abort' to abort the current refactoring.

处理重构“重命名包”时捕获到异常。

原因:移动资源时遇到问题。

单击“撤消”以撤消当前重构的所有成功执行的更改。单击“中止”以中止当前的重构。

What could possibly explain this sudden "change of heart" and how do I fix it?

什么可以解释这种突然的“改变主意”,我该如何解决?

enter image description here

在此处输入图片说明

采纳答案by Warlock

Seems from your snapshot that you are running windows 7, maybe vista. If its not a renaming issue, try running eclipse as administrator. It might be permissions-related, but its just a thought.

从您的快照看来,您正在运行 Windows 7,也许是 vista。如果不是重命名问题,请尝试以管理员身份运行 eclipse。它可能与权限有关,但这只是一个想法。

I see merit behind what Kurru is saying. Windows is not a case-sensitive operating system, meaning that is sees the words Cat and cat as the same thing. When you rename your package, Eclipse creates new directories/folder to put the package in. If you changed the case of your words and not actually rename it, it could throw this error.

我看到了库鲁所说的背后的价值。Windows 不是区分大小写的操作系统,这意味着将 Cat 和 cat 视为同一事物。当您重命名包时,Eclipse 会创建新的目录/文件夹来放置包。如果您更改了单词的大小写而不实际重命名它,则可能会引发此错误。

回答by Thorbj?rn Ravn Andersen

Under Windows this is frequently caused by a file or directory being locked. There can be several reasons for this:

在 Windows 下,这通常是由文件或目录被锁定引起的。这可能有几个原因:

  • A file is open in a viewing program outside of Eclipse. Windows will not allow the open file to be refactored.
  • A CMD.EXE is active in one of the directories to be refactored. Windows will not allow the directory to be moved or deleted.
  • A program is running with open files for items in the workspace. Windows will not allow the items to be refactored.
  • 文件在 Eclipse 之外的查看程序中打开。Windows 将不允许重构打开的文件。
  • CMD.EXE 在要重构的目录之一中处于活动状态。Windows 将不允许移动或删除目录。
  • 程序正在运行,其中包含工作区中项目的打开文件。Windows 将不允许重构这些项目。

If this is the behaviour of a freshly started Eclipse on a freshly started machine, it is probably not Windows, but a corrupted workspace or Eclipse distribution, and you should unpack a fresh Eclipse and create a new workspace in which you can import (and copy) the existing projects from the old workspace. I don't think this is the problem, though.

如果这是在新启动的机器上新启动的 Eclipse 的行为,它可能不是 Windows,而是损坏的工作区或 Eclipse 发行版,您应该解压新的 Eclipse 并创建一个新的工作区,您可以在其中导入(并复制)) 旧工作区中的现有项目。不过,我不认为这是问题所在。

回答by Kurru

If you're just trying to rename a package to the same name, only with a different case, this error is thrown for me. Very annoying when trying to fix package names to the lowercase convention.

如果您只是尝试将包重命名为同名,只是大小写不同,则会为我抛出此错误。尝试将包名称修复为小写约定时非常烦人。

Had some success renaming packages to a step folder, then to the target folder...

成功将包重命名为 step 文件夹,然后重命名为目标文件夹...

ie.

IE。

APackage -> apackage FAIL

APackage -> apackage FAIL

APackage -> APackage2 -> apackage SUCCESS

APackage -> APackage2 -> apackage成功

回答by WorkingMonk

Got the same error. It turns out that my ClearCase (version control) plugin was inactive. Simply activated the version control plugin, and the problem was solved.

得到了同样的错误。结果是我的 ClearCase(版本控制)插件处于非活动状态。只需激活版本控制插件,问题就解决了。

回答by Pubci

Same refactoring problem occurred to me when I was working in the Ubuntu. The cause is the permission limitations. Eclipse cannot re-factor as it does not have permission. After giving root permission, refactoring worked fine for me.

当我在 Ubuntu 中工作时,我也遇到了同样的重构问题。原因是权限限制。Eclipse 无法重构,因为它没有权限。授予 root 权限后,重构对我来说效果很好。

回答by OmiS

If it is the problem because of case. I have successfully tried a solution.

如果是因为大小写的问题。我已经成功尝试了一个解决方案。

  1. This will fail
  1. 这将失败

org.xyz.fileName ---rename---> org.xyz.filename

org.xyz.fileName ---重命名---> org.xyz.filename

  1. This will pass
  1. 这将通过

org.xyz.fileName ---rename---> org.abc (rename the structure)

org.xyz.fileName ---rename ---> org.abc(重命名结构)

org.abc ---rename---> org.xyz.filename This will work fine!

org.abc ---重命名---> org.xyz.filename 这会正常工作!

回答by Matt

This can be caused if using characters like underscores in your class names (e.g. My_Class.java). The project will build and run fine. But in Eclipse, if you run Android Tools > Rename Application Package, the rename will fail.

如果在类名(例如 My_Class.java)中使用下划线等字符,可能会导致这种情况。该项目将构建并运行良好。但是在 Eclipse 中,如果您运行 Android Tools > Rename Application Package,则重命名将失败。