NullPointerException: null
NickRimmer opened this issue · 4 comments
NickRimmer commented
I got this
null
java.lang.NullPointerException
at pl.charmas.parcelablegenerator.util.PsiUtils.isOfType(PsiUtils.java:42)
at pl.charmas.parcelablegenerator.typeserializers.ParcelableSerializerFactory.getSerializer(ParcelableSerializerFactory.java:35)
at pl.charmas.parcelablegenerator.typeserializers.ChainSerializerFactory.getSerializer(ChainSerializerFactory.java:35)
at pl.charmas.parcelablegenerator.CodeGenerator.getSerializerForType(CodeGenerator.java:131)
at pl.charmas.parcelablegenerator.CodeGenerator.generateWriteToParcel(CodeGenerator.java:107)
at pl.charmas.parcelablegenerator.CodeGenerator.generate(CodeGenerator.java:146)
at pl.charmas.parcelablegenerator.ParcelableAction$1.run(ParcelableAction.java:50)
at com.intellij.openapi.command.WriteCommandAction$Simple.run(WriteCommandAction.java:166)
at com.intellij.openapi.application.RunResult.run(RunResult.java:35)
at com.intellij.openapi.command.WriteCommandAction$2$1.run(WriteCommandAction.java:114)
at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:1010)
at com.intellij.openapi.command.WriteCommandAction$2.run(WriteCommandAction.java:111)
at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:124)
at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:99)
at com.intellij.openapi.command.WriteCommandAction.performWriteCommandAction(WriteCommandAction.java:108)
at com.intellij.openapi.command.WriteCommandAction.execute(WriteCommandAction.java:80)
at pl.charmas.parcelablegenerator.ParcelableAction.generateParcelable(ParcelableAction.java:47)
at pl.charmas.parcelablegenerator.ParcelableAction.actionPerformed(ParcelableAction.java:42)
at com.intellij.ui.popup.PopupFactoryImpl$ActionPopupStep.performAction(PopupFactoryImpl.java:856)
at com.intellij.ui.popup.PopupFactoryImpl$ActionPopupStep$1.run(PopupFactoryImpl.java:842)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:756)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:726)
at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:866)
at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:654)
at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:381)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
when i try use plugin for my class
public abstract class SimpleAdapter<T> extends BaseAdapter implements Parcelable {
public List<T> items;
public Context context;
public SimpleAdapter(List<T> items, Context context) {
this.items = items;
this.context = context;
}
@Override
public int getCount() {
return items.size();
}
@Override
public Object getItem(int position) {
return items.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
public View generateView(int viewId, ViewGroup parent){
LayoutInflater inflater = LayoutInflater.from(context);
View view = inflater.inflate(viewId, parent, false);
return view;
}
}
Where I mistake?
NickRimmer commented
Plugin version is 0.6.2
DariusL commented
You shouldn't parcel a class like this. You should parcel models - objects that only contain data and a few basic operations. The exception probably comes from parcelling the context. Parcelling just the List<T>
should work fine.
NickRimmer commented
Probably need to say about this in more informative error message? (=
mcharmas commented
@NickRimmer the NPE is fixed but on the other hand you should not parcel these kind of classes.
@DariusL is completely right