Saturday, December 31, 2011

Android - Test App : Issues I faced and Solution


It was the first time I an trying with Android ... You might as well face the similar issues for the first time try.

1) Android emulator-arm.exe crashing in Windows XP - Space in SDK HOME
2) Can't see the App even after it got started as per console logs - Unlock
There seems to be 2-3 reasons behind the issues I faced.
1) The SDK directory should not have space in path (folder name). I had installed in 'Program FIles'. Also its better to have all sub directories in the SDK path to be <8 characters.
I used a small, no space directory for installing SDK.  The error gone.

2) I was not patient enough to avoid clicking the screen till the app loads completely it seems.

3) I have to unlock the AVD screen to see the app.. I didn't notice that.. :P 

Sunday, December 18, 2011

Log4j - Child Logs are written in to Parent Log file (for imported child apps)



Log4j Appender: Child Logs are written in to Parent Log file.

<Just scribbling the factors> ...will be edited later.</>
I created one app (say it as a Job) – a stand alone java with logging features through Log4j. I had my own log4j.proeprties with file Appender and my own log file specified.

This job is extracted as Jar and shared with another app (say it as a scheduler). The scheduler loads this Jar (along with many other jars for different Jobs) dynamically through Class Loader.

It also used log4j for logging purpose.

What happened: The logs by the child apps (jobs) where getting written in to the parent (Scheduler) messed up with parent log statements in the parent log file. The child log file was not having any logs written.

This is a known feature as long as the Classloader loads the child apps to one app.

If you need separate logs, the parent log4j.properties has to define another rootLoagger and that logger has to be used in the child logging purpose.. meaning it has got little dependency or coupling b/w parent and child.



JUnit: Testcase: initializationError : java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing

When: Tried to run a JUnit TestCase, I got below error.
Error: JUnit Error.NoClassDefFoundError: org/hamcrest/SelfDescribing
Scenario: I was using Junit.jar 4.0 version
Solution: Use the latest JUnit jar – 4.10.
Reason: Some posts says it as due to the log4j version mismatch b/w what is there in junit jar and the one in Ant jar.
Testcase: initializationError took 0 sec 
Caused an ERROR 
org/hamcrest/
SelfDescribing 
java.lang.
NoClassDefFoundError: org/hamcrest/SelfDescribing 
    at java.lang.
ClassLoader.defineClass1(Native Method) 
    at java.lang.
ClassLoader.defineClass(Unknown Source) 
    at java.security.
SecureClassLoader.defineClass(Unknown Source) 
    at java.net.
URLClassLoader.defineClass(Unknown Source) 
    at java.net.
URLClassLoader.access$000(Unknown Source) 
    at java.net.
URLClassLoader$1.run(Unknown Source) 
    at java.security.
AccessController.doPrivileged(Native Method) 
    at java.net.
URLClassLoader.findClass(Unknown Source) 
    at java.lang.
ClassLoader.loadClass(Unknown Source)