0

I am trying to access the edited poly node when making and checking combining.degree, however I get a NullPointerException, how can I fix this? I want to use the poly that was edited in the while loop instead of the poly made outside of the while loop that was made null. This is a

    public static Node multiply(Node poly1, Node poly2) {
    Node poly3=poly1;
    Node poly4=poly2;
    Node poly=null;
    while (poly3!=null)
    {
        while(poly4!=null)
        {
            float x;
            int y;
            x=poly3.term.coeff*poly4.term.coeff;
            y=poly3.term.degree*poly4.term.degree;
            poly=new Node(x,y,poly);
            poly4=poly4.next;
        }
        poly4=poly2;
        poly3=poly3.next;
    }
    
    Node finalpoly=null;
    int i=poly.term.degree;
    float csum=0;
    Node combining = poly;
    while (i>=combining.term.degree)
    {
        while (combining!=null)
        {
            if (i==combining.term.degree)
            {
                csum+=combining.term.coeff;
            }
            combining=combining.next;
        }
        if (csum!=0)
        {
            finalpoly = new Node(csum, i, finalpoly);
        }
        i--;
    }
    
hunter s
  • 1
  • 1
  • Is either argument `null`? – Solomon Ucko Oct 04 '20 at 01:16
  • sorry, i edited the code it was wrong before, but combining.term.degree comes up as null in the while statement – hunter s Oct 04 '20 at 01:37
  • Is `combining` in `while (i>=combining.term.degree)` supposed to refer to the value it had before the loop, or the last non-null value produced by the inner loop (`while (combining!=null)`), or something else? – Solomon Ucko Oct 04 '20 at 01:45
  • it is meant to refer to the value it had before the loop, basically the same as poly.term.degree, and when i print before the loop it prints the correct value, 20 – hunter s Oct 04 '20 at 01:47

0 Answers0