ahmetb / orman

lightweight and minimalist ORM for Java/Android. works with SQLite & MySQL. (not actively maintained)
Other
249 stars 47 forks source link

java.lang.NullPointerException #41

Closed ragunathjawahar closed 12 years ago

ragunathjawahar commented 12 years ago
Uncaught handler: thread main exiting due to uncaught exception
java.lang.NullPointerException
    at org.orman.mapper.F.formatField(F.java:38)
    at org.orman.mapper.F.formatField(F.java:28)
    at org.orman.mapper.C.eq(C.java:18)
    at org.orman.mapper.EntityList.refreshList(EntityList.java:115)
    at org.orman.mapper.EntityList.lazyLoadIfNeeded(EntityList.java:77)
    at org.orman.mapper.EntityList.add(EntityList.java:128)
    at com.package.name.ClassName$2.onClick(ClassName.java:126)
    at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:158)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:123)
    at android.app.ActivityThread.main(ActivityThread.java:4363)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:521)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
    at dalvik.system.NativeStart.main(Native Method)

The latest nightly build from the downloads section and the source code has the same problem, I found that the fieldName contains the generatedFieldName instead of the fieldName which returns null for Field always. I've used a temporary workaround (F.java) which fixed this issue.

public static Field getField(Entity e, String fieldName) {
    for (Field f : e.getFields())
        if (f.getOriginalName().equals(fieldName) || 
                f.getGeneratedName().equals(fieldName))
        return f;
    return null;
}
ahmetb commented 12 years ago

Thanks for the workaround, I'll fix soon.