i'm trying to copy an object with a copy constructor, but it outputs an error:
Exception in thread "main" java.lang.NullPointerException
at Polynomial.<init>(Polynomial.java:30)
at Polynomial.showDerivative(Polynomial.java:59)
at Program.main(Program.java:9)
This is my copy constructor:
public Polynomial(Polynomial poly)
{
for(int i = 0; i < a.length; i++)
a[i] = poly.a[i];
for(int i = 0; i < b.length; i++)
b[i] = poly.b[i];
}
And this is how I instantiate the object:
Polynomial pol = new Polynomial(this);
What do I do?
Thanks.
Polynomialclass, not just the constructor. We need to know, what isa?poly.aandpoly.band don't use it blindly in these linesa[i] = poly.a[i];andb[i] = poly.b[i];.a=poly.a.clone(); b=poly.b.clone();.