Error from Companion: Attempt to invoke virtual method 'java.lang.Class java.lang.Object.getClass()' on a null object reference

As I was making my app, I tested it on my phone. It said, "Error from Companion: Attempt to invoke virtual method 'java.lang.Class java.lang.Object.getClass()' on a null object reference" and my phone screen was blank.
Can anyone help please?


We probably need to see your Blocks - but one question: Are you using any extensions? If so, they might need updating to be compatible with the latest version of AI2.

No, I have just (designed) 1 screen and wrote code on it. My other two screens are totally fresh; I didn't do any designing or coding on them. I even tried disabling the blocks (all of them!) But that didn't solve the issue :disappointed:. And that's not even my first app, but I am facing the problem the first time.
Talking about this particular app, even when I was designing it, I tested it on Ai2 companion. That worked well. As soon as I began coding, this issue started.

Actually I am building a motivational app. I want it to display a random quote each time someone opens it. After I coded that, this error happened.
a snap of my blocks, in case you need them-

Actually the blocks are too wide to fit into 1 screen shot, so I had to upload two.

Nothing wrong with the blocks you have shown.

Check you blocks editor for any other stray blocks ?

Restart AI2 and companion and try again ?

I've already done it. I restarted website two times, but it's not happening.

Actually. I think the issue is in the fact that you named a component quote. Try changing the name to something else, like quoteLabel and see if you still encounter errors.

1 Like

Ya-ya it's ... it's working! My application is working!
Thanks a lot for your kind and polite help all!
That "quote" was the name of a textView.
And could anyone tell me why is it so? I changed the name to "Text1" and it became okay. How?
Does it mean that component names can start only with capital letters or what is it?

Maybe it can be because I've heard that app inventor is based on Java language, and each component has its dedicated class. A class name can only start with a capital letter, hence it is so. Is it the reason?

App Inventor is built on a number of technologies. One is Java and another is Scheme. The issue here is with the Scheme portion. quote is a special syntax in Scheme, but by creating a component quote you override the existing semantics because now it's been defined to mean something else (i.e., your label). Given that quote is used quite frequently in Scheme this causes some spectacular failures, as you've seen. It's generally safer to start all your component names with a capital letter, but not strictly necessary. We'll see about adding this to the reserved word list so that it isn't an issue in the future.

1 Like

Okay, thanks a lot!
May AppInventor thrive for millennia!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.