Thursday, 9 June 2011

Running Android SDK in Eclipse - Errors

In this post I am going to summarize all the errors that I found in the Android SDK installed in Eclipse. Some of them could have solutions

1. LogCat with phantom logs
Sometimes the logcat cannot show correctly the logs. They appears but before you can read them, they disappears.
This could be that there are too many log.
Solution: Clear the previous logs
You can use the button "Clear log" appears on the upper-right corner of Logcat windows.

2. Debug certificate expired
Error generating final archive: Debug certificate expired
There is a certificate for create applications for Android. It contains the private key held by the application's developer and it is automatically created when the programmer creates an android application. This certificate expires in 365 days. Once it is expires, to continue generate programs, the programmers should remove it and new certificate will be created.

1. Remove the old certificate
To remove it, first the place of where it is should be known:
1.1 Go to preferences.
Windows: Window -> preference
Mac os X: Eclipse -> preference
1.2. Check the certificate directory Android -> build -> Default debug keystore.
1.3. Go to the directory indicated in the previous step and remove the keystore.
2. Clear the project
2.1 Go to Project -> Clean...
2.2 Select any project and click on Ok

The eclipse will generate new certificate. (If it is not generated instantly, wait few seconds.)

For more information:
Android official dev guide: http://developer.android.com/guide/publishing/app-signing.html

3.  XML file error parsing
If you have modified the any XML in Android by hand and your are unable to launch correctly the application, you might check the main project folder. There could be some problem with the XML file while the compiler is parsing it. You will notice it if after you refresh the directory, you see a strange FileName.out.xml file.

This could be the error message:

FATAL EXCEPTION: main
 java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.jiahaoliuliu.android/com.jiahaoliuliu.android.SampleClass}: java.lang.ClassNotFoundException: com.jiahaoliuliu.android.SampleClass in loader dalvik.system.PathClassLoader[/data/app/com.jiahaoliuliu.android.SampleProject-1.apk]
  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1573)
  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
  at android.os.Handler.dispatchMessage(Handler.java:99)
  at android.os.Looper.loop(Looper.java:123)
  at android.app.ActivityThread.main(ActivityThread.java:3691)
  at java.lang.reflect.Method.invokeNative(Native Method)
  at java.lang.reflect.Method.invoke(Method.java:507)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:847)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
  at dalvik.system.NativeStart.main(Native Method)
 Caused by: java.lang.ClassNotFoundException: com.jiahaoliuliu.android.SampleClass in loader dalvik.system.PathClassLoader[/data/app/com.jiahaoliuliu.android.SampleProject-1.apk]
  at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
  at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1565)
  ... 11 more

This could be the solution:
1. Delete the extra file (FileName.out.xml) file generated.
2. Close all the files in the Eclipse
3. Press on Project -> Clean and clean the project
4. Open any java class file
5. Click on the file opened so the eclipse will focus to the file
6. Click on "Run" again

It worked on eclipse Indigo.
Source:
http://code.google.com/p/android/issues/detail?id=3767

4. Error parsing the SDK content - Java.lang.NullPointerException
After updating the last version of Android SDK Tools (19), I found a strange error:

Parsing Data for android-7 failed java.lang.NullPointerException
Parsing Data for android-8 failed java.lang.NullPointerException
Parsing Data for android-10 failed java.lang.NullPointerException
Parsing Data for android-14 failed java.lang.NullPointerException



This could be due some error with the new SDK. I hope that Google know this bug and while they are trying to solve it, in order to still working on android, you can do the follow:

1. Copy the old eclipse configuration
1.1 Close eclipse
1.1 Go to the main work directory of eclipse
1.2 Rename the directory .metadata to .oldMetadata

2. Generate new eclipse configuration
2.1 Open the eclipse
2.2 Once eclipse is loaded, it will show the normal Java interface. You will see the Android AVD but you won't be able to create and run any Android project.
2.3 Close eclipse

3. Copy the old Android plugin
3.1 Go to the main work directory of eclipse
3.2 Localize the folder com.android.ide.eclipse.adt It should be in .oldMetadata/.plugins/
3.3 Copy it to the new eclipse configuration: .metadata/plugins/

4. Test the result
4.1 Open eclipse
4.2 Click on File -> New. You should be able to see the "Android project" option.
4.3 Try to create a empty project and run it.

1 comment:

  1. Thanks a lot. It worked just like you indicated.

    ReplyDelete