android - null exception when writing file to internal storage from separate class -
i have 2 activities want call time class bellow every time call class throws exception. if put timewrite()
method in activity works if put in time class , try call write file throws exception.
public class time extends alphabetactivity{ private int time; public void timewrite(int time) { try { string timeval = string.valueof(time); fileoutputstream timestream = openfileoutput("time_file.txt", context.mode_private); timestream.write(timeval.getbytes());} timestream.close(); catch (exception e) { e.printstacktrace();}}
it seems wrong inheritance , not understanding doing wrong.
try { string timeval = string.valueof(time); fileoutputstream timestream = openfileoutput("time_file.txt", context.mode_private); timestream.write(timeval.getbytes()); } timestream.close(); catch (exception e) { e.printstacktrace();} }
your code compile if write:
try { string timeval = string.valueof(time); fileoutputstream timestream = openfileoutput("time_file.txt", context.mode_private); timestream.write(timeval.getbytes()); timestream.close(); }catch (exception e) { e.printstacktrace(); }
if think sytanx wrong, code compile ? please read this, know, long have study or later: https://docs.oracle.com/javase/tutorial/essential/exceptions/
same http://www.tutorialspoint.com/java/java_exceptions.htm
if write file external storge, mind add read , write_external_storage permission manifest
Comments
Post a Comment