Android Question LoadLayout in a Class produces "...has stopped" error

Uitenhage

Member
Licensed User
Longtime User
Informatix (or Agraham?),

I used Informatix's "Yes_it_works2" example from another thread (and Agraham's Reflection library) and it worked exactly as expected.
I tried to extend it to include LongClicks and got unexpected results . I cloned the SetOnClickListener line in the class Initialize Sub and changed it to SetOnLongClickListener. I cloned the Click subs in the class and in Main and changed all the Click references in the clones to LongClick. Now I expected the same behavior on a long click as a click. Click works as previously but long click produces a messagebox "Unfortunately, Layout change example has stopped".
Under Debug (legacy) this appears in the log:

Installing file.
PackageAdded: package:b4a.example
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
java.lang.NullPointerException
at android.view.View.showContextMenu(View.java:4545)
at android.view.View.performLongClick(View.java:4514)
at android.widget.TextView.performLongClick(TextView.java:9575)
at android.view.View$CheckForLongPress.run(View.java:18768)
at android.os.Handler.handleCallback(Handler.java:730)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5455)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
at dalvik.system.NativeStart.main(Native Method)

What have I missed?

Compiled both in Release and Debug (legacy) using B4A v3.20 and Reflection 2.40 on a Galaxy S3.

Thanks,

Jim
 

stevel05

Expert
Licensed User
Longtime User
Can you zip and post your amended project so we can see what you have changed.
 
Upvote 0

Uitenhage

Member
Licensed User
Longtime User
Erel,

Thanks for the response.

I think the attached app illustrates my problem a bit better.

I have a layout that was built in the Designer. I have an activity (main) and a class (MyPanel). The activity populates panels in the class by adding activity-defined views or designer-defined layouts. The views are defined in the activity so their event handlers are there too. I need the layout to also have it's dim's and event handlers in the activity. By switching the commenting of code in the activity and the same lines in the class you can see that the class has to know about the layout. I want the class to know as little as possible about the views and layouts loaded into it so that I can use it in different activities. The class will handle general functions like panel sizing and switching and coloring etc. that will be common to all instances of the class regardless of which activity hosts it.

I'd appreciate your thoughts,

Jim
 

Attachments

  • AnotherTest.zip
    9.3 KB · Views: 147
Upvote 0

Uitenhage

Member
Licensed User
Longtime User
Right in front of me all the time! As usual I was making it more complicated than it needed to be.

Thank you for the fantastic support.

Jim
 
Upvote 0
Top