-3

I have a DrawerLayout, but when I add any view to the content_View.xml I get this error:

java.lang.NullPointerException: Attempt to invoke interface method 
'void android.support.v7.widget.DecorContentParent.
setWindowCallback(android.view.Window$Callback)' on a null object reference

Can anyone explain why is this error happening and how to fix it?

Johannes
  • 377
  • 1
  • 5
  • 16
amr
  • 1
  • 2
  • 2
    Possible duplicate of [What is a nullpointerexception and how do I fix it?](https://stackoverflow.com/q/218384/62576) Also, asking us to solve a problem with code you've not bothered to include is unreasonable. See [ask] and [mcve]. – Ken White May 11 '18 at 16:48

1 Answers1

0

You need to show us your code, but for now I can tell you that NullPointerExceptions occur when you have an uninstantiated object.

For example, let's say you have the variable MyClass myVar, and you want to call the function doSomething() on myVar, and it doesn't work. The reason why is that you need to make an instance of MyClass and assign it to myVar like this: myVar = new MyClass(args...).

This is called instantiating. Now, once you've instantiated myVar you can do myVar.doSomething(). Look at the following code:

MyClass myVar;           // Creates a MyClass object called myVar
myVar = new MyClass;     // Instantiates myVar
myVar.doSomething();     // Executes the function doSomething() on myVar
Johannes
  • 377
  • 1
  • 5
  • 16