App Crash on Restart with following exception Unhandled Exception: type 'Null' is not a subtype of type
Nobody has claimed this yet.
- Dominant language
- Dart
- Stars
- 4.4k
- Forks
- 449
- PR merge metrics
- No merged PRs in 30d
Description
I have followed the sample code properly. While the app is running it works fine. It saves and retrieves data. But when I restart the application it crashes with an exception.
**
if (!kIsWeb) {
Directory dir = await getApplicationDocumentsDirectory();
Hive.init(dir.path);
}
//await Hive.initFlutter();
Hive.registerAdapter(CompanyAdapter());
Hive.registerAdapter(MediaAdapter());
Hive.registerAdapter(KeyWordAdapter());
if (!Hive.isBoxOpen('storyBox')) {
await Hive.openBox<Map<String, dynamic>>(
'storyBox',
);
}
**
[VERBOSE-2:dart_vm_initializer.cc(41)] Unhandled Exception: type 'Null' is not a subtype of type 'Company'
#0 CompanyAdapter.read (package:presseportal/domain/news/story_adapter.dart:47:19)
#1 BinaryReaderImpl.read (package:hive/src/binary/binary_reader_impl.dart:328:33)
#2 BinaryReaderImpl.readMap (package:hive/src/binary/binary_reader_impl.dart:212:21)
#3 BinaryReaderImpl.read (package:hive/src/binary/binary_reader_impl.dart:319:16)
#4 BinaryReaderImpl.readFrame (package:hive/src/binary/binary_reader_impl.dart:276:26)
#5 FrameHelper.framesFromBytes (package:hive/src/binary/frame_helper.dart:21:32)
#6 FrameIoHelper.framesFromFile (package:hive/src/io/frame_io_helper.dart:42:12)
<asynchronous suspension>
#7 StorageBackendVm.initialize (package:hive/src/backend/vm/storage_backend_vm.dart:86:11)
<asynchronous suspension>
#8 HiveImpl._openBox (package:hive/src/hive_impl.dart:105:9)
<asynchronous suspension>
Version
- Platform: iOS, iPhone Pro Max Device and Simulator
- Flutter version: Flutter (Channel stable, 3.7.1, on macOS 13.2 22D49 darwin-arm64, locale en-DE)
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with story_adapter.dart at line 47, then trace how Hive.openBox<Map<String, dynamic>> reads persisted data through CompanyAdapter.read after an application restart. Reproduce on the listed iOS simulator or device using the supplied initialization and registration code; done means the stored box reopens without the reported Null/Company exception.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart, flutter
- Domain
- databases, mobile-dev
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100