重命名Android包名称失败

发布于 2024-11-16 21:02:33 字数 5179 浏览 0 评论 0原文

我在 eclipse、android 工具、“重命名应用程序包”中右键单击我的项目。

选择任何名称都会失败,并引导您查看错误日志以获取详细信息。

在那里我发现以下内容:

eclipse.buildId=M20110210-1200
java.version=1.6.0_26
java.vendor=Sun Microsystems Inc.
BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=nl_BE
Framework arguments:  -product org.eclipse.epp.package.java.product
Command-line arguments:  -os win32 -ws win32 -arch x86_64 -product org.eclipse.epp.package.java.product

错误 2011 年欧洲夏令时间 6 月 24 日星期五 10:11:31 内部错误

java.lang.reflect.InvocationTargetException
at org.eclipse.ltk.internal.ui.refactoring.WorkbenchRunnableAdapter.run(WorkbenchRunnableAdapter.java:91)
at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)
Caused by: org.eclipse.core.internal.resources.ResourceException: An error occurred while traversing resources.
at org.eclipse.core.internal.resources.Resource.accept(Resource.java:83)
at org.eclipse.core.internal.resources.Resource.accept(Resource.java:110)
at org.eclipse.core.internal.resources.Resource.accept(Resource.java:94)
at com.android.ide.eclipse.adt.internal.refactorings.renamepackage.ApplicationPackageNameRefactoring.createChange(ApplicationPackageNameRefactoring.java:128)
at org.eclipse.ltk.core.refactoring.CreateChangeOperation.run(CreateChangeOperation.java:124)
at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1975)
at org.eclipse.ltk.internal.ui.refactoring.WorkbenchRunnableAdapter.run(WorkbenchRunnableAdapter.java:87)
... 1 more
Caused by: java.lang.NullPointerException
at com.android.ide.eclipse.adt.internal.refactorings.renamepackage.ApplicationPackageNameRefactoring.updateJavaFileImports(ApplicationPackageNameRefactoring.java:151)
at com.android.ide.eclipse.adt.internal.refactorings.renamepackage.ApplicationPackageNameRefactoring$JavaFileVisitor.visit(ApplicationPackageNameRefactoring.java:427)
at org.eclipse.core.internal.resources.Resource$2.visit(Resource.java:112)
at org.eclipse.core.internal.resources.Resource$1.visitElement(Resource.java:64)
at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:82)
at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:86)
at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:86)
at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:86)
at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:86)
at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:86)
at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:86)
at org.eclipse.core.internal.watson.ElementTreeIterator.iterate(ElementTreeIterator.java:127)
at org.eclipse.core.internal.resources.Resource.accept(Resource.java:74)
... 7 more
Root exception:
org.eclipse.core.internal.resources.ResourceException(/Touring Mobilis)[566]: java.lang.NullPointerException
at com.android.ide.eclipse.adt.internal.refactorings.renamepackage.ApplicationPackageNameRefactoring.updateJavaFileImports(ApplicationPackageNameRefactoring.java:151)
at com.android.ide.eclipse.adt.internal.refactorings.renamepackage.ApplicationPackageNameRefactoring$JavaFileVisitor.visit(ApplicationPackageNameRefactoring.java:427)
at org.eclipse.core.internal.resources.Resource$2.visit(Resource.java:112)
at org.eclipse.core.internal.resources.Resource$1.visitElement(Resource.java:64)
at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:82)
at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:86)
at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:86)
at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:86)
at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:86)
at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:86)
at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:86)
at org.eclipse.core.internal.watson.ElementTreeIterator.iterate(ElementTreeIterator.java:127)
at org.eclipse.core.internal.resources.Resource.accept(Resource.java:74)
at org.eclipse.core.internal.resources.Resource.accept(Resource.java:110)
at org.eclipse.core.internal.resources.Resource.accept(Resource.java:94)
at com.android.ide.eclipse.adt.internal.refactorings.renamepackage.ApplicationPackageNameRefactoring.createChange(ApplicationPackageNameRefactoring.java:128)
at org.eclipse.ltk.core.refactoring.CreateChangeOperation.run(CreateChangeOperation.java:124)
at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1975)
at org.eclipse.ltk.internal.ui.refactoring.WorkbenchRunnableAdapter.run(WorkbenchRunnableAdapter.java:87)
at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)

这个工具对任何人都有效吗?如果是这样,请告诉我您使用的 eclipse 版本。

我在 Windows 7 上使用最新版本的 eclipse(64 位)以及最新的 ADT eclipse 插件。

I right click on my project in eclipse, android tools , 'Rename application package'.

Pick any name and it will fail, directing you to the error log for details.

There i find the following:

eclipse.buildId=M20110210-1200
java.version=1.6.0_26
java.vendor=Sun Microsystems Inc.
BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=nl_BE
Framework arguments:  -product org.eclipse.epp.package.java.product
Command-line arguments:  -os win32 -ws win32 -arch x86_64 -product org.eclipse.epp.package.java.product

Error
Fri Jun 24 10:11:31 CEST 2011
Internal Error

java.lang.reflect.InvocationTargetException
at org.eclipse.ltk.internal.ui.refactoring.WorkbenchRunnableAdapter.run(WorkbenchRunnableAdapter.java:91)
at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)
Caused by: org.eclipse.core.internal.resources.ResourceException: An error occurred while traversing resources.
at org.eclipse.core.internal.resources.Resource.accept(Resource.java:83)
at org.eclipse.core.internal.resources.Resource.accept(Resource.java:110)
at org.eclipse.core.internal.resources.Resource.accept(Resource.java:94)
at com.android.ide.eclipse.adt.internal.refactorings.renamepackage.ApplicationPackageNameRefactoring.createChange(ApplicationPackageNameRefactoring.java:128)
at org.eclipse.ltk.core.refactoring.CreateChangeOperation.run(CreateChangeOperation.java:124)
at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1975)
at org.eclipse.ltk.internal.ui.refactoring.WorkbenchRunnableAdapter.run(WorkbenchRunnableAdapter.java:87)
... 1 more
Caused by: java.lang.NullPointerException
at com.android.ide.eclipse.adt.internal.refactorings.renamepackage.ApplicationPackageNameRefactoring.updateJavaFileImports(ApplicationPackageNameRefactoring.java:151)
at com.android.ide.eclipse.adt.internal.refactorings.renamepackage.ApplicationPackageNameRefactoring$JavaFileVisitor.visit(ApplicationPackageNameRefactoring.java:427)
at org.eclipse.core.internal.resources.Resource$2.visit(Resource.java:112)
at org.eclipse.core.internal.resources.Resource$1.visitElement(Resource.java:64)
at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:82)
at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:86)
at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:86)
at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:86)
at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:86)
at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:86)
at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:86)
at org.eclipse.core.internal.watson.ElementTreeIterator.iterate(ElementTreeIterator.java:127)
at org.eclipse.core.internal.resources.Resource.accept(Resource.java:74)
... 7 more
Root exception:
org.eclipse.core.internal.resources.ResourceException(/Touring Mobilis)[566]: java.lang.NullPointerException
at com.android.ide.eclipse.adt.internal.refactorings.renamepackage.ApplicationPackageNameRefactoring.updateJavaFileImports(ApplicationPackageNameRefactoring.java:151)
at com.android.ide.eclipse.adt.internal.refactorings.renamepackage.ApplicationPackageNameRefactoring$JavaFileVisitor.visit(ApplicationPackageNameRefactoring.java:427)
at org.eclipse.core.internal.resources.Resource$2.visit(Resource.java:112)
at org.eclipse.core.internal.resources.Resource$1.visitElement(Resource.java:64)
at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:82)
at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:86)
at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:86)
at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:86)
at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:86)
at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:86)
at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:86)
at org.eclipse.core.internal.watson.ElementTreeIterator.iterate(ElementTreeIterator.java:127)
at org.eclipse.core.internal.resources.Resource.accept(Resource.java:74)
at org.eclipse.core.internal.resources.Resource.accept(Resource.java:110)
at org.eclipse.core.internal.resources.Resource.accept(Resource.java:94)
at com.android.ide.eclipse.adt.internal.refactorings.renamepackage.ApplicationPackageNameRefactoring.createChange(ApplicationPackageNameRefactoring.java:128)
at org.eclipse.ltk.core.refactoring.CreateChangeOperation.run(CreateChangeOperation.java:124)
at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1975)
at org.eclipse.ltk.internal.ui.refactoring.WorkbenchRunnableAdapter.run(WorkbenchRunnableAdapter.java:87)
at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)

Does this tool work for anyone? If so, please let me know what version of eclipse you are using.

I'm using the latest versions of eclipse (64bit) on windows 7 with the latest ADT eclipse plugin.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

临风闻羌笛 2024-11-23 21:02:34

我对“遍历资源”有同样的错误。我删除了引用的文件夹(它未使用),之后我能够重构包名称。

I had the same error about "traversing resources." I deleted the referenced folder (it was unused) and I was able to refactor the package name after that.

猫性小仙女 2024-11-23 21:02:34

显然以下方法可以帮助您重命名。

1.右键单击gen文件夹并将包名称重命名为您想要的名称。见下图。

在此处输入图像描述

2.重命名上述内容后,打开清单文件并将包声明更改为您想要的内容但它应该与 gen 文件夹中的包相同,如下所示。

在此处输入图像描述

应该就是这样了,各位。编码愉快!

Apparently the following way can help you rename.

1.Right Click the gen folder and rename the package name to what you want it to be.see the image below.

enter image description here

2.After renaming the above open your manifest file and change the package declaration to what you want it to be but it should be the same as the package in the gen folder see below.

enter image description here

That should be it folks.Happy coding!

柠北森屋 2024-11-23 21:02:34

哈哈
该错误的原因如下:

Caused by: java.lang.NullPointerException
at com.android.ide.eclipse.adt.internal.refactorings.renamepackage.ApplicationPackageNameRefactoring.updateJavaFileImports(ApplicationPackageNameRefactoring.java:151).

因此,您需要检查您的 java 文件之一是否没有包名称。

例如:

//package com.telecom.request.login;
//
//import android.content.Context;
//import android.content.Intent;

我的java文件的包被注释了,然后eclipse无法获取文件的包名,出现nullpointer。

希望对您有帮助。

haha
The reason of this bug is as follows:

Caused by: java.lang.NullPointerException
at com.android.ide.eclipse.adt.internal.refactorings.renamepackage.ApplicationPackageNameRefactoring.updateJavaFileImports(ApplicationPackageNameRefactoring.java:151).

So,you need to check if one of your java files doesn't have a package name.

For example:

//package com.telecom.request.login;
//
//import android.content.Context;
//import android.content.Intent;

The package of my java file has been commented,then eclipse can't get the file's package name,nullpointer comes out.

Hope helpful for you.

笔芯 2024-11-23 21:02:33

你无法相信这一点。我有完全相同的问题,是因为我完全评论了一门课。所以我认为当 Eclipse 尝试更改注释类的包名称时,它会抛出此错误。

要解决该问题,您只需删除该类或取消注释即可。

You can not belive this. I have exactly the same problem and is because I comment a class entirely. So I think that when eclipse try to change the package name of a commented class it throw this error.

To solve the problem you only has to delete the class or uncomment it.

回眸一笑 2024-11-23 21:02:33

我面临着同样的问题。我只是无法使用 package > 重命名该包右键单击>重命名包。似乎某些 xml 模板中使用自定义控件的包引用未更新,因此无法生成 R 文件。查看 xml 并重命名引用后,生成了 R 文件,我可以继续重命名。

I was facing the same problem. I just was was not able to rename the package using package > right click > rename package. It appeared the package references in some xml templates, using custom controls were not updated, so the R file could not be generated. After looking at the xml and renaming the references, the R file was generated and I could continue renaming.

薄荷港 2024-11-23 21:02:33

实际上我决定创建自己的包重命名工具。

实际上非常简单:

  • 将 AndroidManifest.xml 替换为 [packagename]。
  • 替换所有 *.java 文件中的 [packagename].R
  • 替换 xml 文件中的 SCHEMAS:http://schemas.android.com/apk/res/[packagename]

然后我选择“不更新启动配置”并刷新 eclipse 项目。

那么一切都会顺利:)。

与 git 分支和天线预处理器相结合,可以帮助我获得使用各种选项执行应用程序的多个版本所需的灵活性。

Actually I decided to create my own package rename tool.

It's very simple in fact:

  • Replace the AndroidManifest.xml with the [packagename].
  • Replace [packagename].R in all *.java files
  • Replace SCHEMAS in xml files: http://schemas.android.com/apk/res/[packagename]

I then choose to 'not update launch configurations' and refresh eclipse project.

All goes well then :).

That combined with git branches and the antenna preprocessor helps me to get the flexibility I need to perform many versions of an application with various options.

日裸衫吸 2024-11-23 21:02:33

尝试右键单击该包并选择“重构”->“重命名”,它对我来说效果很好,从未遇到过任何麻烦。希望这有帮助。

Try right-clicking on the package and choose Refactor->Rename, it works fine for me, never had any troubles. Hope this helps.

不打扰别人 2024-11-23 21:02:33

我在使用某些版本的 Eclipse 重构/重命名项目时遇到了类似的问题。如果您需要快速修复,我建议这样做。

使用您想要营销的名称创建一个新的 Android 应用程序,并将源代码文件逐个复制到您的新应用程序中。 警告:不要复制文件本身,只复制文件中的代码,因为 Eclipse 有一些与每个文件关联的元数据,这可能会导致链接错误。

希望这有帮助。

I have had similar problems while refactoring / renaming projects with some versions of eclipse. If you need a quick fix, I'd suggest this.

Create a new android application with the name you want to market it as and copy the source code file by file into your new application. Warning: Do not copy the files themselves, just the code in the files, as eclipse has some meta data associated with each file and this could possibly cause linking errors.

Hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文