0

I have an interface:

public interface ICustomObjectListingViews {
    View createCustomObjectListingView(MyDBObject myDBObject);
}  

Then :

public abstract class AbstractICustomObjectListingViews implements ICustomObjectListingViews {

@Override
    public View createCustomObjectListingView(MyDBObject myDBObject) {
        return null;
    }
}  

I then try to implement the interface by extending the abstract class :

public class MyCustomObjectListingView extends AbstractICustomObjectListingViews {

@Override
    public VIew createCustomObjectListingView(MyDBObject myDBObject) {
        Log.v("MyApp", ">>>> " + myDBObject.get_myObjectDescription());

        TextView textView = new TextView(mContext);
        textView.setText(myDBObject.get_myObjectDescription());

        return textView;
    }
}  

I use MyObject to map my database results:

public class MyDBObject {
    public MyDBObject() {
    }

    private String _myObjectDescription;

    public void set_myObjectDescription(String _myObjectDescription) {
        this._myObjectDescription = _myObjectDescription;
    }

    public String get_myObjectDescription() {
        return _myObjectDescription;
    }
} 

I, however, get a null pointer whenever I try to call MyCustomObjectListingView's implementation of createCustomObjectListingView(MyDBObject myDBObject).

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String MyDBObject.get_myObjectDescription()' on a null object reference  

at :

Log.v("MyApp", ">>>> " + myDBObject.get_myObjectDescription());  

This is how I call it:

MyDBObject myObject = new MyObject();
myObject.set_myObjectDescription("HELLO WORLD");

ICustomObjectListingViews iCustomObjectListingViews = new  MyCustomObjectListingView();
iCustomObjectListingViews.createCustomObjectListingView(myObject);  

What am I getting wrong? How should I call an overriding class' overriden method? How can I make the above attempt work?

Thank you all in advance.

motis10
  • 2,484
  • 1
  • 22
  • 46
Program-Me-Rev
  • 6,184
  • 18
  • 58
  • 142

1 Answers1

0

If you don't know how to implement createCustomObjectListingView(MyDBObject myDBObject) in AbstractICustomObjectListingViews , let implement it directly in the concrete class MyCustomObjectListingView (in this way you avoid the null return).

Erase the method from AbstractICustomObjectListingViews, so that it appears like that

   public abstract class AbstractICustomObjectListingViews implements ICustomObjectListingViews {
     //other methods
} 

and leave MyCustomObjectListingView as it is.

Jul10
  • 503
  • 7
  • 19