| | |
Exception error for heap
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Nov 2007
Posts: 28
Reputation:
Solved Threads: 0
I'm not sure if I'm doing this correctly but up to now I get an exception error. Can you see why? :
Java Syntax (Toggle Plain Text)
public void countHeap(){ System.out.println("input data:"); for (int i = 0; i < dataSet.length; i++) { System.out.print(" "+dataSet[i]); count++; } noDataElements = count; formHeapTree(); } public void formHeapTree(){ int unsortedSet[] = new int[noDataElements]; noDataElementsHalf = (noDataElements+1)/2; System.out.println("\nheap Array"); for (int j = 0; j < unsortedSet.length ; j++) { for (int i = noDataElementsHalf; i < noDataElements; i++) { unsortedSet[i] = dataSet[j]; } System.out.print(" "+ unsortedSet[j]); } sortLevel(); for (int j = 0; j < unsortedSet.length ; j++) { for (int i = 0; i < noDataElementsHalf; i++) { unsortedSet[i] = dataSet[j]; } System.out.print(" "+ unsortedSet[j]); } } public void sortLevel(){ System.out.print("\nheap array \n "); for (int i = unsortedSet.length; i > 0; i--) { int j = i-1; //Parent must be smaller than child if(unsortedSet[j] > unsortedSet[i]) { int temp = unsortedSet[i]; unsortedSet[i] = unsortedSet[j]; unsortedSet[j] = temp; } } }
Last edited by Cleo123; Dec 1st, 2008 at 2:11 am.
Exception error, Now thats the most generic term I can think of when describing a problem, Can you be more specific as to what Exception you are getting and at what line number the exception is being thrown as indicated by your JVM ???
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."
"How to ask questions the smart way ?"
"How to ask questions the smart way ?"
Again you have posted the exception without much detail for e.g. line no. Also since oyu haven't put in your entire code and since also your code is not indented properly it is difficult figuring out where the exception would be and hence why it would be occurring at all.
Still I present a hint here : Nullpointer exception occur at places where you use a null reference. This would be where you are using the dot operator (.) and the reference on the LHS of it is a null reference. IF you can figure out yourself where this would be happening in your program - great, but if not you can help us by posting the code part in question e.g. the main method and the entire stack trace with line numbers for the code part.
Still I present a hint here : Nullpointer exception occur at places where you use a null reference. This would be where you are using the dot operator (.) and the reference on the LHS of it is a null reference. IF you can figure out yourself where this would be happening in your program - great, but if not you can help us by posting the code part in question e.g. the main method and the entire stack trace with line numbers for the code part.
![]() |
Similar Threads
- Cannot find server or DNS Error - please help! (Viruses, Spyware and other Nasties)
- Why atof causes a C0000005 exeption? (C++)
- memory leak problem... (C)
- Identifying Drivers needed (Windows 95 / 98 / Me)
- OutOfMemory Error (Java)
- Unexplainable Error Help Needed! (Windows NT / 2000 / XP)
- Exception error (HTML and CSS)
- IE Browser shutting down and shows error on desktop (Java)
- Error Message in the VM (Windows NT / 2000 / XP)
Other Threads in the Java Forum
- Previous Thread: Need help with adt table
- Next Thread: Help with really bad pong game
| Thread Tools | Search this Thread |
android api applet application array arrays automation awt bidirectional binary birt bluetooth businessintelligence busy_handler(null) chat class classes client code columns component constructor database designadrawingapplicationusingjavajslider draw eclipse editor error errors event eventlistener exception expand fractal game givemetehcodez graphics gui guidancer html ide image inetaddress input integer intellij j2me java javafx javamicroeditionuseofmotionsensor javaprojects jme jni jpanel jtree julia linux list loop map method methods mobile mobiledevelopmentcreatejar myaggfun netbeans newbie oracle parsing plazmic print problem program programming project recursion scanner screen server set sharepoint size smart sms smsspam sort sortedmaps sql string subclass support swing textfield threads time tree unlimited utility webservices windows






