Runtime error: Attempt to invoke virtual method 'Java .lang.class java.lang.object.getclass()' on a null object reference

When running an app that has always worked, a runtime error appears (see screenshot). I can't figure out what it depends on. Can someone help me?

Are you using any extension? Probably some extension is causing the error.

Yes... I'm using 5 extensions... How do you know which one is involved?

Make a copy of the project, then try removing the extensions one by one and see when the error disappears. It may also be that you are not using one of the extensions correctly. E.g. you didn't initialize it.

When I work in .aia the error is not there. When I compile the project in apk the error appears.

Share your project here.

I don't know where the error occurs

the runtime error occurs not in project.aia but in project.apk

FOr debugging purposes, add a Label for debugging, and capture the response content into it for analysis here.

These blocks cause the error. That's all I managed to research. I tried to reproduce this error in the sample application, but to no avail. I haven't been able to find the reason why this cluster of blocks works in the companion but not in the apk.

Lists are fixed, not dynamically created. To me this is a very strange error. It is possible that combining this block with another component from the project causes a conflict. Maybe @ewpatton has some idea, knowing the error and the code of this block.

I also took a test. The blocks below also trigger this error when the button is clicked. But only in its project compiled into apk.

These also:

I tried a fresh project with a single Button and the event handler above and it did not crash on Android SDK 31. Is this happening on a specific Android version?

Yes, it's fine in the new project. The problem is only in the project provided by the author of this topic. I'm removing various things from the project one by one and checking when it will start working.

the project works in .aia but not in .apk....it's crazy. The only thing that is certain is that the error is caused by the block posted

android version 11

The error is caused by the fact that you named one of your text fields "min". Change the name of the text field and everything will be fine. Always use component naming with a prefix. For example, for label, use "lb_min" instead of "min". For TextBox you can use "tb_min" etc.

error_min

@ewpatton shouldn't this be caught at compile time?

1 Like

very good, congratulations now it works perfectly. If I understood correctly the term "min" must be a term (word) reserved in SCHEMA

Design time, not compile time, but yes. Scheme is a lexically scoped language so what happens is the component min shadows the global min function.

If not during compilation, why does it work with the companion and only not with the apk?

Because when the code is run in the companion the components are not part of the actual screen object but are instead stored in a Environment object on the Screen whereas the event handler code is run in the context of the Screen. When you compile the app, the YAIL generated code makes actual Java-level fields on the Screen object for each component. When the event handlers run, the lookup will find the field on the class before the function in the runtime.

(added to new section Runtime Errors in Built Apps in FAQ)