Results 1 to 6 of 6

Thread: Java program compiles but does not executes

  1. #1
    Join Date
    Dec 2009
    Posts
    202

    Java program compiles but does not executes

    Hello,
    I knew working netbean side but unfortunately the program that compiles but does not executes. Please help it is making me crazy.
    import java.util .*;

    Public class classeleve {
    String name;

    int nbnt;
    int[] nt;
    Public void Pupils(String name,int nbnt)
    {

    this.name= name;

    this.nbnt= nbnt;

    }
    Public int GetNote(int num)
    {
    return nt[num];
    }
    Public void SetNote(int num,int nt)
    {
    this.nt[num]= nt;
    }
    Public void setNotes( int [ ] has )
    {
    }
    Public void SaisirNote()
    {
    Scanner inp =new Scanner(System.in);
    System.out.System.out.println("enter the grade of the student"+ Name +")");
    for(int i =0; i <nbnt; i + +)
    {
    System.out.System.out.println("enter the nt num ("I + +")");
    nt[i]= inp.nextInt();/ / This is where it stops running
    }

    }
    Public double Average( )
    {
    int i =0, sum =0, Mean =0;
    while(i <nbnt)
    {
    sum + = grade[i];
    i + +;
    }
    mean = sum / i;
    return sum;
    }
    Public int Notemaximale( )
    {
    int i =0, max = grade[0];
    for(i =1; i <nbnt; i + +)
    {
    if(max <nt[i])
    = max rating[i];
    }
    return max;
    }
    Public int Noteminimal( )
    {
    int i =0, min = grade[0];
    while(i <nbnt)
    {
    if(min> nts[i])
    min = grade[i];
    }
    return min;
    }
    Public void display()
    {
    System.out.System.out.println(name);
    for(int elements: nt)
    System.out.System.out.println(elements);
    }
    }
    Last edited by ISAIAH; 14-01-2010 at 04:02 PM.

  2. #2
    Join Date
    May 2008
    Posts
    2,012

    Re: Java program compiles but does not executes

    Hi,
    I think you never initialized the table note [], there must be a moment you declare it as:
    Code:
    nt[]=new int[nbnt]
    It is best to do in your after builders instantiated nbnote. Just try this and if you have any more problems then post back.
    Last edited by Katty; 14-01-2010 at 04:02 PM.

  3. #3
    Join Date
    Dec 2009
    Posts
    202

    Re: Java program compiles but does not executes

    Hello,
    Thanks but even if I initialize the problem and always that's what the compiler writes in performance:
    Code:
    Exception in thread "Hand" java.lang.ArrayIndexOutOfBoundsException: 0
            Has classeleve.SaisirNote(classeleve.java:39)
            Has Hand.hand(Hand.java:25)
    Java Result: 1
    BUILD SUCCESSFUL (Total time: 11 seconds)
    Any help on this.

  4. #4
    Join Date
    May 2008
    Posts
    2,297

    Re: Java program compiles but does not executes

    Hello,
    I think you should add this to your code-
    Public void Pupils(String name,int nbnt)
    {
    this.name= name;
    this.nbnt= nbnt;
    this.nt = new int[nbnt];
    }
    Otherwise a small remark: you should go see the naming conventions for Java code is easier to read when it follows these conventions.

  5. #5
    Join Date
    Feb 2008
    Posts
    1,852

    Re: Java program compiles but does not executes

    Hi,
    Following the error, you must exit a table here, see below
    nt[i]= input.nextInt();
    Are you sure that your table is large enough notes for all your charged?
    Look to ArrayList or Vector if you do not know in advance cb you will note ( "table" Extensible)

  6. #6
    Join Date
    Jan 2008
    Posts
    1,521

    Re: Java program compiles but does not executes

    Hello.
    I tested your code. It will function properly if you initialize your chart notes. You have the choice between initialize in your class as follows:
    int[] nt = new int [MAX];
    With a constant MAX.
    Or you initialize in the hand when the user inform you of the number of points associated with each pupil, as follows:
    Dupont.nt = new int[nbrePtDupont];
    Durant.nt = new int[nbPtDurant];
    Good luck.

Similar Threads

  1. Dr. Java program
    By bamggut29 in forum Software Development
    Replies: 2
    Last Post: 26-11-2011, 04:24 AM
  2. Configuring a program that executes only once.
    By Robin Pande in forum Windows Software
    Replies: 3
    Last Post: 23-12-2010, 11:25 AM
  3. Replies: 6
    Last Post: 24-05-2010, 10:45 AM
  4. Link List Example in Java Sample program in Java
    By trickson in forum Software Development
    Replies: 2
    Last Post: 04-08-2009, 08:23 PM
  5. Embed all files from folder when application compiles
    By Sanket07 in forum Software Development
    Replies: 2
    Last Post: 31-01-2009, 04:00 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,718,524,267.21978 seconds with 17 queries