我有一個服務接口,上面寫着這樣不能解析爲一個類型
package services;
import domain.Items;
public interface IItemsService extends IService {
public final String NAME = "IItemsService";
/** Places items into the database */
public void storeItem(Items items);
/** Retrieves items from the database
*
* @param category
* @param amount
* @param color
* @param type
* @return
* @throws ClassNotFoundException
*/
public Items getItems (String category, float amount, String color, String type) throws ItemNotFoundException, ClassNotFoundException;
}
而一個工廠,看起來像這樣...
package services;
public class Factory {
public Factory(){}
@SuppressWarnings("unchecked")
public IService getService(String name) throws ServiceLoadException {
try {
Class c = Class.forName(getImplName(serviceName));
return (IService)c.newInstance();
} catch (Exception e) {
throw new ServiceLoadException(serviceName + "not loaded");
}
}
private String getImplName (String name) throws Exception {
java.util.Properties props = new java.util.Properties();
java.io.FileInputStream fis = new java.io.FileInputStream("properties.txt");
props.load(fis);
fis.close();
return props.getProperty(serviceName);
}
}
這應該是很簡單 - 但我一直收到兩個錯誤 - IService無法解析爲類型(在工廠和服務上),而且serviceName也無法解析爲工廠中的變量錯誤。我知道我缺少一些簡單的...
那麼,你是否定義了IService?你沒有'顯示給我們。 – bmargulies