Results 1 to 14 of 14
- 12-07-2010, 07:10 AM #1
Member
- Join Date
- Nov 2010
- Posts
- 11
- Rep Power
- 0
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
- 12-07-2010, 09:20 AM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
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)?
- 12-07-2010, 12:21 PM #3
You better post your full class code.
Mak
(Living @ Virtual World)
- 12-07-2010, 12:49 PM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
The exception would be more useful at the moment I'd say.
- 12-07-2010, 12:59 PM #5
Member
- Join Date
- Dec 2010
- Posts
- 19
- Rep Power
- 0
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.
- 12-07-2010, 01:19 PM #6
Member
- Join Date
- Nov 2010
- Posts
- 11
- Rep Power
- 0
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));
- 12-07-2010, 01:22 PM #7
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
What exception!
- 12-07-2010, 01:28 PM #8
Member
- Join Date
- Nov 2010
- Posts
- 11
- Rep Power
- 0
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)
- 12-07-2010, 01:45 PM #9
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
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.
- 12-07-2010, 02:46 PM #10
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,606
- Blog Entries
- 7
- Rep Power
- 17
When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 12-07-2010, 02:46 PM #11
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
You know me, I like to be cryptic.
- 12-07-2010, 03:35 PM #12
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,606
- Blog Entries
- 7
- Rep Power
- 17
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:
kind regards,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
Jos ;-)When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 12-08-2010, 05:48 AM #13
Member
- Join Date
- Nov 2010
- Posts
- 11
- Rep Power
- 0
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
- 12-08-2010, 08:58 AM #14
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
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
-
How to avoid the Deadlock in the below program
By murali1253 in forum New To JavaReplies: 3Last Post: 04-16-2010, 05:46 PM -
How to avoid this problem...
By pbaudru in forum AWT / SwingReplies: 6Last Post: 01-21-2010, 01:20 PM -
How can I avoid java.util.ConcurrentModificationException exception?
By trueblue in forum New To JavaReplies: 19Last Post: 08-28-2009, 12:49 AM -
How to avoid focus()..?
By ehochedez in forum NetBeansReplies: 9Last Post: 08-27-2009, 11:32 AM -
avoid legitimate spamming
By hervey in forum Suggestions & FeedbackReplies: 1Last Post: 10-29-2008, 08:20 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks