NullPointerException: Cannot invoke "com.intellij.openapi.project.Project.getService(java.lang.Class)" because "project" is null
I have a plugin which uses jcef browser to display results in which I have a service level class defines as @Service(Service.Level.PROJECT) and there
i have a field as private final Project project;
I am using the below code for get the access of above project from another class
DataContext dataContext = DataManager.getInstance().getDataContext();
Project project = dataContext.getData(CommonDataKeys.PROJECT);
//some method
FileEditor fileEditor = FileEditorManager.getInstance(project).getSelectedEditor();
Until android studio giraffe it was working fine, but my plugin has stopped working in hedgehog
if i open any project in project/packages format instead of android format. It is working fine if i open my project in android.
I am getting error as project is null;
2024-01-03 09:46:48,500 [ 619260] INFO - STDERR - java.lang.NullPointerException: Cannot invoke "com.intellij.openapi.project.Project.getService(java.lang.Class)" because "project" is null
2024-01-03 09:46:48,500 [ 619260] INFO - STDERR - at com.intellij.openapi.fileEditor.FileEditorManager.getInstance(FileEditorManager.java:27)
Post is closed for comments.
After some more investigation, i found that reloading the project the issue is resolved but still many i times when i open the project this issue occurs
The ususal behaviour of my plugin in hedgehog is that when is send the request the response does not come as at that time the project is null but when i reload /restart the project, i start getting the reponses as now the the project is not null.(as in above code)
FileEditor fileEditor = FileEditorManager.getInstance(project).getSelectedEditor();
Is there any way is can know that project has been loaded or not?
Answered in Slack https://jetbrains-platform.slack.com/archives/C5U8BM1MK/p1704446579254099