943,851 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 507
  • Java RSS
Dec 1st, 2008
0

Exception error for heap

Expand Post »
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)
  1.  
  2. public void countHeap(){
  3. System.out.println("input data:");
  4. for (int i = 0; i < dataSet.length; i++) {
  5. System.out.print(" "+dataSet[i]);
  6. count++;
  7. }
  8. noDataElements = count;
  9. formHeapTree();
  10. }
  11. public void formHeapTree(){
  12.  
  13. int unsortedSet[] = new int[noDataElements];
  14.  
  15. noDataElementsHalf = (noDataElements+1)/2;
  16.  
  17. System.out.println("\nheap Array");
  18. for (int j = 0; j < unsortedSet.length ; j++) {
  19. for (int i = noDataElementsHalf; i < noDataElements; i++) {
  20. unsortedSet[i] = dataSet[j];
  21. }
  22. System.out.print(" "+ unsortedSet[j]);
  23. }
  24. sortLevel();
  25.  
  26. for (int j = 0; j < unsortedSet.length ; j++) {
  27. for (int i = 0; i < noDataElementsHalf; i++) {
  28. unsortedSet[i] = dataSet[j];
  29. }
  30. System.out.print(" "+ unsortedSet[j]);
  31. }
  32. }
  33. public void sortLevel(){
  34.  
  35. System.out.print("\nheap array \n ");
  36. for (int i = unsortedSet.length; i > 0; i--) {
  37. int j = i-1;
  38. //Parent must be smaller than child
  39. if(unsortedSet[j] > unsortedSet[i]) { int temp = unsortedSet[i];
  40. unsortedSet[i] = unsortedSet[j];
  41. unsortedSet[j] = temp;
  42. }
  43. }
  44. }
Last edited by StephNicolaou; Dec 1st, 2008 at 2:11 am.
Similar Threads
Reputation Points: 39
Solved Threads: 12
Junior Poster
StephNicolaou is offline Offline
159 posts
since Nov 2007
Dec 1st, 2008
0

Re: Exception error for heap

Please mention in detail what Exception you are getting.
BTW are you getting an ArrayOutOfBoundsException ?
Reputation Points: 485
Solved Threads: 89
Posting Shark
verruckt24 is offline Offline
944 posts
since Nov 2008
Dec 1st, 2008
0

Re: Exception error for heap

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 ???
Featured Poster
Reputation Points: 653
Solved Threads: 151
Nearly a Posting Virtuoso
stephen84s is offline Offline
1,316 posts
since Jul 2007
Dec 1st, 2008
0

Re: Exception error for heap

Sorry...Null Pointer Exception - Exception in thread "main"
Reputation Points: 39
Solved Threads: 12
Junior Poster
StephNicolaou is offline Offline
159 posts
since Nov 2007
Dec 1st, 2008
0

Re: Exception error for heap

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.
Reputation Points: 485
Solved Threads: 89
Posting Shark
verruckt24 is offline Offline
944 posts
since Nov 2008
Dec 1st, 2008
0

Re: Exception error for heap

public void formHeapTree() {

        int unsortedSet[] = new int[noDataElements];
Certainly int unsortedSet[] hides Your previous declaration -> delete int
quuba
Reputation Points: 123
Solved Threads: 106
Posting Pro
quuba is offline Offline
573 posts
since Nov 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Need help with adt table
Next Thread in Java Forum Timeline: Help with really bad pong game





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC