hive icon indicating copy to clipboard operation
hive copied to clipboard

Unhandled Exception: type 'Null' is not a subtype of type 'String' in type cast running from WINDOWS flutter

Open casterock opened this issue 3 years ago • 6 comments
trafficstars

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]

casterock avatar Jul 07 '22 22:07 casterock

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);

casterock avatar Jul 07 '22 22:07 casterock

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

Nicolab avatar Jul 29 '22 10:07 Nicolab

are there any other ways to solve it?

guvanch07 avatar Oct 06 '22 00:10 guvanch07

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.

WillianSalceda avatar Nov 06 '22 22:11 WillianSalceda

if you are using an emulator/device

  1. uninstall app from emulator or device
  2. run flutter clean
  3. run flutter pub get
  4. flutter run

leadpresence avatar May 09 '23 13:05 leadpresence

Found path with the help of this code lines var appDir = await getApplicationDocumentsDirectory(); print(appDir.path);

Any solution for web?!

AliEasy avatar Aug 07 '23 11:08 AliEasy