简体   繁体   中英

Rename Android Package name fails

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.

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.

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.

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.

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.

在此输入图像描述

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.

在此输入图像描述

That should be it folks.Happy coding!

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.

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

I have had similar problems while refactoring / renaming projects with some versions of eclipse. If you need a , 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. 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. 不要复制文件本身,只复制文件中的代码,因为eclipse有一些与每个文件关联的元数据,这可能会导致链接错误。

Hope this helps.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM