Johan Schoeman Expert Licensed User Longtime User Mar 6, 2016 #1 I have an activity with a customview, 3 buttons, and a label. I have only just added the label via designer. In the library I raise an event.... Code: Sub zx1_brightness_changed (bright As Double) 'ADDED 6 MARCH 2016 Label1.Text = "" & bright If bright < 0.30 Then zx1.brightnessTurnFlashOn If bright > 0.35 Then zx1.brightnessTurnFlashOff End Sub ....but when the Event is raised I get this error: Code: ** Service (starter) Create ** ** Service (starter) Start ** ** Activity (main) Create, isFirst = true ** ** Activity (main) Resume ** main_zx1_brightness_changed (java line: 432) android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views. at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:6984) at android.view.ViewRootImpl.invalidateChildInParent(ViewRootImpl.java:1104) at android.view.ViewGroup.invalidateChild(ViewGroup.java:4542) at android.view.View.invalidate(View.java:11651) at android.view.View.invalidate(View.java:11605) at android.widget.TextView.checkForRelayout(TextView.java:8054) at android.widget.TextView.setText(TextView.java:4876) at android.widget.TextView.setText(TextView.java:4729) at android.widget.TextView.setText(TextView.java:4704) at anywheresoftware.b4a.objects.TextViewWrapper.setText(TextViewWrapper.java:43) at JHS.ZxingBarcodeScanner.main._zx1_brightness_changed(main.java:432) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169) at anywheresoftware.b4a.BA.raiseEvent2(BA.java:157) at zxingbarcodescannerwrapper.zxingBarcodeScannerWrapper$2.brightness_changed(zxingBarcodeScannerWrapper.java:188) at main.java.me.dm7.barcodescanner.zxing.ZXingScannerView.invokeBrightnessChanged(ZXingScannerView.java:241) at main.java.me.dm7.barcodescanner.zxing.ZXingScannerView.buildLuminanceSource(ZXingScannerView.java:186) at main.java.me.dm7.barcodescanner.zxing.ZXingScannerView.onPreviewFrame(ZXingScannerView.java:129) at android.hardware.Camera$EventHandler.handleMessage(Camera.java:1005) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:146) at android.os.HandlerThread.run(HandlerThread.java:61) ** Activity (main) Pause, UserClosed = true ** If I remove Label1.Text = "" & bright from the code then all is working...What am I missing here?
I have an activity with a customview, 3 buttons, and a label. I have only just added the label via designer. In the library I raise an event.... Code: Sub zx1_brightness_changed (bright As Double) 'ADDED 6 MARCH 2016 Label1.Text = "" & bright If bright < 0.30 Then zx1.brightnessTurnFlashOn If bright > 0.35 Then zx1.brightnessTurnFlashOff End Sub ....but when the Event is raised I get this error: Code: ** Service (starter) Create ** ** Service (starter) Start ** ** Activity (main) Create, isFirst = true ** ** Activity (main) Resume ** main_zx1_brightness_changed (java line: 432) android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views. at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:6984) at android.view.ViewRootImpl.invalidateChildInParent(ViewRootImpl.java:1104) at android.view.ViewGroup.invalidateChild(ViewGroup.java:4542) at android.view.View.invalidate(View.java:11651) at android.view.View.invalidate(View.java:11605) at android.widget.TextView.checkForRelayout(TextView.java:8054) at android.widget.TextView.setText(TextView.java:4876) at android.widget.TextView.setText(TextView.java:4729) at android.widget.TextView.setText(TextView.java:4704) at anywheresoftware.b4a.objects.TextViewWrapper.setText(TextViewWrapper.java:43) at JHS.ZxingBarcodeScanner.main._zx1_brightness_changed(main.java:432) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169) at anywheresoftware.b4a.BA.raiseEvent2(BA.java:157) at zxingbarcodescannerwrapper.zxingBarcodeScannerWrapper$2.brightness_changed(zxingBarcodeScannerWrapper.java:188) at main.java.me.dm7.barcodescanner.zxing.ZXingScannerView.invokeBrightnessChanged(ZXingScannerView.java:241) at main.java.me.dm7.barcodescanner.zxing.ZXingScannerView.buildLuminanceSource(ZXingScannerView.java:186) at main.java.me.dm7.barcodescanner.zxing.ZXingScannerView.onPreviewFrame(ZXingScannerView.java:129) at android.hardware.Camera$EventHandler.handleMessage(Camera.java:1005) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:146) at android.os.HandlerThread.run(HandlerThread.java:61) ** Activity (main) Pause, UserClosed = true ** If I remove Label1.Text = "" & bright from the code then all is working...What am I missing here?
Cableguy Expert Licensed User Longtime User Mar 6, 2016 #2 Are you sure the event on the custom view is not named the same as your calling event? From the logs I would say you have the same names for both the custom view managed event and for the "owner" module called event Upvote 0
Are you sure the event on the custom view is not named the same as your calling event? From the logs I would say you have the same names for both the custom view managed event and for the "owner" module called event
Johan Schoeman Expert Licensed User Longtime User Mar 6, 2016 #3 Cableguy said: Are you sure the event on the custom view is not named the same as your calling event? From the logs I would say you have the same names for both the custom view managed event and for the "owner" module called event Click to expand... The event name is set in the customview as zx1. All events are raised without a problem from within the library. All that I am trying to do is to display a returned value in the label by setting the text of the label. This does not make sense to me whatsoever... Upvote 0
Cableguy said: Are you sure the event on the custom view is not named the same as your calling event? From the logs I would say you have the same names for both the custom view managed event and for the "owner" module called event Click to expand... The event name is set in the customview as zx1. All events are raised without a problem from within the library. All that I am trying to do is to display a returned value in the label by setting the text of the label. This does not make sense to me whatsoever...
JordiCP Expert Licensed User Longtime User Mar 6, 2016 #4 Are you using raiseeventfromdifferentThread? Upvote 0
Johan Schoeman Expert Licensed User Longtime User Mar 6, 2016 #5 JordiCP said: Are you using raiseeventfromdifferentThread? Click to expand... No Jordi, using: Code: if (ba.subExists(eventName + "_brightness_changed")) { ba.raiseEvent2(ba, false, eventName + "_brightness_changed", true, new Object[]{cv.getBrightness()}); } Upvote 0
JordiCP said: Are you using raiseeventfromdifferentThread? Click to expand... No Jordi, using: Code: if (ba.subExists(eventName + "_brightness_changed")) { ba.raiseEvent2(ba, false, eventName + "_brightness_changed", true, new Object[]{cv.getBrightness()}); }
JordiCP Expert Licensed User Longtime User Mar 6, 2016 #6 Not totally sure since I haven't tried it, but raiseEvent/2 will fail if called from a different thread, or if your main Activity is paused Code: if (ba.subExists(eventName + "_brightness_changed")) { ba.raiseEventFromDifferentThread(this, null, 0, eventName + "_brightness_changed", true, new Object[]{cv.getBrightness()}); } Upvote 0
Not totally sure since I haven't tried it, but raiseEvent/2 will fail if called from a different thread, or if your main Activity is paused Code: if (ba.subExists(eventName + "_brightness_changed")) { ba.raiseEventFromDifferentThread(this, null, 0, eventName + "_brightness_changed", true, new Object[]{cv.getBrightness()}); }
Johan Schoeman Expert Licensed User Longtime User Mar 6, 2016 #7 JordiCP said: Are you using raiseeventfromdifferentThread? Click to expand... I am still confused about what happened but this solved it: Code: ba.raiseEventFromDifferentThread(getObject(), null, 0, eventName + "_brightness_changed", true, new Object[]{cv.getBrightness()}); Thanks Jordi Last edited: Mar 6, 2016 Upvote 0
JordiCP said: Are you using raiseeventfromdifferentThread? Click to expand... I am still confused about what happened but this solved it: Code: ba.raiseEventFromDifferentThread(getObject(), null, 0, eventName + "_brightness_changed", true, new Object[]{cv.getBrightness()}); Thanks Jordi