Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Weird RMI Error: Incompatible types for storing into array of arrays or objects...

 
TNguyen
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can someone please help me with an RMI error? I am currently stompted because I am getting the following RMI error when I try to start my DBServer with these commands:

D:\SUN\Certification\JavaDevelopersExam\Assignment>rmic suncertify.db.DataServicesImpl
D:\SUN\Certification\JavaDevelopersExam\Assignment>java suncertify.db.DBServer
Exception in thread "main" java.lang.VerifyError: (class: suncertify/db/DataServicesImpl, method: searchFlights signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)[[Ljava/lang/String;) Incompatible types for storing into array of arrays or objects at suncertify.db.DBServer.main(DBServer.java:36)

I have a Remote interface with the following method:
public interface IDataServices extends Remote
{
...
public String[][] searchFlights(String userID,
String origAirport,
String destAirport)
throws RemoteException;
...
}

My DataServicesImpl remote object extends UnicastRemoteObject and implements the method in the Remote interface above. I bind this object in my DBServer code as follows:
public class DBServer
{
public static void main(String[] args) throws IOException, RemoteException
{
System.setSecurityManager( new RMISecurityManager() );
try
{
...
String URL = "rmi://" + serverDNSName + ":" + portNum + "/" + IDataServices.SERVERNAME;
IDataServices remoteObj = new DataServicesImpl();
Naming.rebind(URL, remoteObj);
...
}
catch (...) { ... }
}
}
Could someone please let me know what I am doing wrong here? Just for kicks, I tried changing the signature of my searchFlights() method to "public boolean searchFlights();" and successfully recompiled my code. But I got the exact same error when I re-ran my DBServer.
Thank you for all your help.
Timothy Nguyen

------------------
 
asad ali
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks like you are returning an array of array from searchFlights method. Please show the code where you are creating and populating the array of array in the method. It will help identify the problem.
 
TNguyen
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Asad,
Thank you for your help as I am totally stompt and I cannot move on without fixing this. Here is the code for the searchFlights() method:
public class DataServicesImpl extends UnicastRemoteObject implements IDataServices
{
...
...
public String[][] searchFlights(String userID, String origAirport, String destAirport) throws RemoteException
{
String[][] retRecords = null;
...
//Do the search.
DataInfo[] searchResults = myDataSource.criteriaFind( searchCriteria );

//Put the search results in the retRecords array.
int recsFound = 0;
for (int i=0;i<searchResults.length;i++)>
{
if ( searchResults[i] != null )
{
retRecords[recsFound] = searchResults[i].getValues();
recsFound++;
}
}
...
return retRecords;
}
...
...
}

public class DataInfo implements Serializable
{
private String [] values;
...
...
public String [] getValues()
{
return values;
}
...
...
}
Thanks.
Timothy Nguyen
 
asad ali
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are declaring two dimensional array of String which is referenced by retRecords. However, you are not defining the size of the array.
Your code is failing at the following statement :
retRecords[recsFound] = searchResults[i].getValues();
searchResults[i].getValues() returns an array of Strings but the size of your two dimensional array is not defined.
Hence you need to define the size like :
retRecords = new String[searchResults.length][searchResults[0].length];
before the 'for' loop.
 
TNguyen
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Asad,
Awesome, that fixed it. Completely a Java fundamental problem and nothing relating to RMI. However, pretty weird that RMI choked on it.
Thanks alot.
Timothy Nguyen
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic