Results 1 to 2 of 2
  1. #1
    fakepics500 is offline Member
    Join Date
    Jul 2011
    Posts
    43
    Rep Power
    0

    Default null pointer error help!!

    Java Code:
    import java.util.*;
    class kbc2
    {
    	String q1[]={"Vande Mataram was first sung at the session of the Indian National Congress in",
    			"The Battle of Plassey was fought in",
    			"The system of competitive examination for civil service was accepted in principle in the year",
    			"Universities in the Presidency towns in India were established in",};
    	String a1[]={"1896","1757","1853","1857",};
    	String o1[]={"1892","1904","1886","1782","1748","1764","1897","1823","1899","1858","1900","1909",};
    	String q2[]={"qutab minar is in which state",
    			"which place is I.T hub of india",
    			"which state has biggest slum in INdia",
    			"_________ is called pink city "};
    	String a2[]={"New delhi","banlore","mumbai","jaipur"};
    	String o2[]={"u.p","bihar","tamil naidu","agra","chennia","kolkata","haryana","punjab"};
    	int money[]={0,1000,2000,3000,5000,10000,20000,40000,80000,160000,320000,640000,1250000,2500000,5000000,10000000};
    	String com1[]={"amithab: coumpter ji what is next question",
    			"amithab :next question pesh kare",
    			"amithab: kya next question  ke liye ready hai",
    			"amithab : nexy question hai"};
    	String com2[]={"amithab: shhhh ap har gaye",
    			"amithab :app har gaye",
    			"amithab:apke sapne aduhre rahe gaye ",
    			"amithab: app yeah kar sakte the",
    			"amithab: apne bahut acha kelhla",
    			"amithab jingayi me har jeet hoti hoti rahti hai"};
    	String com3[]={"amithab:kya lagte hai apke sahi answere kya tha",
    			"amithab: kya apko isks answere atha tha",
    			"amithab: kon sa option app ko laga ke sahi answere hai",
    			"amithab: apne bahut acha khela"};
    	int q10[]={0,0,0,0};
    	int q20[]={0,0,0,0};
    	String option[];
    	int ans=0;
    	void selectquestion(int l,String q[],int qq[],String a[],String o[],int len)
    	{ 
    		int rq,ra;
    		Random r= new Random();
    		rq=r.nextInt(l);
    		if(qq[rq]==0)
    		{
    			System.out.println(q[rq]);
    			qq[rq]=1;
    		}
    		else
    			selectquestion(l,q,qq,a,o,len);
    		ra=r.nextInt(4);
    		if(ra==0)
    		{
    			option[0]=a[rq];
    			System.out.println(option[0]);
    			for(int i=0;i<3;i++)
    			{
    				option[i+1]=o[r.nextInt(len)];
    				System.out.println(option[i+1]);
    			}	
    			ans=1;
    			
    		}
    		if(ra==1)
    		{
    			option[0]=o[r.nextInt(len)];
    			System.out.println(option[0]);
    			option[1]=a[rq];
    			System.out.println(option[1]);
    			for(int i=0;i<2;i++)
    			{
    				option[i+2]=q[r.nextInt(len)];
    				System.out.println(option[i+2]);
    			}
    			ans=2;
    		}
    		if(ra==2)
    		{
    			for(int i=0;i<2;i++)
    			{
    				option[i]=o[r.nextInt(len)];
    				System.out.println(option[i]);
    			}
    			option[2]=a[rq];
    			System.out.println(option[2]);
    			option[3]=o[r.nextInt(len)];
    			System.out.println(option[3]);
    			ans=3;
    		}
    		if(ra==3)
    		{
    			for(int i=0;i<3;i++)
    			{
    				option[i]=o[r.nextInt(len)];
    				System.out.println(option[i]);
    			}
    			option[3]=a[rq];
    			System.out.println(option[3]);
    			ans=4;
    		}	
    				
    				
    	}	
    	public void my()
    	{
    		Random r1= new Random();
    		int qch,nextq=0,m=1,bal=0;
    		do{
    		System.out.println("\033"); 
    		qch=r1.nextInt(2);
    		int len1=o1.length;
    		int len2=o2.length;
    		int l1=q1.length;
    		int l2=q2.length;
    		System.out.println("\n\nyou have won= "+money[bal]+"\n");
    		System.out.println("\n\n\t\t\tThis question is for Rs"+money[m]+"\n\n");		
    		if(qch==0)
    		{
    			selectquestion(l1,q1,q10,a1,o1,len1);
    		}
    		else if(qch==1)
    		{
    			selectquestion(l2,q2,q20,a2,o2,len2);	
    		}
    		Scanner sc=new Scanner(System.in);
    		int uans;
    		System.out.println("\n\n\n\t\t\tenter your answere 1,2,3,4\n");
    		System.out.println("\n\n\n\t\t\tif you want to quit enter 5\n");
    		uans=sc.nextInt();
    		if(uans==ans)
    		{
    			System.out.println("\n\n\n\t\t\tCorrect answere\n\n\n\n");
    			nextq=1;m++;bal++;
    			if(m==14)
    			{
    				System.out.println("\n\ncongrats\t\t\t\t\t\t\tcongrats");
    				System.out.println("\n\n\t\t\t\t\t\tyou are new Crorepati\n\n\n");
    				System.out.println("\n\ncongrats\t\t\t\t\t\t\tcongrats");
    			}
    		}
    		else if(uans==5)
    		{
    			System.out.println("\t\t\tyou have quited this question");
    			System.out.println(com3[r1.nextInt(4)]);
    			System.out.print("\t\tthe answere to the question was ");
    			if(qch==0)
    				System.out.println("option "+ans+" "+option[ans]);
    			if(qch==1)
    				System.out.println("option "+ans+" "+option[ans]);
    			nextq=0;
    		}
    		else
    		{
    			nextq=0;
    			System.out.println("\n\n\t\t\twrong answere\n");
    			System.out.println(com2[r1.nextInt(6)]);
    			System.out.print("\t\t\t you have won=");
    			if((money[bal]<10000)&&(money[bal]>=0))
    			System.out.println("0");
    			if((money[bal]<320000)&&(money[bal]>=10000))
    			System.out.println("10000");
    			if((money[bal]<10000000)&&(money[bal]>=320000))
    			System.out.println("320000");
    		}
    		if(nextq==1)
    			System.out.println(com1[r1.nextInt(4)]);
    		}while(nextq==1);
    
    	}
    	
    }
    
    class kbc22 extends kbc2
    {
    	
    	public static void main(String ar[])
    	{
    		kbc2 k=new kbc2();
    		k.my();
    		
    	}
    }
    the complies but when i run it gives nullpointexpection

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    Which line is line 50? You must have something uninitialized, try printing values you use and see which one prints null

Similar Threads

  1. Error = Null pointer with inner class
    By jonytek in forum New To Java
    Replies: 3
    Last Post: 05-11-2011, 04:10 AM
  2. Null Pointer Exception error
    By tfitz666 in forum New To Java
    Replies: 3
    Last Post: 03-28-2010, 07:20 PM
  3. Null Pointer
    By theen3my in forum AWT / Swing
    Replies: 3
    Last Post: 10-03-2009, 02:10 PM
  4. null pointer help
    By mayhewj7 in forum New To Java
    Replies: 5
    Last Post: 02-17-2009, 11:51 PM
  5. Null pointer exception error
    By brownie_jedi in forum New To Java
    Replies: 3
    Last Post: 03-15-2008, 06:27 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
  •