Results 1 to 2 of 2
  1. #1
    ekeuus is offline Member
    Join Date
    May 2013
    Posts
    1
    Rep Power
    0

    Default Exception in thread "main" java.lang.NullPointerException

    So im trying to make this beginner java project and im not very familiar with java. I'm gettin the error that's in the title. It says the error occurs at line 59... Thanks in advance! Sorry for it not being in english!

    Java Code:
    import java.util.Scanner;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    
    
    class main{
    		
    	class inimene{
    		int kood;
    		String nimi;
    		int boonus;
    		public inimene(int kood, String nimi, int boonus){
    			this.kood = kood;
    			this.boonus = boonus;
    			this.nimi = nimi;
    			
    		}
    		
    		public class filmid extends inimene{
    			int paevad;
    			int kood = 1;
    			public filmid(int kood, String nimi, int boonus, int paevad) {
    				super(kood, nimi, boonus);
    				this.kood = kood;
    				this.paevad = paevad;
    				// TODO Auto-generated constructor stub
    			}
    			
    		}
    	}
    	class film{
    		int kood = 1;
    		String nimi;
    		String liik;
    		public film(int kood, String nimi, String liik){
    			this.kood = kood;
    			this.nimi = nimi;
    			this.liik = liik;
    		}
    	
    	}
    	/**
    	 * @param args
    	 */
    	
    	public static void main(String[] args) {
    		@SuppressWarnings("resource")
    		Scanner scanIn = new Scanner(System.in);
    		String action = "asd";
    		int basic_price = 3;
    		int premium_price = 4;
    		int i = 0;
    		int FilmideArv = 0;
    		int KlientideArv = 0;
    		main.inimene[] klient = new main.inimene[100];
    		klient = new main.inimene[10];
    		main.film[] Films = new main.film[100];
    		klient[0].nimi = "lol";
    		int j;
    		for(int i1 = 0; i1<5; i1++){
    			klient[i1].nimi = scanIn.nextLine();
    		}
    		
    		for(int i1 = 0; i1<5; i1++){
    			System.out.println(klient[i1].nimi);
    		}
    //		while(!action.equals("exit")){
    //			System.out.println("Vali, kas soovid:");
    //			System.out.println("a) Näha kõiki filme");
    //			System.out.println("b) Näha renditud filmide hinda");
    //			System.out.println("c) Näha kasutajate boonuspunkte");
    //			System.out.println("Kirjuta \"exit\", et väljuda");
    //			action = scanIn.nextLine();
    //			
    //			if(action.equals("a")){
    //				System.out.println("A");
    //	
    //				//prindi k6ik filmid
    //			}
    //			else if(action.equals("b")){
    //				System.out.println("B");
    //				//arvuta hinnad
    //			}
    //			else if(action.equals("c")){
    //				System.out.println("C");
    //				//boonus
    //			}
    //		}
    		
    		
    		// TODO Auto-generated method stub
    		
    		System.out.println("Aitäh kasutamast, sulgun...");
    
    	}
    	public static char[] getInt(String string) {
    		// TODO Auto-generated method stub
    
    		return null;
    	}
    
    }

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,782
    Rep Power
    7

    Default Re: Exception in thread "main" java.lang.NullPointerException

    When you create an object array it does not automagically create all the objects for you. Also you create an array with a length of 100 then immediately throw it away and create an array of 10. Why?

Similar Threads

  1. Replies: 6
    Last Post: 04-19-2012, 07:10 PM
  2. Replies: 5
    Last Post: 12-21-2011, 06:44 PM
  3. Replies: 6
    Last Post: 07-16-2009, 03:30 PM
  4. Replies: 1
    Last Post: 07-16-2009, 10:35 AM
  5. Replies: 1
    Last Post: 07-16-2007, 06:32 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
  •