Java Question ba.activity problem

sareban

Member
Hi
I am wrapping this library

this library has these functions

Java:
    MaryPopup(Activity activity) {
        this.activity = activity;
        this.activityView = (ViewGroup) activity.findViewById(android.R.id.content);
        this.actionBarView = activityView.findViewById(R.id.action_bar_container);
    }

    public static MaryPopup with(Activity activity) {
        return new MaryPopup(activity);
    }

with this R.java Class
Java:
public class R {
    public static final class layout {
        public static int popup_layout_draggable = BA.applicationContext.getResources().getIdentifier("popup_layout_draggable", "layout", BA.packageName);
        public static int popup_layout = BA.applicationContext.getResources().getIdentifier("popup_layout", "layout", BA.packageName);
    }
    public static final class id {
        public static int action_bar_container = BA.applicationContext.getResources().getIdentifier("action_bar_container", "id", BA.packageName);
        public static int content = BA.applicationContext.getResources().getIdentifier("content", "id", BA.packageName);
    }
}


and i use this for initialize it in wrapper class:

Java:
    public void Initialize(BA ba) {
        _initialize(ba);
    }

    @Hide
    public void _initialize(BA ba) {

        this.ba = ba;
        marypopup = MaryPopup.with(ba.activity); 
        this.setObject(marypopup);
    }

when i compile library and run it in b4a

B4X:
Sub Button_Click
    Popup.Initialize
End Sub

error ...

*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
main_button_click (java line: 383)
java.lang.NullPointerException
at me.mava.marypopup.MaryPopupWrapper._initialize(MaryPopupWrapper.java:41)
at me.mava.marypopup.MaryPopupWrapper.Initialize(MaryPopupWrapper.java:34)
at b4a.example.main._button_click(main.java:383)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:196)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:180)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:176)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
at android.view.View.performClick(View.java:4438)
at android.view.View$PerformClick.run(View.java:18422)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5019)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)


please help me
 
Last edited:

walterf25

Expert
Licensed User
Longtime User
Hi
I am wrapping this library

this library has these functions

Java:
    MaryPopup(Activity activity) {
        this.activity = activity;
        this.activityView = (ViewGroup) activity.findViewById(android.R.id.content);
        this.actionBarView = activityView.findViewById(R.id.action_bar_container);
    }

    public static MaryPopup with(Activity activity) {
        return new MaryPopup(activity);
    }

with this R.java Class
Java:
public class R {
    public static final class layout {
        public static int popup_layout_draggable = BA.applicationContext.getResources().getIdentifier("popup_layout_draggable", "layout", BA.packageName);
        public static int popup_layout = BA.applicationContext.getResources().getIdentifier("popup_layout", "layout", BA.packageName);
    }
    public static final class id {
        public static int action_bar_container = BA.applicationContext.getResources().getIdentifier("action_bar_container", "id", BA.packageName);
        public static int content = BA.applicationContext.getResources().getIdentifier("content", "id", BA.packageName);
    }
}


and i use this for initialize it in wrapper class:

Java:
    public void Initialize(BA ba) {
        _initialize(ba);
    }

    @Hide
    public void _initialize(BA ba) {

        this.ba = ba;
        marypopup = MaryPopup.with(ba.activity);
        this.setObject(marypopup);
    }

when i compile library and run it in b4a

B4X:
Sub Button_Click
    Popup.Initialize
End Sub

error ...

*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
main_button_click (java line: 383)
java.lang.NullPointerException
at me.mava.marypopup.MaryPopupWrapper._initialize(MaryPopupWrapper.java:41)
at me.mava.marypopup.MaryPopupWrapper.Initialize(MaryPopupWrapper.java:34)
at b4a.example.main._button_click(main.java:383)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:196)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:180)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:176)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
at android.view.View.performClick(View.java:4438)
at android.view.View$PerformClick.run(View.java:18422)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5019)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)


please help me
I think you need to add the ActivityObject annotation to your library.

Walter
 
Top