I'm writing an app that gets info and a picture from the user and saves the info into separate text files and moves the selected picture from the gallery to a folder on the SD card. However my app keeps crashing.
I use this code
And I use this to get the pictures file path and display a preview/thumbnail for the user...
Now everything seems to save fine but when it takes me back to the page where I have my spinner and I run ListSpinner_ItemClick on the new item or any item then my app force closes. But if I restart or click through them before I add a new entry they all display fine with the info filling the text box and image being displayed as well. It seems when I add a new entry and then try to select it/view or any other entry in the spinner list it crashes.
The code that crashes is in a different activity than the main. (Not sure if that matters). but Ill list that code too..
I'm thinking it has something to do with the images but I have no clue what to fix. Any help would be much appreciated! Thanks!
I use this code
B4X:
Sub SaveButt_Click
Dim IndexNumber As Int
AddPanel.Visible = False
ListSpinner.Clear
List.Add(Username.Text)
IndexNumber = List.Size
File.WriteList(File.DirInternal, "TheList.txt",List)
'Writes Files
File.WriteString(File.DirInternal, "1.txt", Username.text)
File.WriteString(File.DirInternal, "2.txt", Number.text)
File.WriteString(File.DirInternal, "3.txt", email.text)
File.WriteString(File.DirInternal, "4.txt", Birthday.text)
File.WriteString(File.DirInternal, "5.txt", Bio.text)
Dim objOut As OutputStream
objOut = File.OpenOutput("/mnt/sdcard/Images/", UserName.Text & ".jpg",False)
bmp.WriteToStream(objOut,50,"JPEG")
objOut.Close
HomePanel.BringToFront
AddPanel.SendToBack
AddPanel.RemoveAllViews
Dim i As Int
List = File.ReadList(File.DirInternal, "TheList.txt")
For i = 0 To List.Size - 1
ListSpinner.Add(List.Get(i))
Next
ToastMessageShow("Saved", True)
End Sub
And I use this to get the pictures file path and display a preview/thumbnail for the user...
B4X:
Sub chooser_Result (Success As Boolean, Dir As String, FileName As String)
If Success Then
AddImageBox.Enabled = True
bmp.Initialize(Dir, FileName)
FName = FileName
FDir = Dir
AddImageBox.Bitmap = bmp
ClickImageLabel.Visible = False
Else
ToastMessageShow("No image selected", True)
End If
End Sub
Now everything seems to save fine but when it takes me back to the page where I have my spinner and I run ListSpinner_ItemClick on the new item or any item then my app force closes. But if I restart or click through them before I add a new entry they all display fine with the info filling the text box and image being displayed as well. It seems when I add a new entry and then try to select it/view or any other entry in the spinner list it crashes.
The code that crashes is in a different activity than the main. (Not sure if that matters). but Ill list that code too..
B4X:
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("ShowCase")
UsernameDisplayText.text = Main.UsernameDisplayTextGlobal
'Reads text file data
ShowCaseImage.Bitmap = LoadBitmapSample("/mnt/sdcard/Images/",UsernameDisplayText.text & ".jpg", ShowCaseImage.Width, ShowCaseImage.Height)
NumberDisplayText.text = File.ReadString(File.DirInternal,"2.txt")
EmailDisplayText.text = File.ReadString(File.DirInternal, "3.txt")
BirthdayDisplayText.text = File.ReadString(File.DirInternal, "4.txt")
BioDisplayText.text = File.ReadString(File.DirInternal, "5.txt")
Dim ht As Float
ht = StrUtil.MeasureMultilineTextHeight(NotesDisplayText, NotesDisplayText.text) ' measure Label height
ScrollView1.Panel.Height = ht + 100 ' set the ScrollView internal Panel height to the measured height
BioDisplayText.Height = ht ' set the Label height to the measured height
ScrollView1.FullScroll(True)
BioDisplayText.RemoveView
ScrollView1.Panel.AddView(BioDisplayText, 0, 0 ,100%x, 100%y)
End Sub
I'm thinking it has something to do with the images but I have no clue what to fix. Any help would be much appreciated! Thanks!