Android Question List of Arrays or Array of Arrays

TheWind777

Active Member
Licensed User
Longtime User
I am trying to create, either, an two-dimensional string array, or a List of arrays.

I would like to load in 4 different sentences for 365 different days from a text file, then access them like:

Day(235,1) would equal the first sentence of the 235th day... Day(365, 3) would equal the 3rd sentence of the 365th day. (Day(365, 0) might equal the total number of sentences for that day... because maybe in the future they might be more than 4 sentences per day).

I have tried both methods.

I have tried declaring a list in the Global area, then populating it in a Sub.

I have tried declaring the list in the Global area and populating it in the global area.

I have tried declaring a two-dimensional array in the Global area and populating it in Sub.

I have even succeeded, if one were to count using Log(Day(365,3))

However, whenever I try an actually use that string or return it as a value, or even print it in a StringFunction message Box... it always gives me an error of java.lang.NullPointerException

I'm figuring that the problem has to do with the original definition being just a reference pointer to a string which isn't really there later.

What is the proper way of declaring (either a list which will be a list of string arrays) or a two-dimensional string array so I can fill them in either at the beginning and then access them later, or fill them in from a Sub later without getting that annoying "NullPointrException" error?

365 x 4 real strings need to be created, globally.

Then, in some fashion, either a List of Array pointers has to point to those strings.

And, after they have been declared... how does one access them?

When I was doing experiments using a list of arrays, I seemed to be setting-up the list of arrays properly... but I could then never access the arrays, and thus those string array items properly.

Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.

Dim ListOfArrays As List
Dim sf As StringFunctions
Dim TimingArray(5) As String
End Sub

Sub Activity_Create(FirstTime AsBoolean)

'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("main")


Dim z As Short
Dim sf As StringFunctions

ListOfArrays.Initialize ' (I've also tried putting this in the Globals area)

For z = 0 To 365

Dim TimingArray(5) As String

TimingArray(0) = "4"
TimingArray(1) = "A" & NumToStr(z)
TimingArray(2) = "B" & NumToStr(z)
TimingArray(3) = "This is a test of the emergency broadcast system" & NumToStr(z)
TimingArray(4) = "D" & NumToStr(z)
ListOfArrays.Add(TimingArray)
Next

' Creates a string pointer called GetArray?

Dim GetArray() AsString



' Points the GetArray string pointer to the 25th Array in the ListOfArrays List and accesses the 25th

GetArray = ListOfArrays.Get(25)
Log(GetArray(3)) ' And, it shows "This is a test of the emergency broadcast system25"

TheString = GetArray(3) ' Doesn't cause problem to assign it. Must be a string pointer.
sf.MB(TheString) 'Gives null pointer error any time I try actually using that value

End Sub


The same exact thing happened when I tried to create a two-dimensional array.

What's the right way of doing it?
 

TheWind777

Active Member
Licensed User
Longtime User
Every file in the File.DirAssets folder should be lower case. Change this line: If File.Exists(File.DirInternal,"Init.txt") so it say "init.txt" not "Init.txt". That should help. Make sure all your files in the files folder are all lower case names. Also, make sure your code that looks for any file in Assets is looking for lower case as well.

I found the latest DateUtil library (1.05) and that one wasn't corrupted. Thanks.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
B4X:
(Line: 1472) If File.Exists(File.DirInternal,"Init.txt") Then
java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Boolean

I have not read the whole thread, but I think this is your last issue, right?

This is really weird. It seems that the Exists function returns a double!

Try:
B4X:
Log ("FileExists =" & File.Exists (File.DirInternal, "init.txt"))

Then try to use:
B4X:
If File.Exists(File.DirInternal,"Init.txt") = -1 Then '  or 1 i don't know the value, see the log

Being an anomalous error, I would recommend you create a new project, create all the modules but empty and then fill them with copy and paste.
 
Last edited:
Upvote 0

TheWind777

Active Member
Licensed User
Longtime User
B4X:
(Line: 1472) If File.Exists(File.DirInternal,"Init.txt") Then
java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Boolean

I have not read the whole thread, but I think this is your last issue, right?

This is really weird. It seems that the Exists function returns a double!

Try:
B4X:
Log ("FileExists =" & File.Exists (File.DirInternal, "init.txt"))

Being an anomalous error, I would recommend you create a new project, create all the modules but empty and then fill them with copy and paste.

Yes; but it is returning a type Long only SOMETIMES. At other times it is working... and I can run it two times in two minutes and it will work one time, and not work another.

I thought that maybe, inside one of the subroutines, that the load of the map file was trying to load a Boolean, and it was seeing a long. There was a time where I was trying to write a Boolean to the init.txt file - but that was AGES ago. Since then I have deleted and rewritten the init.txt file enormous numbers of times. I've both deleted it with the function, and by hand from the android folder.

So, do you mean copy with a "Select All" all subroutines and paste them into a 'New' project's subroutine box?
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
The error in that single line is too strange, it should not regard the contents of the text file.

There seems to be a corrupt file (perhaps even in your B4A installation).

As proof, I advised you to recreate the project from scratch and do a SELECT ALL (CTRL + A) of all the code for each module and past (CTRL + V) in the respective new modules (same name).

It is an attempt tedious, I know, but ...!

(Sorry, English is not my native language :))
 
Upvote 0

TheWind777

Active Member
Licensed User
Longtime User
B4X:
(Line: 1472) If File.Exists(File.DirInternal,"Init.txt") Then
java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Boolean

I have not read the whole thread, but I think this is your last issue, right?

This is really weird. It seems that the Exists function returns a double!

Try:
B4X:
Log ("FileExists =" & File.Exists (File.DirInternal, "init.txt"))

Then try to use:
B4X:
If File.Exists(File.DirInternal,"Init.txt") = -1 Then '  or 1 i don't know the value, see the log

Being an anomalous error, I would recommend you create a new project, create all the modules but empty and then fill them with copy and paste.

Nope. Did the same thing. I tried renaming the init.txt file to acim.txt and that worked for the first try, then back to the same problem. Renamed it as acim2.txt this time. Deleted out all but lessons 1 and 2... so this is what it looks like with all modules. It uses no external libraries (yet).
 

Attachments

  • acim.zip
    301.9 KB · Views: 201
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
The file is not important, nor his name. If the command can not find the file or if the text file is corrupted, it should only return False.

I'm giving a look at your project, but I'll tell you in advance that I have an older version of B4A and lacking all the txt files.

But I try :)


WAAAit a moment: the IDE advise me that a lot of txt file are missing (they are 10.txt, 100.txt...), even your "Init.txt" is in the Files folder?
If so, you can not read them using File.DirInternal, because that folder (Files) corresponds to the File.DirAssets folder (and files contained in this folder are read-only)
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
At line 1472 i can see:
B4X:
File.WriteMap(File.DirInternal,"acim2.txt", TheMapFile)

not:
B4X:
If File.Exists(File.DirInternal,"Init.txt") Then

I searched that "If File.Exists (File.DirInternal, "init.txt") Then" and I have not found it in the Main module!

It may depend on the version of my B4A (?)
 
Upvote 0

TheWind777

Active Member
Licensed User
Longtime User
The error in that single line is too strange, it should not regard the contents of the text file.

There seems to be a corrupt file (perhaps even in your B4A installation).

As proof, I advised you to recreate the project from scratch and do a SELECT ALL (CTRL + A) of all the code for each module and past (CTRL + V) in the respective new modules (same name).

It is an attempt tedious, I know, but ...!

(Sorry, English is not my native language :))

There's only the one module. Copied and pasted... only included the minimum of files for chapter 1 of the ACIM and lessons 1 and 2. The timer is not only beginning, so it is not yet controlled by the options checkmarks; so just keep the message box up to shut it up.

If you can compile the project ten times in a row - you are doing better than I am. Mine only compiles about one time out of ten. I suspect that yours will compile it perfectly.

I have re-installed Basic4Android. I have re-installed Java SE 7 Development Kit. Android SDK has everything possible installed.

The thing that confuses me is the variable aspect of the problem. I don't understand why, only at times, there's a problem... and it compiles fine other times.

I am running Windows 7 64-bit on a very fast AMD FX(tm-4130 Quad-core at 3.80 GHz with 8 GB of RAM.

I have 32 bit Java installed.

The return of Long for Boolean also occurred with some functions from two different String libraries: StringFunctions and MLStr. Both exhibited the problem. It only occurs for certain functions and never with other functions.

Only other strange symptom is the AMD Manager isn't opening. When I go to the android folder and double-click SDK Manager.exe... it opens a window which immediately goes away. Version number of SDK is adt-bundle-windows-x86_64-20131030

Might it be that some variable isn't set properly for the SDK? It seems like, back when I was getting eclipse working properly, they said to set some environment variable. That was about a year ago... and I didn't set any environmental variables when I reinstalled it. Might it be some environmental variable setting for the SDK that's wrong?
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
I can not compile your project, unfortunately, because we have two incompatible versions of B4A.

The fact that the AVD manager does not work, indicates that the installation has some problems.

Have you tried to create a new simple project? With only a txt file to be read and use the File.Exists?

After this test, I, very calmly, would try reinstalling the SDK. After this and other tests done, reinstall B4A.

You have also verified "the paths of B4A", I guess.
 
Upvote 0

TheWind777

Active Member
Licensed User
Longtime User
The file is not important, nor his name. If the command can not find the file or if the text file is corrupted, it should only return False.

I'm giving a look at your project, but I'll tell you in advance that I have an older version of B4A and lacking all the txt files.

But I try :)


WAAAit a moment: the IDE advise me that a lot of txt file are missing (they are 10.txt, 100.txt...), even your "Init.txt" is in the Files folder?
If so, you can not read them using File.DirInternal, because that folder (Files) corresponds to the File.DirAssets folder (and files contained in this folder are read-only)

No, Init.txt is not in the Files folder of either the old project, or the new one.

init.txt is only created from the App. I have never copied it across from the Android (hard-to-find) DirInternal folder. I've only looked-at, or deleted the init.txt file.

Yes, there (were) tons of .txt files associated with the (old) project. I forgot to do a Clean Project after I pasted and copied and deleted.

I'm currently trying to re-install the Android SDK.

I know I'm supposed to install JRE 32 bit... but Android SDK 64 bit doesn't seem to like Java 32 bit.

I copied the jre folder over to the eclipse folder.

C:\Program Files (x86)\Java\jdk1.7.0_51\jre copied to C:\adt-bundle-windows-x86_64-20131030\eclipse

Ran eclipse. Got "Failed to load the INI shared library
"C:\adt-bundle-windows-x86_64-2131030\eclipse\jre\bin\clint\jvm.dll"

When I looked that error up on the internet I got this page:

http://stackoverflow.com/questions/7352493/failed-to-load-the-jni-shared-library-jdk

I uninstalled all other Java versions... so only have the 32 bit version (which Basic4Android said 64 didn't work). Does that mean I also need to install 32 bit SDK?

Does eclipse need to be working in-order that Basic4Android works?

What should my Environment Path look like?

I modified it to look like this:

C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files (x86)\QuickTime\QTSystem\;C:\adt-bundle-windows-x86_64-20131030\sdk\platform-tools;C:\Program Files\WIDCOMM\Bluetooth Software\;C:\Program Files\WIDCOMM\Bluetooth Software\syswow64;;C:\Program Files (x86)\B1 Free Archiver;C:\Program Files (x86)\Java\jdk1.7.0_51\bin\

I added C:\Program Files (x86)\Java\jdk1.7.0_51\bin\

I modified C:\adt-bundle-windows-x86_64-20131030\sdk\platform-tools (it used to point to C:\android\)

In the previous install I had renamed adt-bundle-windows-x86_64-20131030 to 'android'.

Still, when I double-click on C:\adt-bundle-windows-x86_64-20131030\SDK Manager.exe, a black DOSPrompt window opens, then closes, with no SDK Manager window showing.

I would suspect that it is the SDK, the environment variables, and the different 32 bit/64 bit versions of Java that are possibly causing the problem. I would guess that Basic4Android secretly uses Eclipse in some manner, then passes the Eclipse data to the Android? Just guessing. So, if Eclipse is not working perfectly, then Basic4Android won't?
 
Upvote 0

TheWind777

Active Member
Licensed User
Longtime User
The file is not important, nor his name. If the command can not find the file or if the text file is corrupted, it should only return False.

I'm giving a look at your project, but I'll tell you in advance that I have an older version of B4A and lacking all the txt files.

But I try :)


WAAAit a moment: the IDE advise me that a lot of txt file are missing (they are 10.txt, 100.txt...), even your "Init.txt" is in the Files folder?
If so, you can not read them using File.DirInternal, because that folder (Files) corresponds to the File.DirAssets folder (and files contained in this folder are read-only)

So, pointed the path in Tools->Configure Paths and pointed to the new adt-bundle-windows-x86 folder. Same problem.

I can not compile your project, unfortunately, because we have two incompatible versions of B4A.

The fact that the AVD manager does not work, indicates that the installation has some problems.

Have you tried to create a new simple project? With only a txt file to be read and use the File.Exists?

After this test, I, very calmly, would try reinstalling the SDK. After this and other tests done, reinstall B4A.

You have also verified "the paths of B4A", I guess.



Is jdk-7u51-windows-i586.exe the proper java installer to use? It is what s currently installed.
adt-bundle-windows-x86_64-20131030.zip is the SDK

It is the 64 bit SDK and the 32 bit Java.

Anybody else using 64 bit Windows 7?

The SDK is always problematic. They say to 'just run eclipse'. There IS no installer. You just unpack the zip file and put it somewhere. About the only thing they say is... don't use spaces. However there's a space in the path if you install java and it goes into the C:\Program Files (x86) folder.

Paths in B4a are:
Java C:\Program Files (x86)\Java\jdk1.7.0_51\bin\javac.exe
Android.jar C:\adt-bundle-windows-x86_64-20131030\sdk\platforms\android-19\android.jar

Additional Libraries is: C:\B2A\AddLibraries

My source code goes in C:\B2A in a separate folder for each project.
 
Upvote 0

TheWind777

Active Member
Licensed User
Longtime User
The file is not important, nor his name. If the command can not find the file or if the text file is corrupted, it should only return False.

I'm giving a look at your project, but I'll tell you in advance that I have an older version of B4A and lacking all the txt files.

But I try :)


WAAAit a moment: the IDE advise me that a lot of txt file are missing (they are 10.txt, 100.txt...), even your "Init.txt" is in the Files folder?
If so, you can not read them using File.DirInternal, because that folder (Files) corresponds to the File.DirAssets folder (and files contained in this folder are read-only)


Lets try that again. I copied the Files/ Deleted the ones that weren't supposed to be there. Cleaned the project. Took the code and converted to .txt file.

Take two...

By the way. The code also has a second options.txt file. That one has never had a problem, not even once. Always load and saves it properly. Same exact concept, same methods, same use of Exists function. Same folder.
 

Attachments

  • acim.zip
    213.5 KB · Views: 197
  • acimcode.txt
    53 KB · Views: 217
Upvote 0

TheWind777

Active Member
Licensed User
Longtime User
I can not compile your project, unfortunately, because we have two incompatible versions of B4A.

The fact that the AVD manager does not work, indicates that the installation has some problems.

Have you tried to create a new simple project? With only a txt file to be read and use the File.Exists?

After this test, I, very calmly, would try reinstalling the SDK. After this and other tests done, reinstall B4A.

You have also verified "the paths of B4A", I guess.


You should now be able to compile the project. Just create a new project. Copy and paste the code. Copy the files to the Files folder and add them. Quite simple program... doing nothing strange that I know of.
 
Upvote 0

TheWind777

Active Member
Licensed User
Longtime User
I can not compile your project, unfortunately, because we have two incompatible versions of B4A.

The fact that the AVD manager does not work, indicates that the installation has some problems.

Have you tried to create a new simple project? With only a txt file to be read and use the File.Exists?

After this test, I, very calmly, would try reinstalling the SDK. After this and other tests done, reinstall B4A.

You have also verified "the paths of B4A", I guess.



In case you're wondering why all my Subs return type Long for no good reason... I was trying to eliminate all Boolean returns just in-case that was causing the problem somewhere. When they returned type Boolean, I wanted to make sure it wasn't part of the problem. Removed all Boolean Returns and Boolean checks on all Subs.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
I have to carefully read everything you've written.

Anyway, I tell you my setup:

Windows 7 64-bit

The paths configured in B4A:
javac.exe = "C:\Program Files\ Java\jdk1.6.0_43\bin\javac.exe"
android.jar = C:\Users\lm\AppData\Local\Android\android-sdk\platforms\android-19\android.jar


Environment variable (system):
JAVA_HOME = C:\Program Files\Java\jdk1.7.0_07


I have no problems with Eclipse (although for now it is on standby, it already has a lot of dust ;))
 
Upvote 0

margret

Well-Known Member
Licensed User
Longtime User
I have run your project, created from the text file. The first issue is the Dim of TheMapFile should be in globals and removed from all other locations, which I did. The next issue in CreateOptionsFile was you had ResponseToTemptation when it should of been DoResponseToTemptation for the Key. Once these were changed and I created a new options.txt it compiled and ran fine. I compiled it 20-25 times. Then when I used it long enough for the Timer to tick, it killed the project and I can not recompile the project. So the new, cut copy and paste will have to be done again. The Timers are what seems to be killing the project. It is not your install of B4A, Java or the SDK. Mine crashed after the timer and required a reboot of the PC and the Android device before it would work again.

I could not even run any of my other project that I know are fine, it killed B4A. I really think Erel should look at this because B4A should not be able to be hung up this way. Even after a Clean Project and me deleting all the created files manually, it still will not run. A timer should not cause this kind of issue.

The Project is attached:
 

Attachments

  • ACIM.zip
    220.4 KB · Views: 202
Last edited:
Upvote 0

TheWind777

Active Member
Licensed User
Longtime User
I have run your project, created from the text file. The first issue is the Dim of TheMapFile should be in globals and removed from all other locations, which I did. The next issue in CreateOptionsFile was you had ResponseToTemptation when it should of been DoResponseToTemptation for the Key. Once these were changed and I created a new options.txt it compiled and ran fine. I compiled it 20-25 times. Then when I used it long enough for the Timer to tick, it killed the project and I can not recompile the project. So the new, cut copy and paste will have to be done again. The Timers are what seems to be killing the project. It is not your install of B4A, Java or the SDK. Mine crashed after the timer and required a reboot of the PC and the Android device before it would work again.

I could not even run any of my other project that I know are fine, it killed B4A. I really think Erel should look at this because B4A should not be able to be hung up this way. Even after a Clean Project and me deleting all the created files manually, it still will not run. A timer should not cause this kind of issue.

The Project is attached:


Well, I had that problem with the Boolean/long thing weeks before I started working on the timer. And, the timer addition is very small and simple. I'm doing nothing strange with the timer that I know of.

One thing about the timer is the Media play of the sound. I would figure that would be the problem rather than the timer.

...

Thanks for the heads-up about the DoResponse vs Response. However, that would be the options file, not the init.txt (now called acim2.txt), isn't it? file.

I'll also move the map file global. I have the 32GB Nexus7; so out-of-memory issues might be a problem with the two sound files (although they are small).
 
Upvote 0
Top