Java Bufferedwriter Please help. Thanks

giga

Well-Known Member
Licensed User
Longtime User
I have a checkbox that a user selects to append text to a file and I keep getting this error

" java.lang.ClassCastException: java.io.BufferedWriter cannot be cast to android.content.Intent

This is the code I am using. When the user clicks the checkbox append the word test into a file.
:sign0104: Hope this code is right. Thanks as always for any help or guidance

Sub CheckBoxShowImage_CheckedChange(Checked As Boolean)

Dim cb As TextReader
cb.Initialize(File.OpenInput(DirName, FileName))
Dim ck As TextWriter
ck.Initialize(File.OpenOutput(DirName, FileName, False))
ck.WriteLine("test") ' writes test to file

myImageView.Initialize(myImageView)

If Checked = True Then
StartActivity(ck)
myImageView.Visible = True
Else
myImageView.Visible = False
End If
End Sub
 

warwound

Expert
Licensed User
Longtime User
ck is a TextWriter object and you're passing it to the StartActivity method - that's not valid and that's why you get the exception that a TextWriter can't be cast to an Intent.
(StartActivity is expecting an Intent or Activity to be passed to it).

B4X:
Dim ck As TextWriter
StartActivity(ck)

Martin.
 
Upvote 0

giga

Well-Known Member
Licensed User
Longtime User
ck is a TextWriter object and you're passing it to the StartActivity method - that's not valid and that's why you get the exception that a TextWriter can't be cast to an Intent.
(StartActivity is expecting an Intent or Activity to be passed to it).

B4X:
Dim ck As TextWriter
StartActivity(ck)

Martin.

Martin, Thanks for the reply, I must be lost on this one. I am new at this
I changed ck to Intent and still getting the error BufferedWriter


Is it possible to write text to a file when the Checkbox is true? Am I writing this code completely wrong. :confused:

Sub CheckBoxShowImage_CheckedChange(Checked As Boolean)

Dim cb As TextReader
cb.Initialize(File.OpenInput(DirName, FileName))
Dim ck As Intent
ck.Initialize(File.OpenOutput(DirName, FileName, False))
ck.WriteLine("test") ' writes test to file

myImageView.Initialize('myImageView')

If Checked = True Then
StartActivity(ck)
myImageView.Visible = True
Else
myImageView.Visible = False
End If
End Sub
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
I think you'll have to upload your project - use the File menu > Export as ZIP option.

Also what exactly do you want this Sub to do - do you want it to start a different activity?

Martin.
 
Upvote 0

giga

Well-Known Member
Licensed User
Longtime User
I think you'll have to upload your project - use the File menu > Export as ZIP option.

Also what exactly do you want this Sub to do - do you want it to start a different activity?

Martin.


:sign0188: Martin,

Ultimately, All I am trying to do is when the user places a Check in the Checkbox it writes text into a file.

I will try an upload my project later today.

Thanks.
 
Upvote 0
Top