Thursday, April 26, 2012

getElementsByTagName returns null in Android 4.0 or 3.0

Today, my application crashed on Android 4 device. I always thought it will work on Android 4 because it was a simple application but I guessed wrong.

For some reason  getElementsByTagName  returns null in Android 4.0 or Android 3.0, if your  code look somewhat like this.


 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
 DocumentBuilder builder = factory.newDocumentBuilder();
 InputSource is = new InputSource(new StringReader("Some XML here and there"));
 Document document = builder.parse(is);
 Element root = document.getDocumentElement();
 root.normalize();
           
 NodeList items = root.getElementsByTagName("tag");  <-- this function will always return null on Android 4 


When i dig in I found a bug reported in Google forums. I found this very hard to believe because this is a very primary level issue and how did it get passed?

Anyway, As a work around I had to use XPath. Just remember to change the project's Android SDK to 2.2 or higher otherwise XPath classes are not visible. They resides in javax.xml.xpath namespace. Or you can use XmlPullParser which reads documents from top to bottom.


InputSource is = new InputSource(new StringReader("Some XML here and there"));
XPathFactory factory = XPathFactory.newInstance();
XPath xPath = factory.newXPath();
NodeList nodeList = (NodeList) xPath.evaluate("/xpath", is, XPathConstants.NODESET);




Sunday, March 11, 2012

Android requires compiler compliance level 5.0. Please fix project properties

Today, I moved a different work space from my old work space, but I imported some of the projects from my previous project and I started to get this error out of no where. I figure out it's something to do with the Eclipse compiler issue. To fix this you need to change globe flag which is located here

Window - > Preferences -> Java -> Compiler - > Change JDK compiler complience level to 1.5 or greater. (I use 1.6)

Tuesday, February 7, 2012

Wi-Fi Keep Alive / On for Kindle Fire

I have uploaded my first app to Amazon App Store, Check it out here

Wi-Fi Keep Alive


It is a simple for kindle fire to keep the wi-fi connection always on even the device screen goes off. This might use some extra battery power to keep the Wi Fi up but it wont disconnect your streaming music :)

Tuesday, January 31, 2012

debug.keystore keystore password ?

Today when i wanted to play with Google Maps, i had to generate a new Certificate fingerprint to include Maps. To generate a new Certificate fingerprint you need to use the keytool that comes with the SDK,

so i executed this line in the CMD,

keytool -list -keystore .android/debug.keystore

but it's asking for a password, duh! after few seacrches on google, I found out, it's android, type android and you shall passed

Thursday, December 29, 2011

How to add icons to Preference example in Android

If you are having a pain in the ass getting this to work. Download the example from here

http://www.ziddu.com/download/17996784/preference_icon_example.zip.html

Wednesday, December 7, 2011

StackOverflow error in Eclipse ?

Today, friend of mine Kitaro Nu shared this information with me.

This error is likely to happen if you have two library projects and they both refer each other.

· Project A import project B and Project B import Project A .

Thursday, December 1, 2011

Unable to create editor ID org.eclipse.jdt.ui.PropertiesFileEditor: Editor could not be initialized. Java heap space

Today, after I took the latest version of a component and try to rebuild the work space i started to getting this error.

To solve this,
1. Had to close eclipse and restart
2. Run eclipse with clean command
\eclipse\eclipse.exe -clean
3. delete

workspace\.metadata\.plugins\org.eclipse.jdt.core
workspace\metadata\.plugins\org.eclipse.core.resources\.history

worked for me!