Android Question How to initialize view ?

akosije

Member
Licensed User
Longtime User
B4X:
Sub GetView(Row As Int, Col As Int) As Label
' Returns the label in the specific cell
    Dim l As Label
 l = Table.GetView(Row * NumberOfColumns + Col) 'Line 408
    Return l
End Sub

B4X:
Here's the error

Error occurred on line: 408 (main)
java.lang.RuntimeException: Object should first be initialized (View).
    at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:49)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:636)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:302)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:238)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:121)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:163)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:159)
    at anywheresoftware.b4a.objects.EditTextWrapper$2.onEditorAction(EditTextWrapper.java:107)
    at android.widget.TextView.doKeyDown(TextView.java:5461)
    at android.widget.TextView.onKeyDown(TextView.java:5343)
    at android.view.KeyEvent.dispatch(KeyEvent.java:2640)


    at android.view.View.dispatchKeyEvent(View.java:7670)
    at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408)
    at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408)
    at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408)
    at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408)
    at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408)
    at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchKeyEvent(PhoneWindow.java:2035)
    at com.android.internal.policy.impl.PhoneWindow.superDispatchKeyEvent(PhoneWindow.java:1505)
    at android.app.Activity.dispatchKeyEvent(Activity.java:2418)
    at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1962)
    at android.view.ViewRootImpl$ViewPostImeInputStage.processKeyEvent(ViewRootImpl.java:3852)
    at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3826)
    at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3399)
    at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3449)
    at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3418)
    at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3525)
    at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3426)
    at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3582)
    at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3399)
    at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3449)
    at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3418)
    at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3426)
    at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3399)
    at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3449)
    at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3418)
    at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3558)
    at android.view.ViewRootImpl$ImeInputStage.onFinishedInputEvent(ViewRootImpl.java:3718)
    at android.view.inputmethod.InputMethodManager$PendingEvent.run(InputMethodManager.java:2010)
    at android.view.inputmethod.InputMethodManager.invokeFinishedInputEventCallback(InputMethodManager.java:1704)
    at android.view.inputmethod.InputMethodManager.finishedInputEvent(InputMethodManager.java:1695)
    at android.view.inputmethod.InputMethodManager$ImeInputEventSender.onInputEventFinished(InputMethodManager.java:1987)
    at android.view.InputEventSender.dispatchInputEventFinished(InputEventSender.java:141)
    at android.os.MessageQueue.nativePollOnce(Native Method)
    at android.os.MessageQueue.next(MessageQueue.java:138)
    at android.os.Looper.loop(Looper.java:123)
    at android.app.ActivityThread.main(ActivityThread.java:5021)
    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:827)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:643)
    at dalvik.system.NativeS
Message longer than Log limit (4000). Message was truncated.

How can i initialize the Table ?
Table as Panel

Sorry im newbie
 

akosije

Member
Licensed User
Longtime User
Here's the full code sir.

Here's the number : 4800888113474

edtBarcode = Add ( Top Edittext )
MinusBarcode = Deduct/Remove ( Bottom Edittext )

This steps occurs the error:

1) insert this number in top edittext = 4800888113474 ( It will add a row )
2) insert this number in bottom edittext = 4800888113474 ( It will remove the row )
3) insert this number again in top edittext = 4800888113474 ( Error )

The error occurs when I Add and Remove and Add again using this 2 Edit Text.

Thank you in advance!!
 

Attachments

  • Project.zip
    13.7 KB · Views: 171
Upvote 0

KMatle

Expert
Licensed User
Longtime User
What I see (quick check):

You don't need to make another reference to the Scrollview.Panel with
B4X:
Table = scvList.Panel

You can directly add/remove views to

B4X:
scvList.Panel

In this sub the app is crashing

B4X:
Sub GetView(Row As Int, Col As Int) As Label
' Returns the label in the specific cell
    Dim l As Label
    l = Table.GetView(Row * NumberOfColumns + Col)
    Return l
     
End Sub

The reason is that the panel "Table" has no views on it (or less views than you expect) . So it will not get any reference (= not initialized).

Check (Row * NumberOfColumns + Col) against Table.NumberOfViews to prevent problems like that.

Log every add/remove of views and your indexes.
 
Upvote 0
Top