Android-java vs PC-Java
This simple line of code gives the error "The method getTextContent() is undefined for the type Element":
String color_string = ( ( Element )( ( Element )inner_node ).getElementsByTagName( "color" ).item( 0 ) ).getTextContent();
I get the error in my Android-java version, but not in my PC-Java which I us开发者_JS百科e for testing and debugging Java code before I run it on the phone.
I have
import org.w3c.dom.Element;
on both versions. And I copied the code from the PC-Java to the Android-Java so I am 100% sure I have the same syntax on both.
The android reference says there is such a method defined for the Element
class. So perhaps you are missing some libraries, or have a wrong version.
@Aspen - the answer is that you are using the wrong libraries on your PC. You should be compiling your application against Android level 7 libraries, not against Sun Java libraries.
You should be able to correct this for test compiles by downloading the relevant Android JARs and putting them on your compilation bootclasspath. But I would NOT recommend trying to run code like this on a PC Java platform. (It might work, but you might also end up chasing lots of problems caused by doing this.)
EDIT
A better idea might be to use Eclipse with the ADT plugin, as described on this page.
after checking a lot and scratching my head thousands of times I came up with simple alteration that it needs to change your API level to 8
Android Java is not Sun Java. Androids Java based on Apaches Harmony project (Re-Implementation of Sun Java under an open license). Some details can be different.
Wiki has a list of the java packages and their origins.
精彩评论