Results 1 to 14 of 14
  1. #1
    kathir0301 is offline Member
    Join Date
    Nov 2010
    Posts
    11
    Rep Power
    0

    Default Help me To Avoid the Exception...

    Hi
    Following is code and got the folloing exception.Im getting the expected output, but i dont know why im getting this exception .



    class values
    {
    public static void main(String[] args)throws Exception {
    compare ob=new comapre();
    ob. findPosistion(String inpuFile1,String inpuFile2);
    }


    class compare
    {
    FileInputStream fin =null;
    GZIPInputStream gzis=null;
    InputStreamReader isr=null;
    BufferedReader br=null
    public void findPosistion(String inpuFile1,String inpuFile2) throws Exception
    {



    fin = new FileInputStream(inpuFile1);
    gzis = new GZIPInputStream(fin);
    isr = new InputStreamReader(gzis);
    br = new BufferedReader(isr);


    while ((strLine = br.readLine()) != null){
    buffer1.append(strLine);
    posistion=i;
    findField( posistion);

    }
    public void findField(posistion ) throws Exception
    {
    String xmlFile="compare.xml";
    DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBu ilder();
    Document document = builder.parse(new File(xmlFile));
    XPath xpath = XPathFactory.newInstance().newXPath();
    String expression="//Record [@id="+"'"+type+"']/Sequence";
    Node nodes = (Node) xpath.evaluate(expression, document, XPathConstants.NODE);
    }

    }

    Exception is

    at com.nielsen.mit.testSuite.FileCompare.findField(Fi leCompare.java:153)
    at com.nielsen.mit.testSuite.FileCompare.findPosistio n(FileCompare.java:94)
    at com.nielsen.mit.testSuite.FileCompareTest.testFile Compare(FileCompareTest.java:12)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknow n Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Un known Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.junit.runners.model.FrameworkMethod$1.runRefle ctiveCall(FrameworkMethod.java:44)
    at org.junit.internal.runners.model.ReflectiveCallabl e.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExpl osively(FrameworkMethod.java:41)
    at org.junit.internal.runners.statements.InvokeMethod .evaluate(InvokeMethod.java:20)
    at org.junit.internal.runners.statements.RunBefores.e valuate(RunBefores.java:28)
    at org.junit.internal.runners.statements.RunAfters.ev aluate(RunAfters.java:31)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild( BlockJUnit4ClassRunner.java:73)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild( BlockJUnit4ClassRunner.java:46)
    at org.junit.runners.ParentRunner.runChildren(ParentR unner.java:180)
    at org.junit.runners.ParentRunner.access$000(ParentRu nner.java:41)
    at org.junit.runners.ParentRunner$1.evaluate(ParentRu nner.java:173)
    at org.junit.internal.runners.statements.RunBefores.e valuate(RunBefores.java:28)
    at org.junit.internal.runners.statements.RunAfters.ev aluate(RunAfters.java:31)
    at org.junit.runners.ParentRunner.run(ParentRunner.ja va:220)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestR eference.run(JUnit4TestReference.java:46)
    at org.eclipse.jdt.internal.junit.runner.TestExecutio n.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.main(RemoteTestRunner.java:197)


    please help me to overcome this exception..and please tell me why im getting this excption .Thanks in advance

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,006
    Rep Power
    20

    Default

    There should be some text before that stack trace that actually says what the exception is.

    And can you point out the actual line it is thrown from (line 153 presumably)?

  3. #3
    makpandian's Avatar
    makpandian is offline Senior Member
    Join Date
    Dec 2008
    Location
    Chennai
    Posts
    448
    Rep Power
    6

    Default

    You better post your full class code.
    Mak
    (Living @ Virtual World)

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,006
    Rep Power
    20

    Default

    The exception would be more useful at the moment I'd say.

  5. #5
    SmilingKey is offline Member
    Join Date
    Dec 2010
    Posts
    19
    Rep Power
    0

    Default

    I think code shown has some basic errors:

    1. posistion=i;
    you have to specify posistion class in this assignment: int posistion = i; ? String posistion = i? I don't know.

    2. public void findField(posistion ) throws Exception
    you have to specify posistion class again: public void findField(String posistion ) throws Exception
    Also, your findField has an input called posistion you don't use.
    Last edited by SmilingKey; 12-07-2010 at 01:01 PM.

  6. #6
    kathir0301 is offline Member
    Join Date
    Nov 2010
    Posts
    11
    Rep Power
    0

    Default

    Hi
    I made all the changes as said by SmilingKey and variable posistion is of type int .but while debugging im not able to load XML file. Im getting exception in the following statement
    DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBu ilder();
    Document document = builder.parse(new File(xmlFile));

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,006
    Rep Power
    20

    Default

    What exception!

  8. #8
    kathir0301 is offline Member
    Join Date
    Nov 2010
    Posts
    11
    Rep Power
    0

    Default

    The exception i got is

    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknow n Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Un known Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.junit.runners.model.FrameworkMethod$1.runRefle ctiveCall(FrameworkMethod.java:44)
    at org.junit.internal.runners.model.ReflectiveCallabl e.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExpl osively(FrameworkMethod.java:41)
    at org.junit.internal.runners.statements.InvokeMethod .evaluate(InvokeMethod.java:20)
    at org.junit.internal.runners.statements.RunBefores.e valuate(RunBefores.java:28)
    at org.junit.internal.runners.statements.RunAfters.ev aluate(RunAfters.java:31)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild( BlockJUnit4ClassRunner.java:73)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild( BlockJUnit4ClassRunner.java:46)
    at org.junit.runners.ParentRunner.runChildren(ParentR unner.java:180)
    at org.junit.runners.ParentRunner.access$000(ParentRu nner.java:41)
    at org.junit.runners.ParentRunner$1.evaluate(ParentRu nner.java:173)
    at org.junit.internal.runners.statements.RunBefores.e valuate(RunBefores.java:28)
    at org.junit.internal.runners.statements.RunAfters.ev aluate(RunAfters.java:31)

  9. #9
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,006
    Rep Power
    20

    Default

    That's not an exception.
    That's a stack trace (as I said earlier).

    This is an exception (with stack trace):
    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 5
    at Scratch.main(Scratch.java:55)

    That first bit tells us what is actually going wrong. Without it we are guessing.

  10. #10
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,519
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Tolls calmly wrote View Post
    There should be some text before that stack trace that actually says what the exception is.
    Quote Originally Posted by Being totally ignored Tolls wrote View Post
    The exception would be more useful at the moment I'd say.
    Quote Originally Posted by Finally Tolls desparately shouted View Post
    What exception!
    If I'm not mistaken you seem to be curious to know what Exception was actually thrown. Why don't just just ask?

    kind regards,

    Jos ;-)
    cenosillicaphobia: the fear for an empty beer glass

  11. #11
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,006
    Rep Power
    20

    Default

    You know me, I like to be cryptic.

  12. #12
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,519
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Tolls View Post
    You know me, I like to be cryptic.
    Ah, you even fooled me for a second old chap; I thought that you wanted to know what Exception was thrown but obviously you couldn't care less. Good joke, good joke ...

    Obviously the OP doesn't know or care either; most of those whippersnappers can't read; when an exception is thrown they don't read the stack trace or anything; they see something like this:

    Java Code:
    goobledygook: fnart()
      at: ssdgsdgs your code is correct sDgfsdfsdfsd: 153
      at: gfdgsdf there's a bug in java sdfsdffsd: 965
      at: sdsdfsdf buy a faster harddisk fadsdfsd: 23
      at: sdfsdfdffs reinstall everything dssfdfs: 5443
      at: sdsd post on the forums fsdgghd: 336
    kind regards,

    Jos ;-)
    cenosillicaphobia: the fear for an empty beer glass

  13. #13
    kathir0301 is offline Member
    Join Date
    Nov 2010
    Posts
    11
    Rep Power
    0

    Default

    HI
    i got several questions based on the reply i got
    1.Are u saying my code is correct?
    2.When i opened in debug perspective, i got filenotfoundException when i load file ie DocumentBuilder builder = DocumentBuilderFactory.newInstance ().newDocumentBuilder();
    Document document = builder.parse(new File(xmlFile));
    but i in the output the file is loaded and getting proper output,


    But when i invoke the the method public void findField(int posistion ) throws Exception using the object, i am getting outPut without exception,
    but when i call the same method from another method im getting the exception
    Pls help me on this

  14. #14
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,006
    Rep Power
    20

    Default

    Let's start again shall we.

    Give us the exception and stack trace.
    Identify where the exception is occurring in your code, as well as giving us the method it occurs in, since simply printing the line of code is unlikely to tell us what's going on.

    Also tell us what values certain variables have (ie xmlFile). This will probably require you to use Sysout calls to print them out since you say it does no consistently happen.

Similar Threads

  1. How to avoid the Deadlock in the below program
    By murali1253 in forum New To Java
    Replies: 3
    Last Post: 04-16-2010, 05:46 PM
  2. How to avoid this problem...
    By pbaudru in forum AWT / Swing
    Replies: 6
    Last Post: 01-21-2010, 01:20 PM
  3. Replies: 19
    Last Post: 08-28-2009, 12:49 AM
  4. How to avoid focus()..?
    By ehochedez in forum NetBeans
    Replies: 9
    Last Post: 08-27-2009, 11:32 AM
  5. avoid legitimate spamming
    By hervey in forum Suggestions & Feedback
    Replies: 1
    Last Post: 10-29-2008, 08:20 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •