2016-03-10 81 views
0

我目前正在創建一個程序,以接受用戶註冊並允許他們通過Corba「購買」一本電子書。 我得到的主要錯誤是這樣的:IDL抽象方法錯誤

BookServant is not abstract and does not override abstract method storeUserDetails(UserDetails) in distBkOperations 

的ebook.idl目前看起來如下:

module BookAny { 

struct UserDetails { 
    string name; 
    string password; 
}; 

struct BookDetails { 
    string bookID; 
    string title; 
    string price; 
}; 


interface distBk { 
void storeUserDetails(in UserDetails myUserDetails); 
any getUserDetails(in string name, out any myUserDetails); 

void storeBookDetails(in BookDetails myBookDetails); 
any getBookDetails(in string title, out any myBookDetails); 
}; }; 

BookServant.java如下所示:

import java.io.*; 
import java.util.*; 
import BookAny.*; 
import org.omg.CORBA.*; 

public class BookServant implements distBkOperations{ 
    public static Hashtable hashtable; 
    public static ORB orb; 

public BookServant (org.omg.CORBA.ORB orb){ 
     hashtable = new Hashtable(); 
     this.orb=orb; 
} 

public void storeUserDetails (BookAny.UserDetails myUserDetails, AnyHolder password){ 

    Any pass = orb.create_any(); 

    myUserDetails.password="safepasswordlol"; 

    pass.insert_string(myUserDetails.password); 

    password.value = pass; 


    hashtable.put(myUserDetails.name, myUserDetails); 
    System.out.println(myUserDetails.name + " You have registered and your password is " +myUserDetails.password+myUserDetails.name); 

} 

public Any getUserDetails (String name, AnyHolder myUserDetails){ 

Any anyAB = orb.create_any(); 
try { 
    UserDetails tempAddrBook = (UserDetails)hashtable.get(name); 

    UserDetailsHelper.insert(anyAB, tempAddrBook); 
    myUserDetails.value = anyAB; 
}catch (Exception e) { 
    System.err.println("Error E: "+e); 
    e.printStackTrace(System.out); 
    } 
} 


/* public void getUserDetails (String name, org.omg.CORBA.AnyHolder myUserDetails){ 

Any anyAB = orb.create_any(); 
try { 
    UserDetails tempAddrBook = (UserDetails)hashtable.get(name); 

    UserDetailsHelper.insert(anyAB, tempAddrBook); 
    myUserDetails.value = anyAB; 
}catch (Exception e) { 
    System.err.println("Error E: "+e); 
    e.printStackTrace(System.out); 
    } 
}*/ 
} 

我可以從IDL正確生成文件,但實際上試圖編譯BookServant或BookServer.java時出現上述錯誤。我曾嘗試將idl接口從void更改爲any,但仍然沒有任何結果。任何幫助,將不勝感激!

回答

0

由於錯誤指示,你的IDL文件只有在任何storeUserDetails操作的一個參數,即在Java代碼中刪除第二個參數

@Override 
public void storeUserDetails(BookAny.UserDetails myUserDetails) { 
+0

試過了,我仍然得到同樣的錯誤消息,還有其他建議嗎? – Kaneo71

+0

您仍然需要實現'storeUserDetails'的重載版本,即具有'BookDetails'參數的版本 – Reimeus

相關問題