![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Hobbyist Programmer
Join Date: Mar 2005
Posts: 139
Rep Power: 4
![]() |
Hi All,
This gives me a null pointer exception: System.out.println("\nThere are " + polyInstance.signChanges(tempCoefsArray, noCoefs) + " positive real roots in the equation you entered\n");
......other non important code here.....
public int signChanges(String tempCoefsArray[], int noCoefs)
{
int signChanges=0;
for(int i=0; i<=tempCoefsArray.length-2; i++)
{
if(tempCoefsArray[i].charAt(0) != tempCoefsArray[i+1].charAt(0))//null ptr here
{
signChanges++;
}
}
return signChanges;
}Last edited by paulchwd; Apr 14th, 2007 at 12:20 AM. |
|
|
|
|
|
#2 |
|
Hobbyist Programmer
|
I'm not sure if it is the same with Chars as it is with strings, but I know with strings, you have to do
tempCoefsArray[i].charAt(0).equals |
|
|
|
|
|
#3 |
|
Expert Programmer
|
@PhilBon: The OP is correctly comparing chars with the != operator; however you are correct that in most cases Strings should be compared with the equals method.
@paulchwd: It appears one of the elements in the tempCoefsArray is null. If you did not intend this to be the case you should review the code in which the argument is generated. However, if you accept the possibility that one of the elements of tempCoefsArray might be null, you should check for that before comparing each value. Also, the second argument to the signChanges method is unused within the method, and if it represents what its name would indicate (the length of the array) the information it provides is redundant. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Function Parameters | grimpirate | PHP | 10 | Mar 14th, 2007 6:55 PM |
| C# corruption!!! | Kilo | C++ | 32 | May 21st, 2006 8:44 PM |
| Array issues :( | Alo Tsum | Java | 10 | Nov 26th, 2005 5:45 PM |
| A standards question, optional inputs into Methods | Arla | C# | 4 | Apr 27th, 2005 10:38 PM |
| replace space with ' * ' | TecBrain | C++ | 15 | Apr 13th, 2005 12:32 PM |