2015-12-03 84 views
-1

我有点混淆这段代码。它一直给我“Determ Null Pointer”的错误。Deferred空指针错误

bookStore.java

@Override 
protected store createOutlet (String storeName, String storeType) { 
    store theStore = null; 
     theStore.setStoreName(storeName); //getting Deferencing Null Pointer Error 
     theStore.setStoreType(storeType); 
    return theStore; 
} 

storeProducer.java

public abstract class storeProducer { 
protected abstract store createOutlet(String storeName, String storeType); 

public store createNewStore(String storeName, String storeType) { 
    store newStore = createOutlet(storeName, storeType); 
    newStore.createStore(); 

    return newStore; 
} 

store.java

public abstract class store extends Observable { 
abstract void createStore(); 

什么是问题?我已经尝试抛出异常,但仍然无法正常工作。

+1

你觉得'店theStore = NULL;'呢? –

+0

我是它的软件,但如果我删除它,我的变量“theStore”将显示未初始化。但如果我创建一个实例它显示商店的错误是抽象的,不能立即。 –

+0

你**必须拥有一个具体的'store'类型才能在运行时使用它。使用它。 –

回答

2

theStorenulltheStore.anything()将试图解引用空指针。

看来你想创造一个store例如,你可以做到这一点与new

store theStore = new AnyNonAbstractClassDerivingFromStore(); 
+0

它不允许我创建它作为store.java中的一个抽象 –

+0

哦,是的,你需要''new''store'的非抽象子类。 – emlai