11

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.

1
  • Let me elaborate a bit: In android manifest we have this : <manifest xmlns:android="schemas.android.com/apk/res/android" package="com.mycompany.android.application" so the R class that contains all my references will be com.mycompany.android.application.R These are repeated throughout the application in activities. I cannot just create a baseactivity, because some classes also inherit from preferencesactivity and the likes. The thing i'm really looking for is an 'include file' that contains a single line with my .R import. Now i have to change that many times :( Commented Jun 24, 2011 at 9:06

8 Answers 8

12

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Also works to just add your package name at the top of the commented out class. A question you might ask yourself (me too yes) is why there is a commented out class just laying around ;)
3

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.

Comments

1

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.

Comments

0

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

5 Comments

Hi, thanks for the reply. Right clicking on the package itself does trigger a rename of that package. However, it's not those packages that i want to rename. The R - class in android is generated using the package name that is bound to the manifest. So all the com.mycompany.android.packagename.R imports fail to be renamed.
Just rename all your packages including the main package and clean your project, no need to do anything with the R class and its package.
Sorry, but you don't really understand what I mean i think. All the packages where my .java classes reside do not need to be renamed. In fact, they need to stay in the same package. What I do want, is deploy the same android code, to the android market as a different application. (with some different modules) Therefor i need to change the android manifest with a different package name. This results in another package name for the .R class and all import statements for the .R class are no longer valid and need to be changed manually in every activity/application/.. that uses it.
Well, in my mind the application package name indicated in the manifest should point to the main app package, it's not just an indication for the Market. So if you want to change the package in manifest, you must change it in project. Am I right?
Actually, they can be different and is not bad practice to do so. Consider a codebase that is 90% equal except some modules and themes that are customized for your clients. If you can just change the manifest package name (and not the actual packages), you can create hard references to your activities and applications. The only downside is, like i mentioned, that the .R class follows the package of the manifest package. The android market only checks for uniqueness on the android manifest package name and not on the class packages (where your java files are).
0

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.

1 Comment

Thanks, I thought about this too, but it's such a drag to maintain. Atm i'm just considering writing a small tool that does the .R replacements for me. But that is yet another thing to keep in mind when i'm switching versions..
0

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.

Comments

0

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!

1 Comment

Hey using your steps in my project not any type of error but my Application open at that time Unfortunately, myappname has stopped.
0

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.

1 Comment

actually, they all had a package name. I guess the above bug is fixed these days by updates to the platform.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.