Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > Java
You last visited: Today at 00:46

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



Custom LinkedList class hasNext Methode

Discussion on Custom LinkedList class hasNext Methode within the Java forum part of the Coders Den category.

Reply
 
Old   #1
 
Jonni8's Avatar
 
elite*gold: 4
Join Date: Jun 2010
Posts: 239
Received Thanks: 15
Custom LinkedList class hasNext Methode

Hey leute.

Ich bin grad dabei eine eigene LinkedList Klasse zu schreiben.
Jetzt hat so ein LinkedList Objekt je 2 Variablen. Den Namen und ein weiteres LinkedList objekt. Ich möchte mit einer Funktion prüfen können ob ein LinkedList Objekt noch weitere Elemente besitzt oder ob ein Element das letzte ist. Leider stoße ich dabei auf das Problem, dass meine hasNext() Methode immer true ausgibt und als ich versucht habe das auf andere Weise zu prüfen bekam ich einen NullPointerExceptionError.

Hier der relevante Code dafür:

Code:
public class MyLinkedList
{
    private String name;
    private MyLinkedList next;
    
    public MyLinkedList( String name )
    {
        this.name = name;
    }
    
    public MyLinkedList( )
    {
        this( "" );
    }
    public MyLinkedList getNext()
    {
        return next;
    }
    private boolean hasNext()
    {
        System.out.println("loop"); //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! IMMER TRUE?...
        System.out.println(this.getNext() != null);
        return this.getNext() != null;
    }
}
Die prints sind nur aus Testzwecken drin.
Habt ihr vielleicht eine Idee wie man das anders testen kann?

Gruß
Jonni8 is offline  
Old 06/07/2015, 02:52   #2
 
elite*gold: 0
Join Date: May 2015
Posts: 700
Received Thanks: 445
Code:
public class MyLinkedList
{

    public static void main(String[] args) {
        MyLinkedList mll = new MyLinkedList();
        System.out.println(mll.hasNext());
    }

    private String name;
    private MyLinkedList next;
    
    public MyLinkedList( String name )
    {
        this.name = name;
    }
    
    public MyLinkedList( )
    {
        this( "" );
    }
    public MyLinkedList getNext()
    {
        return next;
    }
    private boolean hasNext()
    {
        System.out.println("loop"); //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! IMMER TRUE?...
        System.out.println(this.getNext() != null);
        return this.getNext() != null;
    }
}
Gibt bei mir false aus.
algernong is offline  
Thanks
1 User
Old 06/07/2015, 12:26   #3
 
Jonni8's Avatar
 
elite*gold: 4
Join Date: Jun 2010
Posts: 239
Received Thanks: 15
Jo, danke ich hab das jetzt nochmal ausprobiert und das Problem tritt tatsächlich erst auf wenn ich einige Elemente hinzufüge. Muss mir das wohl nochmal angucken
Jonni8 is offline  
Reply


Similar Threads Similar Threads
Some custom class icons
11/14/2014 - Shaiya PServer Guides & Releases - 4 Replies
1) http://i.imgur.com/LBS4yvB.jpg http://i.imgur.com/TfyW9co.jpg 2) http://i.imgur.com/1BAzoRN.jpg 3) http://i.imgur.com/pZzWebJ.jpg 4) http://i.imgur.com/M2VDVkH.jpg (LoL icons) http://i.imgur.com/vV02xUt.jpg
HBRelog lädt Custom Class nicht
01/26/2014 - World of Warcraft - 1 Replies
Hey, habe folgendes Problem mit meine honorbuddy-relogger (HB-Relog), ich habe die Custom Class angegeben, die er laden soll, er bleibt aber beim Fenster hängen und lädt garkeine. Muss ich die iwie umbenennen?
MW3 Custom Class
07/04/2013 - Call of Duty - 3 Replies
Hallo Habe mir heute MW3 Mit 4Delta1 installiert Es funktioniert auch alles einwandfrei außer das ich keine custom class erstellen kann Alle waffen die ich bis jetzt freigeschaltet habe sind ausgeschwarzt und ja ich habe level 15 also sollte es auch funktionieren ich kann also nur die standartklassen spielen Kann mir jemand bitte helfen? habe schon google gefragt aber keine antwort gefunden
Custom Class
01/17/2009 - WoW Bots - 2 Replies
Hey, ich hab mal ne bitte an jemanden mit Glider Forum Acc. Ich brauch die neuste Ooberhunter Custom class version( wenns geht die ppather version) kann mir die mal einer uppen?



All times are GMT +2. The time now is 00:46.


Powered by vBulletin®
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2024 elitepvpers All Rights Reserved.