hive
hive copied to clipboard
Unhandled Exception: type 'Null' is not a subtype of type 'String' in type cast running from WINDOWS flutter
Steps to Reproduce Declare `@HiveType(typeId: 1) class Pings extends HiveObject { @HiveField(0) late String ip; @HiveField(1) late String mac; //mac @HiveField(2) late DateTime last_ping; @HiveField(3) bool connected=false; @HiveField(4) String user=" "; @HiveField(5) String pass=" "; @HiveField(6) String port=" ";
Pings({ required this.ip, required this.mac, //mac required this.last_ping, required this.connected, required this.user, required this.pass, required this.port });
@override String toString() { return 'Pings{ip: $ip, mac: $mac, name: $last_ping, connected:$connected, user: $user, pass:$pass, port:$port }'; } }`
Compile and works OK on flutter running on Android, but crash on start on flutter running on Windows with: "Unhandled Exception: type 'Null' is not a subtype of type 'String' in type cast running from WINDOWS flutter"
I think could be a database corrupted issue but can locate hive database path in Windows. Please provide path where hive stores databases in Windows?
Thanks and best regards
Code sample
Provide a few simple lines of code to show your problem.
Version
- Platform: iOS, Android, Mac, Windows, Linux, Web
- Flutter version: [e.g. 1.5.4]
- Hive version: [e.g. 0.5.0]
Steps to Reproduce Declare `@HiveType(typeId: 1) class Pings extends HiveObject { @HiveField(0) late String ip; @HiveField(1) late String mac; //mac @HiveField(2) late DateTime last_ping; @HiveField(3) bool connected=false; @HiveField(4) String user=" "; @HiveField(5) String pass=" "; @HiveField(6) String port=" ";
Pings({ required this.ip, required this.mac, //mac required this.last_ping, required this.connected, required this.user, required this.pass, required this.port });
@OverRide String toString() { return 'Pings{ip: $ip, mac: $mac, name: $last_ping, connected:$connected, user: $user, pass:$pass, port:$port }'; } }`
Compile and works OK on flutter running on Android, but crash on start on flutter running on Windows with: "Unhandled Exception: type 'Null' is not a subtype of type 'String' in type cast running from WINDOWS flutter"
I think could be a database corrupted issue but can locate hive database path in Windows. Please provide path where hive stores databases in Windows?
Thanks and best regards
Code sample
Provide a few simple lines of code to show your problem.Version
* Platform: iOS, Android, Mac, Windows, Linux, Web * Flutter version: [e.g. 1.5.4] * Hive version: [e.g. 0.5.0]
SOLVED:
Like I though, was database corrupted problem. Solved deleting database by "hand" allocated in: "C:\Users\Admin\Documents" where "Admin" is your username. Delete files with ".hive" extension.
Found path with the help of this code lines
var appDir = await getApplicationDocumentsDirectory(); print(appDir.path);
I have also this bug with the 2.2.3 version. It's solved by deleting the boxes (.hive and .lock) as suggested by @casterock
are there any other ways to solve it?
Bump!
Currently having the same problem (for Android, not Windows), even though it works after deleting the boxes, as soon as I add any other data, I'll get the same error. Must say that the value pointed to be null, can not be, in any possible way, a null value. It'll always be a String.
Not an emulator problem, as it has been tested on 2 different emulators and on a physical device (S21 Ultra, if it is someone's interest).
Values are immutable and always defined at the class constructor as well.
if you are using an emulator/device
- uninstall app from emulator or device
- run flutter clean
- run flutter pub get
- flutter run
Found path with the help of this code lines var appDir = await getApplicationDocumentsDirectory(); print(appDir.path);
Any solution for web?!