Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Error when searching an array from another class' method...(Error when searching an array from another class' method...)
Error when searching an array from another class' method... [message #1059871] Wed, 22 May 2013 04:21 Go to next message
Joseph Gill is currently offline Joseph GillFriend
Messages: 1
Registered: May 2013
Junior Member
So, I'm trying to search a String[][] named SearchableArray in a given column col. This array has a specified number of rows numRows. The program makes it to the println which reads "I'm in here", but the next line is what gives me all the errors.

The statement SearchableArray[row][col].contains(searchString) represents a boolean, thus it should work perfectly with the surrounding code.

The snippet from CLASS 2 is calling the code shown from CLASS 1 with the last line of code shown. Maybe this boils down to some lack of experience I have with passing things from a method in one class to another method in another class. Any advice is WELCOME!



CLASS 1 (Class FindMe):

public void searchArray(String searchString, int col, int numRows) {

System.out.println("made it to findMe");
FoundRowIndexes = new int[numRows];

j = 0;
System.out.println("numRows = " + numRows);
for(int row = 0; row<numRows; row++) {
System.out.println("I'm in here.");
if(SearchableArray[row][col].contains(searchString)) {
System.out.println("I'm in here too.");
FoundRowIndexes[j] = row;
System.out.println("Found " + searchString + " at row index " + row + " and column index "+ col + ".");
j++;
}
else {
System.out.println("nope");
}
}
}



CLASS 2:

search(searchString, colIndex)

public void search(String searchString, int colIndex) {
findMe FindMe = new findMe();
FindMe.searchArray(searchString, colIndex, numRows);
}



ERROR LOG:

made it to findMe
numRows = 3
I'm in here.
Exception in thread "main" java.lang.NullPointerException
at hey.RecordBook.findMe.searchArray(findMe.java:338)
at hey.RecordBook.searchMe.search(searchMe.java:118)
at hey.RecordBook.searchMe$2.widgetSelected(searchMe.java:92)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:248)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4136)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1458)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1481)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1466)
at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:1271)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3982)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3621)
at hey.RecordBook.boss.main(boss.java:28)
2013-05-21 23:47:03.830 java[7210:903] *** __NSAutoreleaseNoPool(): Object 0x100167190 of class __NSCFDate autoreleased with no pool in place - just leaking
2013-05-21 23:47:03.833 java[7210:903] *** __NSAutoreleaseNoPool(): Object 0x10015a3e0 of class NSCFTimer autoreleased with no pool in place - just leaking



Again, any advice is WELCOME!


Thanks,

Joseph Gill
Re: Error when searching an array from another class' method... [message #1059998 is a reply to message #1059871] Wed, 22 May 2013 13:44 Go to previous message
David Wegener is currently offline David WegenerFriend
Messages: 1445
Registered: July 2009
Senior Member
First, this forum is for question related to using the Eclipse Java Development Tools. It isn't a general Java programming forum. You need to ask general Java questions on stack overflow or similar forum.

You haven't given enough context to answer your question. You don't show where SearchableArray is defined so anyone looking to help is left to guess what it is. You also don't show if this variable is initialized any place. My guess would be that this is an initialization problem. Java arrays aren't automatically initialized, you have to add all elements. If you don't initialize an array, you will get NullPointer exceptions.

Previous Topic:I want my perspective button bar back
Next Topic:IJavaProject without Eclipse Environment
Goto Forum:
  


Current Time: Thu Apr 18 07:52:23 GMT 2024

Powered by FUDForum. Page generated in 0.01916 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top