Giriş Yap Kayıt ol Online Üyeler Aktif Konular Arama Üyeler Forum Kuralları
Tahribat.Com | Java Hakkında Yardım.
Tahribat.Com Forumları
Java
      Java Hakkında Yardım.
Bu Bölümde yeni konu açmak için tıklayın Konuyu cevaplamak için tık...
Konu 30 Kasim 2011 (Çarsamba) 22:48 tarihinde açıldı. Kısayol | Alıntı yap | Özel Mesaj
orhantigli
(Çömez)


Kayıt : 8 Eylül 2009
Erkek Üye
 

Eclipse ile java kodlamaya çalışıyorum. Programı çalıştırdığımda Exception in thread "main" java.lang.NullPointerException  hatasını alıyorum. Neden olabileceği hakkında biri yardım edebilir mi?


 
30 Kasim 2011 (Çarsamba) 22:56 tarihinde yazıldı. Kısayol | Alıntı yap | Özel Mesaj
sLeymN


Kayıt : 31 Mart 2008
Adana
Erkek Üye
 

edit yanlış anlamışım hata kodunu.. araştırim bir


Cehennemin dibine kadar yolum var daha.. || www.logicalarea.com 
30 Kasim 2011 (Çarsamba) 23:01 tarihinde yazıldı. Kısayol | Alıntı yap | Özel Mesaj
Andrei


Kayıt : 11 Aralik 2008
h4ckc1ty
Erkek Üye
 

hocam kodu buraya kopyalasan da öyle yardımcı olsak ?


#creme de la creme. 
30 Kasim 2011 (Çarsamba) 23:10 tarihinde yazıldı. Kısayol | Alıntı yap | Özel Mesaj
orhantigli
(Çömez)


Kayıt : 8 Eylül 2009
Erkek Üye
 

Kod çok uzun valla bakmak çok zamanınızı alabilir. Ben kısaca açıklayayım. Yazmaya çalıştığım program ödevim oluyo aynı zamanda. SortedLinkList programı yazıyorum. Ekleme, silme, aratma falan var. Bi test dosyası verilmiş benden Sortedlinklist.java içerisine gerekli kodları yazmam isteniyo. Diğer java dosyalarını hoca yazmış hata olcanı sanmam :) Sortedlinklist içeriği de :

 /********************************************************************

 * SortedLinkedList ADT: Stores integers in a doubly linked list in 

 *                       ascending order of key values

 * Supported Operations:

 *

 *

 ********************************************************************/

public class SortedLinkedList {

  public LinkedListNode head, tail; /* Head and tail of the list of nodes */

  public int noOfNodes;             /* Current number of nodes in the list */

 

  /*******************************************************

   * Constructor: Initializes the linked list

   *******************************************************/

  public SortedLinkedList(){

    Clear();

  } //end-SortedLinkedList

 

  /*******************************************************

   * Removes all of the nodes from this list.

   *******************************************************/

  public void Clear(){

    head = tail = null;

    noOfNodes = 0;

  } // end-Clear

 

  /*******************************************************

   * Returns the number of nodes in the list

   *******************************************************/

  public int NoOfNodes(){return noOfNodes;}

 

  /*******************************************************

   * Inserts the given key in ascending order in the list

   *******************************************************/

  public void Add(int key){

LinkedListNode newNode = LinkedListNode();

newNode.key = key;

if (head == null){

head = newNode;

tail = newNode;

}

else{

LinkedListNode curr = head;

while (curr != null && curr.key < newNode.key){

curr =curr.next;

}//end while

if (curr == null){

//Add end.

newNode.prev = tail;

tail.next = newNode;

tail = newNode;

noOfNodes++;

}

else if (curr == head){

//Add top

newNode.next = curr;

curr.prev = newNode;

head = newNode;

noOfNodes++;

}

else{

//Add between

newNode.prev = curr.prev;

newNode.next = curr;

curr.prev.next = newNode;

curr.prev = newNode;

noOfNodes++;

}//end else if

}//end if

noOfNodes++;

  } //end-Add

 

  private LinkedListNode LinkedListNode() {

// TODO Auto-generated method stub

return null;

}

 

/*******************************************************

   * Removes the node that contains the key from the list (if the key is found)

   *******************************************************/

  public void Remove(int key){

 LinkedListNode removeNode = new LinkedListNode();

 removeNode.key = key;

 LinkedListNode curr = head;

 while (curr != null && curr.key != removeNode.key){

 curr = curr.next;

 }

 if (curr == null){

 System.out.println("Key is not found !");

 }

 else if (curr==head){

 head = curr.next;

 head.prev = null;

 noOfNodes--;

 }

 else if (curr==tail){

 tail = curr.prev;

 tail.next = null;

 noOfNodes--;

 }

 else{

 curr.next.prev = curr.prev;

 curr.prev.next = curr.next;

     noOfNodes--;

 }

 

  } //end-Remove

  /*******************************************************

   * Removes a node from the list given a pointer to the node

   *******************************************************/

  public void Remove(LinkedListNode node){

    Remove(noOfNodes);

   } //end-Remove

 

  /*******************************************************

   * Searches a key in the list and returns a pointer

   * to the list node that contains the key

   *******************************************************/

  public LinkedListNode Find(int key){

 int i=0;

 LinkedListNode removeNode = new LinkedListNode();

 removeNode.key = key;

 LinkedListNode curr = head;

 while (curr != null && curr.key != removeNode.key){

 curr = curr.next;

 i++;

 }

 if (curr == null){

 System.out.println("Key is not found !");

 } 

 else{

 System.out.println("The key is on "+i+". slot.");

 }

      return null;

  } //end-Find

};

 

 
30 Kasim 2011 (Çarsamba) 23:39 tarihinde yazıldı. Kısayol | Alıntı yap | Özel Mesaj
Sscheme


Kayıt : 4 Mart 2007
NULL
Erkek Üye
 

 

Hatayı aldığın ekranda hatanın stack trace i çıkar. Buradaki ifadeye göre hata SortedLinkedList dosyasında 67. satırda peki o satırda ne var.

        newNode.key = key;

bu ifadede görünürde bir hata yok ama aldığın hata NullPointerException yani büyük ihtimalle  tanımlanmamış bir nesneye erişmeye çalışıyorsun, hemen geriye gidip newNode ve key değişkenlerinin tanımlanıp tanımlanmadıklarına bakıyorsun.

key zaten fonksiyon parametresi olarak geliyor onda sorun yok. Sorun newNode da

LinkedListNode newNode = LinkedListNode();

ifadesinde constructor dan önce new ifadesi unutulmuş.

LinkedListNode newNode = new LinkedListNode();

Başlıkları daha açıklayıcı açarsan mesela "Java NullPointerException hatası" gibi daha güzel olur diye düşünüyorum.

Kolay gelsin...


Bütün mesajlarım ve konularım BSD Lisansı"yla lisanslanmıştır. 
30 Kasim 2011 (Çarsamba) 23:52 tarihinde yazıldı. Kısayol | Alıntı yap | Özel Mesaj
orhantigli
(Çömez)


Kayıt : 8 Eylül 2009
Erkek Üye
 

Teşekkür ederim hocam sen olmasan bu ödevi çok zor yapardım hatta yapamayabilirdim :)


 

[1]


Bu Bölümde yeni konu açmak için dıklayın Konuyu cevaplamak için tık...
Allah'a Havale Et Google Bookmark'a Ekle Yahoo'ya Ekle Stumbleupon'a Ekle Facebook'a Ekle Twitter'a Ekle   Google'da Ara : Java hakkında yardım. Favorilerime Ekle Yukarı Çık
Konuda 6 Mesaj Var.
Konu 313 Sefer Gösterilmiş.
2001-2012 © Tahribat Group - Her Hakkı Saklıdır. - ● Gizlilik İlkeleri ● Kullanım Koşulları ● İletişim