Help with Java code...spot the error...STUCK!! :(

suryad

Veteran
Code:
/*
 * XMLValidator.java
 *
 * Created on April 21, 2005, 7:42 PM
 *
 */

package xmlvalidator;

import java.io.File;

/**
 *
 * @author Surya
 */
public class XMLValidator
{
    
    private File xml;
    private File xsd;
    
    /**
     * Creates a new instance of XMLValidator 
     */
    public XMLValidator(File xml, File xsd)
    {
        this.xml = xml;
        this.xsd = xsd;
        java.awt.EventQueue.invokeLater(new Runnable()
        {
            public void run()
            {
                new ValidateGUI(this).setVisible(true);
            }
        });
    }
    
    // Returns the xml file
    public File getXmlFile()
    {
        return xml;
    }

    //Returns the xsd file 
    public File getXsdFile()
    {
        return xsd;
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args)
    {
        if (args.length != 2)
            System.out.println("Usage 'java XMLValidate filename.xml filename.xsd");
        else
        {
            File file1 = new File(args[0]);
            File file2 = new File(args[1]);
            
            if (file1.exists() && file2.exists())
               XMLValidator xmlv = new XMLValidator(file1, file2);
            else
                System.out.println("One or more of the filenames mentioned does not exist.");
        }
    }
}

Using Netbeans 4.1 RC to code. Error is at the line:
Code:
XMLValidator xmlv = new XMLValidator(file1, file2);

I dont understand the error. The error states that line 63 not a statement. Another error is line 63 ';' expected. This lead me to believe that there was a syntactical error somewhere but I have gone over my code so many times. I dont get it. Please let me know if you need additional info on the code. Hope you guys can help. Driving me crazy for a while :devilish: thanks in advance.[/code]
 
Just a little suggestion, scrap Netbeans for now.

When I'm in the middle of typing something Netbeans has a habbit of automatically highlighting it as an error, that's not an issue.

However, when I've finished typing up what I need to, Netbeans either requires you to save your work or restart the IDE entirely for it to recognise the line of code as valid.

Eclipse doesn't have this problem.

I also fixed your problem:
Code:
new XMLValidator(file1, file2);
 
K.I.L.E.R. I apprecitate your help and suggestion. I am just used to Netbeans and they have improved a lot from before. I usually use JEdit and just do my work there but I used Netbeans a month ago for my last class before graduation and it worked great for me.

Yeah I know the highlighting thing you are talking about. It does get annoying there is no doubt about it but I never had the problem you are talking about. 4.1 is really nice. Eclipse is a great platform no doubt but for some reason so far I have found it very easy to learn Netbeans so far. Also I dont know where to get all sorts of plugins and addons...since I am new to the IDE world. Thanks for your advice. I will dload a copy of Eclipse and give it a shot.

Now...not to sound stupid or anything but could you specify...what you did? Err I dont understand how you fixed the bug or what the bug was. I am either really stupid or just really frustrated right now...I dont get it. Could you kindly elaborate what the difference between your line of code and my line 63 was? Thanks in advance. Much appreciated.
 
Sorry for the double post but I understand the change now. But could you please kindly explain why it works that XMLValidator xmlv = new XMLValidator(arg1, arg2) wont work but new XMLValidator(arg1,arg2) does. Thank you very very much.
 
You create an instance outside of a conditional statement, not inside but you can assign an instance inside a conditional check.

The reason my change works is because all it does is execute an instance.
 
Gotcha. Thanks once again K.I.L.E.R. and as it so turned out I dumped that code haha and wrote a standalone gui instead. So far it is almost working...I can read files and display them in my gui.
 
Back
Top