java-error in null pointer exception

PLEASE HELP ME TO FIND THIS ANSWER NULL POINTER EXCEPTION ERROR HELP ME

on these two lines

25,83 null pointer exception please correct my code i created a object l with reference to class linkk to access methods in the class but while accessing the methods in the class with different conditions it is showing null pointer exception i didnt finish the code due to this error im struck at this point i cant move further this is my post in overflow i have read answers in overflow but this is the first time fr me to post a question in overflow , today i created a ac nd posting this question please help me frnds

import    java . util.Scanner;



class node
{
    int i,q;	
     node next;
     node prev;
}

class link{
    public static void main(String args[])
{
    	linkk l = new linkk();
    	
  l.op();
    	int user=0;  	
     while(user!=10)
    {Scanner a=new Scanner(System.in);
      if(user==1)
      {
    	  System.out.println("\nenter data\n");
    	  
    	  l.create(a.nextInt());
     
      }System.out.println("\n1.create link\n2.insert beginning\n3.insert middle\n4.insert end\n5.delete data\n6.reverse");
user=a.nextInt();
}
if(user==2)
l.insertbeg();
if(user==3)
	l.insertmid();
if(user==4)
	l.insertend();
if(user==5)
	l.del();
if(user==6)
	l.reverse();
if(user==7)
l.display();
		
	}

}

class  linkk
{  
node temp4;
int ch,add,cnt=0,t=0,b;
node p= new node();
node q;
	node last;
node first=null;

public boolean isEmpty()

{

    return first == null;

}

public  void insertbeg()
{
}

public  void insertmid()
{
}
public void insertend()
{
}
public  void del()
{
} 
public  void reverse()
{
}
public  void display()
{
}
public  void create(int val)
{   
	 first.i=val;

	 first.next=null;
	 cnt++;   
        }
 public void ob()
 {
 }
 public void op()
 {
}
}

Answers


Your defined first as null as node first=null; and you are trying to access i with first object using first.i=val; by calling l.create(a.nextInt());.

You should initialize first as below:

node first = new node();//and then access i of it and so on.

Need Your Help

Android Activity Flow

android android-activity

I have two Activities, say A1 and A2. sequence being A1->A2

HTML Validator that is extensible

html validation extensibility

Several validators, such as the one by the W3C, can validate an HTML (or XHTML) page against the W3C spec. Are there any validators that are extensible? That is, I'd like to not only validate aga...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.