Android Question Why can't I set table column width? [SOLVED]

Tim Chapman

Active Member
Licensed User
Longtime User
If I uncomment line 19 (Line 45 in Main in my actual code), I get a error:
java.lang.RuntimeException: Object should first be initialized (View).

I have spent hours trying to figure out what the problem is.
It works in the code in the Table.zip file: https://www.b4x.com/android/forum/t...supports-tables-of-any-size.19254/#post110901

Project is attached.
Please help!
And Thank You In Advance!

B4A Snippet:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    Type Todo(ID As Short, Name As String, Status As Byte, Context As Byte, Category As Byte, Priority As Int, Note As String)
    Dim table1 As Table
    Dim Statuses(12,2) As String
    Dim Categories(40,2) As String
    Dim TodoList As List
    Dim HeaderRow(7) As String
    Dim Categories(40,2) As String
    Dim n As Notification = CreateNotification("Tap to Proceed.")
End Sub

Sub Activity_Create(FirstTime As Boolean)
    If table1.IsInitialized Then
        Activity.RemoveAllViews 'remove the current table
    End If
    table1.Initialize(Me, "Table1", 4) 'The last value here sets the number of columns in the table that shows on the screen.
    table1.AddToActivity(Activity, 0, 0, 100%x, 100%y)
    'table1.SetColumnsWidths(Array As Int(100dip, 30dip, 130dip, 100%x - 260dip))
   
    myMap.Initialize
    'Activity.AddMenuItem("Load Table", "LoadTable")
    'Activity.AddMenuItem("Save Table", "SaveTable")
    Activity.AddMenuItem("Allow Context Notification", "AllowContextNotification")
    Activity.AddMenuItem("Clear Context Notification", "ClearContextNotification")
    Activity.AddMenuItem("Exit Program", "ExitProgram")
   
    LoadArrays(File.DirAssets, "Todo List.xls")
    Notifier
End Sub
 

Attachments

  • TimTodo Works.zip
    189.5 KB · Views: 122
Last edited:
Solution
In the Table class, you must fill the table before calling Table1.SetColumnsWidths.
This is the case in the code of Table.zip.
You should move this line at the end of the LoadTable routine after having filled the Table.
B4X:
        For j = 1 To TempContextLength

            If Context = TempContext(j) Then
                'Log("...")
                'Log("Context = " & Context)
                'Log("TempContext("&j&" = "& TempContext(j))
                TableRow = TableRow + 1
                table1.AddRow(Values)
            End If
        Next
    Next
    table1.SetColumnsWidths(Array As Int(100dip, 30dip, 130dip, 100%x - 260dip))

As I already told you in another thread, the Table class you use is a very old one.
It does scroll...

Cableguy

Expert
Licensed User
Longtime User
But I don't see any reason why the code for for an older implementation of a table should not still work properly.
I do understand what you are saying, and I agree that "simply" replacing the "old" table by a new(er) different view... Maybe the old view is buggy, maybe the implementation of the newer view is cumbersome...
Anyway, in B4A at least the older table view is based in its java equivalent, so I guess that at least, using reflection, the collumnwidth method should be accessible
 
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
I just hear a BEEP.
How to load the table data?
 
Upvote 0

Tim Chapman

Active Member
Licensed User
Longtime User
Open the spreadsheet in the files folder.
Go to the contexts sheet.
Put in your current latitude and longitude in the first one (Anne's Heated Garage) replacing the current lat and lon there.
Save that spreadsheet in the files folder.
Run the program.
When it beeps, a notification will come up. Tap on it and select Anne's Heated Garage.
Then a table will be made that will show the todo items for that location.

It is odd if you are getting a beep without doing this because it should only beep if you are near one of the specified locations. But let's overlook that for the moment.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
In the Table class, you must fill the table before calling Table1.SetColumnsWidths.
This is the case in the code of Table.zip.
You should move this line at the end of the LoadTable routine after having filled the Table.
B4X:
        For j = 1 To TempContextLength

            If Context = TempContext(j) Then
                'Log("...")
                'Log("Context = " & Context)
                'Log("TempContext("&j&" = "& TempContext(j))
                TableRow = TableRow + 1
                table1.AddRow(Values)
            End If
        Next
    Next
    table1.SetColumnsWidths(Array As Int(100dip, 30dip, 130dip, 100%x - 260dip))

As I already told you in another thread, the Table class you use is a very old one.
It does scroll only vertically.
The more recent Table class, even an old one, i suggested you calculates automatically the column widths according to their content and scrolls in both directions.
 
Upvote 0
Solution

Tim Chapman

Active Member
Licensed User
Longtime User
Awesome! Thank you all so much for the help! That fixed it.
I only need the vertical scroll for this project.
Where should I have looked to find that the set column width can only be called after the table is populated?
I never saw that.
 
Upvote 0

BlueVision

Active Member
Licensed User
Longtime User
Where should I have looked to find that the set column width can only be called after the table is populated?
I can well understand Tim's frustration, as well as his joy when it works.
This thread is an example of a general problem with the B4....-environments. Unfortunately, I don't have a patent remedy for this either. A kind of Wikipedia would be ideal. How grateful I was at the beginning for the documents from Klaus, which familiarised me step by step with the programming of B4A.
The problem is simply the complexity of the whole thing and even if someone like Klaus goes to a lot of trouble and invests an incredible amount of time, you often have to search your fingers to the bone for a very specific problem. Then there is the problem with the native language. You can certainly find almost everything in the forum. However, it is often so specialised that you will never find the post with the answer based on the search arguments entered and then often only be pointed out by other users.
The forum lacks a reference work that needs to be constantly updated and that quickly leads a user to solutions and also describes the "Does & Dont's", additionally all the little things such as the properties of an object, the syntax or the general approach.
It will be particularly bad with Android, because the ongoing updates by Google mean that what is currently absolutely correct will no longer apply tomorrow. The code inevitably becomes obsolete and is very difficult to keep running in the long term (DoEvents, Sleep(0) is a good example of this). So today it is the solution of a genius, tomorrow it's a code smell.
Libraries are updated and improved. Old versions may no longer work with higher SDK levels. And complete concepts are thrown overboard (control of storage media, access to essential resources (download folder)).
Yes, there are many publications to read (and again Klaus comes to mind) and there are also the wonderful video tutorials by Erel. But there is still a wide range of unaddressed topics, which makes it very difficult for newcomers and users who have not been actively involved for a long time.

Anywhere Software's products are very good, but due to their complexity, there is simply no common thread and it is very easy to get lost in the jungle. That's the problem. I have in mind that these products are unfortunately hardly known and don't even appear in the top 100 of programming environments or other rankings, so unfortunately they may not reach the people who are looking for exactly this type of software.

How can we get rid of this or am I totally wrong?
 
Upvote 0

MaaMoz

Member
Licensed User
Longtime User
I just realized one thing. To me the cardinal rule of programming language development is to make sure that you maintain backwards compatibility as the language progresses. B4A has not done this. I never thought to look for this problem because the programming languages I use have done this. QB64 replaced QuickBASIC and has excellent backwards compatibility with the original language. I would much rather see effort put in to making sure the older parts of B4A still work than adding new more complicated features to do the same job. If I were not being forced to use the newer more complicated parts of B4A I would be perfectly happy using the parts I have selected because they get the job done nicely. The new B4Xtable won't even scroll. To me that is unacceptable on a touch screen. The latest and greatest is not necessarily the best especially when it adds more complexity.
Welcome to reality... welcome to a complicated World...

A BIG thank you to B4A and the Forum for their kind help!

I started programming some 36 years back.
Things have never been easy.
Over the years I have learned and used several different languages. None was always fully backwards compatible. This is impossible.

Example: I have been programming with Microsoft Visual Studio for over 30 years now.
I am still using VS 2019. I tried and would love to update to VS 2022. But at least one of my programs will not work with (so far) no work around.
In any programming language, you will run into the problems you describe.

Tim, your frustration is understandable. But you might need to face reality:
In an ever changing World and ever new players and bright minds starting to play, there will always be frustrating changes.

A BIG THANK YOU to B4A and the B4A Forum and, specially, to Erel !!

I had tried several IDEs for mobile environments and found B4A to be the easiest.
I hate many of the changes GOOGLE makes to Android. But, it is their environment.
We have, Erel has, to play by their rules.
If not, we would have to start programming in "zeros / ones" ... will we be able to?

99% of the code running our computers and devices is done by champions... our programs are just 1% running on the 99%.
More than 40 years ago a friend of mine programming in Assembly (ASM or asm) sadly grew sick and finally died because of the incredible load of programming the 99%.
Glad we have IDEs doing the 99% of the work.

Again, thank you for B4A.
You have made my frustrating programming World a better place.

Thank you to Erel for his friendly, smart, compassionate personal help he often provides.
Thank you to the many friendly Community friends, Klaus and DonManfred being two of them, who, despite of sometimes "silly" questions, are so often ready to take their time to help.

I would choose B4A again.

Greetings from a "nobody" in a world of programming champions who do the 99% of the work for OUR programs to run.
 
Upvote 0

Tim Chapman

Active Member
Licensed User
Longtime User
Trust me when I say that I face reality every day. I love B4A even with its difficulties because it allows me to get real work done.
The reality that I face is that I have a ton of work to do (like everyone else).
Therefore, I try to use the simplest methods with the least learning curve to get the jobs done.
When I finish my current project, I will be making an inventory control system for my manufacturing company.
The current project serves two purposes - to be a refresher on B4A and to give me todo list functionality that I can't find anywhere else.
I am pragmatic to a fault so my approach to programming is to take the shortest distance two points in order to get more work done.
Considering my lack of programming background, I am very pleased with my results.
I don't doubt that everything you say about programming is true, but I have enough learning curves that I avoid new ones where possible.
 
Upvote 0
Top