Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Matlab / Java Linked List Error

  1. #1
    Junior Member
    Join Date
    Dec 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Matlab / Java Linked List Error

    Hi
    i'm working on my Final university Project , and my time is too short the project is about Wireless sensor network and i have to simulate one of the recent papers about it. most of the coding is done but i have a simple problem about linked list(i use matlab and import java libraries into it for using linked list)

    okay here is some explanation i have a queue/list that every time head of the list is checked that is it the goal or not if its not a goal it deletes the first item and gets the second one which is actualy the first one in the list problem occurs when my list has only 1 item and its not goal so code delete the first item , AFTER that code tries to get the first item which is null and empty thats when Error happens ,

    my goal is after checking/searching all the list if it was successful turn flagg=1 if not flagg=0

    while temp ~= goal;

    for K=1:size(G,1)

    if temp == G(K,1)
    q.add(G(K,2))

    end
    end

    if (~q.isEmpty())

    q.removeFirst();
    temp=q.getFirst();

    else
    flagg=1

    end

    end
    Thanks. M.Dadmand


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,529
    My Mood
    Hungover
    Thanks
    144
    Thanked 647 Times in 552 Posts

    Default Re: Matlab / Java Linked List Error

    What happens when the list only has a single element? Trace through this with a piece of paper and a pencil if you have to.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Dec 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Matlab / Java Linked List Error

    thank you so much for reply
    let me explain more
    first my search is Breadth first search

    if the algorithm find the goal it will break the While and everything is fine
    but at the moment no result has found (that means the queue is empty)

    i have a matrix like this :
    [1,2; 1,3 ; 1,5 ; 3,8 ; 5,10]

    i input 1 by hand for the first number in queue
    it searches the 1 in my matrix (only the first column) we have 3 ones in our first column
    so it add 2 , 3 , 5 to the queue
    after finish searching in my matrix it deletes the first one (q.removeFirst()
    and gets the first one so now is 2
    loop repeats until we are at 10 and no goal found yet
    so at this line :

    q.removeFirst();
    temp=q.getFirst();
    it removes 10 and tries to get first item which is nothing/null and that's when error happens
    so what i want to do after that is turn a flag 1 and come out of my while loop

    if i use poll method instead of these
    q.removeFirst();
    temp=q.getFirst();

    lines everything could work fine , saddly matlab gives me this error for it
    Undefined function 'pollFirst' for input arguments of type 'double'.

    Error in TestFInal2 (line 102)
    pollFirst(temp)


    EDIT : problem solved , i just added a break in while

    so it breaks the while NOT the whole code
    btw i was stuck at in in weeks
    i have another problem its about graph should i make another thread ?

Similar Threads

  1. Replies: 1
    Last Post: October 25th, 2012, 03:03 PM
  2. Singly Circular Linked List Error
    By clydefrog in forum Collections and Generics
    Replies: 7
    Last Post: March 5th, 2012, 08:17 PM
  3. Linked list Schminked list help with Nodes Please
    By Bially in forum Collections and Generics
    Replies: 1
    Last Post: September 29th, 2011, 04:20 PM
  4. need help with Doubly-Linked list programing in java
    By bulutbey in forum Algorithms & Recursion
    Replies: 3
    Last Post: August 22nd, 2011, 02:51 PM
  5. Java Newbie - Sorted Linked List not inserting properly - please help!
    By bubbleboy in forum What's Wrong With My Code?
    Replies: 20
    Last Post: June 17th, 2011, 12:48 PM

Tags for this Thread