Bookmark Topic Watch Topic
  • New Topic

Errors in code  RSS feed

 
Alice Hampton
Ranch Hand
Posts: 217
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Report post to moderator
Can someone tell me why if I stick a ';' after the bracket on line 43 it says that xmlwriter,myIDList,saxParser and defaultHandler are unused?
It also says that 'environment' on line 24 hasn't been initialized - I thought setting it up as private would fix that issue.
*Edit if I edit the private to private static it fixes it but I'm not sure whether I want/need to be doing that?
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Report post to moderator
Alice Hampton wrote:Can someone tell me why if I stick a ';' after the bracket on line 43 it says that xmlwriter,myIDList,saxParser and defaultHandler are unused?

Because they aren't - based on what you've posted (although it doesn't look complete to me). Those are local (ie, method) variables, and you don't have any code in the method (at least that we can see) that uses them.

It also says that 'environment' on line 24 hasn't been initialized...

Again, it hasn't. There's nothing in your DefaultHandler definition that initializes a variable called 'environment', so if you don't pass it to the startElement() method, the compiler has no idea what you're referring to. Don't forget that you're doing all this inside main(), which is a static method, so it can't "see" your 'environment' variable.

I thought setting it up as private would fix that issue.

Nope. Nothing to do with it - although it's probably a very good idea.

*Edit if I edit the private to private static it fixes it but I'm not sure whether I want/need to be doing that?

See my previous reply (2 up).

Winston
 
Alice Hampton
Ranch Hand
Posts: 217
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Report post to moderator
Im guessing my start,end and char should not be in main? Would you mind giving me an example of how it should look using the code I gave? Would something like this be better:

 
Mike. J. Thompson
Bartender
Posts: 689
17
  • Likes 1
  • Mark post as helpful
  • send pies
  • Report post to moderator
Perhaps you need to take a step back and stop writing code. What is it you're trying to achieve? The code you've posted has lots of things in it, but doesn't appear to have any functionality. You've declared a lot of things, created an anonymous class, and initialised some variables. What functionality do you want it to have though? I think the code is getting in your way in achieving that...

Im guessing my start,end and char should not be in main? Would you mind giving me an example of how it should look using the code I gave?


I'm assuming that when you say start, end and char you actually mean the methods startElement(...), endElement(...) and characters(...). These methods are members of the anonymous class you've declared (of type DefaultHandler). You haven't got @Override annotations on them, but I assume those methods are declared in the DefaultHandler interface or class?

I would expect you to pass that DefaultHandler to something that is doing the SAX parsing.

Some comments on the code you posted:

1) Why does XMLWriter extend DefaultHandler? You are creating an anonymous class that extends DefaultHandler elsewhere, so do you really need XMLWriter to extend it?

2) The method SaxParse should start with a lower case letter, otherwise it looks like a class name. The compiler doesn't care, but this is Java convention so people who are reading your code will be expecting it to be written as 'saxParse(...)'

3) As mentioned above, there is no actual functionality in what I can see. It's just a lot of variable declarations and an anonymous class definition.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Report post to moderator
This thread is now starting to head in the same direction as this thread.
I think we need to keep the discussion in one or the other.
 
Campbell Ritchie
Marshal
Posts: 56525
172
  • Mark post as helpful
  • send pies
  • Report post to moderator
Good idea, Joanne. Locking it.
 
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!