Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

NullPointerException when using getElementsByTagName in plugin

843834May 28 2002 — edited Jun 5 2002
Hi,

i try to get all html-elements of a kind using getElementsByTagName().
previously i accessed the html-document using the DOMService-method which i get properly and can read e.g., its title. but when trying to get the length of the NodeList i get a NullPointerException although there should be at least 10 nodes in it.

can anyone point me the right direction?

thanks in advance,
dirk

the error message in the java-console:

java.lang.NullPointerException
at JSCom$SpanTagAccess.run(JSCom.java:46)
at sun.plugin.dom.DOMService.invokeAndWait(Unknown Source)
at JSCom.getTitle(JSCom.java:63)
at SmartBar.start(SmartBar.java:73)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

my source code:

import org.w3c.dom.*;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.Document;
import org.w3c.dom.css.*;
import org.w3c.dom.events.*;
import org.w3c.dom.html.*;
import org.w3c.dom.stylesheets.*;
import org.w3c.dom.views.*;
import com.sun.java.browser.dom.*;



public class JSCom {

SmartBar sb = null;
DOMService service = null;

public class SpanTagAccess implements DOMAction {
private NodeList spanTags = null;

public Object run(DOMAccessor accessor) {

HTMLDocument htmldoc = (HTMLDocument) accessor.getDocument( sb );
Document doc = (Document) htmldoc;
System.out.println(htmldoc.getTitle());

spanTags = (NodeList) doc.getElementsByTagName("span");

46: System.out.println(spanTags.getLength());



return null;
}
}

public void getTitle() {
String title = null;

SpanTagAccess sta = new SpanTagAccess();

try {
this.service = DOMService.getService( sb );

service.invokeAndWait(sta);

}
catch (DOMUnsupportedException e1) {
e1.printStackTrace();
}
catch (DOMAccessException e2) {
e2.printStackTrace();
}
}

/** Creates new JSCom */
public JSCom( SmartBar applet ) {
this.sb = applet;

}
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 3 2002
Added on May 28 2002
10 comments
1,391 views