pinchbv / floor

The typesafe, reactive, and lightweight SQLite abstraction for your Flutter applications
https://pinchbv.github.io/floor/
Apache License 2.0
967 stars 191 forks source link

[floor_generator]- Null check operator used on a null value #516

Open saharvx9 opened 3 years ago

saharvx9 commented 3 years ago

Hi while i am generating new table or queries i'm getting this error:

=[SEVERE] floor_generator:floor_generator on lib/repository/rest_api.dart:

Null check operator used on a null value
#0      LinkedElementFactory.isLibraryUri (package:analyzer/src/summary2/linked_element_factory.dart:418:48)
#1      LibraryContext.isLibraryUri (package:analyzer/src/dart/analysis/library_context.dart:96:27)
#2      LibraryAnalyzer._isLibrarySource (package:analyzer/src/dart/analysis/library_analyzer.dart:512:25)
#3      LibraryAnalyzer._resolveDirectives (package:analyzer/src/dart/analysis/library_analyzer.dart:553:36)
#4      LibraryAnalyzer.analyzeSync (package:analyzer/src/dart/analysis/library_analyzer.dart:127:5)
#5      LibraryAnalyzer.analyze (package:analyzer/src/dart/analysis/library_analyzer.dart:104:12)
#6      AnalysisDriver._computeAnalysisResult.<anonymous closure> (package:analyzer/src/dart/analysis/driver.dart:1315:63)
#7      PerformanceLog.run (package:analyzer/src/dart/analysis/performance_logger.dart:32:15)
#8      AnalysisDriver._computeAnalysisResult (package:analyzer/src/dart/analysis/driver.dart:1286:20)
#9      AnalysisDriver._computeErrors (package:analyzer/src/dart/analysis/driver.dart:1369:26)
#10     AnalysisDriver.performWork (package:analyzer/src/dart/analysis/driver.dart:987:20)
#11     AnalysisDriverScheduler._run (package:analyzer/src/dart/analysis/driver.dart:2006:24)
<asynchronous suspension>

Here is my flutter doctor:

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.0.2, on Mac OS X 10.15.7 19H15 darwin-x64, locale en-IL)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[✓] Xcode - develop for iOS and macOS
[✓] Chrome - develop for the web
[✓] Android Studio (version 4.1)
[✓] Connected device (1 available)

• No issues found!
dkaera commented 3 years ago

Hi @saharvx9 Can you please provide lib/repository/rest/api.dart source code, to reproduce the problem or understand what might have gone wrong.

saharvx9 commented 3 years ago

Hi rest api is an interface it doesn't relate to floor it look like this:

class RestApi {
  login(String username, String password) {}

  getMachines(String? updateDt) {}

  getAlerts(String? updateDt) {}

  getMachinesExtraData(String? updateDt, List<int>? machines) {}

  getActorsHierarchy() {}

  getGroups(String? updateDt) {}

  getMachineInfo(int machineId_) {}
}

if i a'm deleting this class it present to me another class with this error with new class name if i'a, puttng a comment for whole classses it still present this error. I think there is a cache issue with all generator classes.

dkaera commented 3 years ago

hmm, in my assumption the floor annotations are used unproperly somewhere in the code. Can you please double-check the structure of the floor annotation declaration in your project, please? Maybe it's a wrong import in the class. It's hard to answer now. Here is the how-to manual https://vitusortner.github.io/floor/getting-started/

saharvx9 commented 3 years ago

I took all the floor classes to new project and it finish sucssefully. But when i'm returning other packges its happend again...

mqus commented 3 years ago

Can you run dartanalyzer/flutter analyze on your code? What is the output?

roma7481 commented 3 years ago

I'm having the same exception when I'm trying to build my .db.

final database = await $FloorAppDatabase.databaseBuilder(floorDB).build(); inside sqlite_database_factory.dart

databasesPath is null.

extension DatabaseFactoryExtension on DatabaseFactory {
  Future<String> getDatabasePath(final String name) async {
    final databasesPath = await this.getDatabasesPath();
    return join(databasesPath, name);
  }
}
E/flutter (17966): [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: Null check operator used on a null value
E/flutter (17966): #0      MethodChannel.binaryMessenger (package:flutter/src/services/platform_channel.dart:142:86)
E/flutter (17966): #1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:148:36)
E/flutter (17966): #2      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:331:12)
E/flutter (17966): #3      invokeMethod (package:sqflite/src/sqflite_impl.dart:17:13)
E/flutter (17966): #4      SqfliteDatabaseFactoryImpl.invokeMethod (package:sqflite/src/factory_impl.dart:82:7)
E/flutter (17966): #5      SqfliteDatabaseFactoryMixin.safeInvokeMethod.<anonymous closure> (package:sqflite_common/src/factory_mixin.dart:41:38)
E/flutter (17966): #6      wrapDatabaseException (package:sqflite/src/exception_impl.dart:7:32)
E/flutter (17966): #7      SqfliteDatabaseFactoryImpl.wrapDatabaseException (package:sqflite/src/factory_impl.dart:78:7)
E/flutter (17966): #8      SqfliteDatabaseFactoryMixin.safeInvokeMethod (package:sqflite_common/src/factory_mixin.dart:41:7)
E/flutter (17966): #9      SqfliteDatabaseFactoryMixin.getDatabasesPath (package:sqflite_common/src/factory_mixin.dart:153:26)
E/flutter (17966): #10     DatabaseFactoryExtension.getDatabasePath (package:floor/src/sqflite_database_factory.dart:24:38)
E/flutter (17966): #11     _$AppDatabaseBuilder.build (package:lullabies_flutter/app/data/repositories/floor_database.g.dart:46:40)
E/flutter (17966): #12     main (package:lullabies_flutter/main.dart:13:69)
E/flutter (17966): #13     _runMainZoned.<anonymous closure>.<anonymous closure> (dart:ui/hooks.dart:146:25)
E/flutter (17966): #14     _rootRun (dart:async/zone.dart:1354:13)
E/flutter (17966): #15     _CustomZone.run (dart:async/zone.dart:1258:19)
E/flutter (17966): #16     _runZoned (dart:async/zone.dart:1789:10)
E/flutter (17966): #17     runZonedGuarded (dart:async/zone.dart:1777:12)
E/flutter (17966): #18     _runMainZoned.<anonymous closure> (dart:ui/hooks.dart:139:5)
E/flutter (17966): #19     _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:283:19)
E/flutter (17966): #20     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)
vitusortner commented 3 years ago

@roma7481 I'm not sure if your described issue is related to the one reported initially. Which version of floor are you using?

@saharvx9 are you still experiencing the problem with the newest version?

DevHachi commented 3 years ago

I got the same problem. E/flutter (17113): [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: Null check operator used on a null value E/flutter (17113): #0 MethodChannel.binaryMessenger (package:flutter/src/services/platform_channel.dart:142:86) E/flutter (17113): #1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:148:36) E/flutter (17113): #2 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:331:12) E/flutter (17113): #3 invokeMethod (package:sqflite/src/sqflite_impl.dart:17:13) E/flutter (17113): #4 SqfliteDatabaseFactoryImpl.invokeMethod (package:sqflite/src/factory_impl.dart:82:7) E/flutter (17113): #5 SqfliteDatabaseFactoryMixin.safeInvokeMethod.<anonymous closure> (package:sqflite_common/src/factory_mixin.dart:41:38) E/flutter (17113): #6 wrapDatabaseException (package:sqflite/src/exception_impl.dart:7:32) E/flutter (17113): #7 SqfliteDatabaseFactoryImpl.wrapDatabaseException (package:sqflite/src/factory_impl.dart:78:7) E/flutter (17113): #8 SqfliteDatabaseFactoryMixin.safeInvokeMethod (package:sqflite_common/src/factory_mixin.dart:41:7) E/flutter (17113): #9 SqfliteDatabaseFactoryMixin.getDatabasesPath (package:sqflite_common/src/factory_mixin.dart:153:26) E/flutter (17113): #10 DatabaseFactoryExtension.getDatabasePath (package:floor/src/sqflite_database_factory.dart:24:38) E/flutter (17113): #11 _$AppDatabaseBuilder.build (package:movecat_smart_app/database/app_database.g.dart:46:40) E/flutter (17113): #12 LocalRepository._initDb (package:movecat_smart_app/repositories/local_repository.dart:152:10) E/flutter (17113): #13 new LocalRepository (package:movecat_smart_app/repositories/local_repository.dart:8:5) E/flutter (17113): #14 main (package:movecat_smart_app/main.dart:47:24) E/flutter (17113): #15 _runMainZoned.<anonymous closure>.<anonymous closure> (dart:ui/hooks.dart:142:25) E/flutter (17113): #16 _rootRun (dart:async/zone.dart:1354:13) E/flutter (17113): #17 _CustomZone.run (dart:async/zone.dart:1258:19) E/flutter (17113): #18 _runZoned (dart:async/zone.dart:1789:10) E/flutter (17113): #19 runZonedGuarded (dart:async/zone.dart:1777:12) E/flutter (17113): #20 _runMainZoned.<anonymous closure> (dart:ui/hooks.dart:138:5) E/flutter (17113): #21 _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:283:19) E/flutter (17113): #22 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)

I run on the newest version from floor and floor-generator. Floor Version: 1.1.0

kjawadDeveloper commented 3 years ago

Any update?

aecrespo95 commented 3 years ago

This error happened to me when I wanted to obtain an instance of the database before the runApp method, the solution for me was to execute this method before instantiating it: WidgetsFlutterBinding.ensureInitialized(); Personally I recommend using FutureBuilder and waiting for the Database to be instantiated, in this way the UI would not wait to be displayed by the database

Muraveiko commented 2 years ago

I get this error too. Null check operator used on a null value package:source_gen/src/type_checker.dart 177:74 TypeChecker.isExactlyType package:floor_generator/misc/type_utils.dart 32:43 StreamTypeChecker.isStream package:floor_generator/processor/query_method_processor.dart 43:41 QueryMethodProcessor.process

My wrong code :

@Query("DELETE FROM inn_info WHERE inn=:innInfo.inn") void delete(InnInfo innInfo);

Real error: All queries have to return a Future or Stream.