Dart异常:类String没有实例方法'>'

时间:2014-04-02 22:35:45

标签: exception dart sqljocky

我正在编写一个简单的类来使用sqljocky来管理数据库查询。代码如下

import 'package:sqljocky/sqljocky.dart';

import 'Config.dart';

abstract class QueryResultCallBack {
  void handleQuery(dynamic queryResult);
}

class DatabaseFactory {

  static DatabaseFactory INSTANCE;

  static DatabaseFactory getInstance() {
    if(INSTANCE == null)
      INSTANCE = new DatabaseFactory();

    return INSTANCE;
  }

  var dbpool;

  DatabaseFactory() {
    if(Config.DB_PWD.length == 0) {
      dbpool = new ConnectionPool(host: Config.DB_HOST, port: Config.DB_PORT, user: Config.DB_USER, db: Config.DB_NAME, max: Config.DB_CONNECTION_POOL_SIZE);
    } else {
      dbpool = new ConnectionPool(host: Config.DB_HOST, port: Config.DB_PORT, user: Config.DB_USER, password: Config.DB_PWD, db: Config.DB_NAME, max: Config.DB_CONNECTION_POOL_SIZE);
    }
  }

  void executeFullQuery(String query, QueryResultCallBack callback) {
    dbpool.query(query).then((result) {
      callback.handleQuery(result);
    });
  }

  void executeQuery(String queryStr, List<dynamic> params, QueryResultCallBack callback) {
    try {
      dbpool.prepareExecute(queryStr, params).then((result) {
          callback.handleQuery(result);
      });
    } catch(e) {
      print('DatabaseFactory.executeQuery exception:\n${e}');
    }
  }

  void shutDown() {
    dbpool.close();
  }
}

然而,当执行查询时,我得到异常&#34;类String没有实例方法&#39;)&#39;。堆栈跟踪显示它被抛出:

dbpool.prepareExecute(queryStr, params).then((result) {

我已经在互联网上搜索过,大多数情况下这种错误都是一个包丢失的错误,但没有发现任何类似String的情况。有什么想法吗?

提前致谢

编辑:Stacktrace

Uncaught Error: Class 'String' has no instance method '>'.

NoSuchMethodError : method not found: '>'
Receiver: "5"
Arguments: [0]
Stack Trace:
#0      Object.noSuchMethod (dart:core-patch/object_patch.dart:45)
#1      int.< (dart:core-patch/integers.dart:72)
#2      ConnectionPool._getConnection (package:sqljocky/src/connection_pool.dart
:64:29)
#3      Query._getConnection (package:sqljocky/src/query.dart:35:32)
#4      Query._prepare (package:sqljocky/src/query.dart:41:26)
#5      ConnectionPool.prepare (package:sqljocky/src/connection_pool.dart:242:26
)
#6      ConnectionPool.prepareExecute (package:sqljocky/src/connection_pool.dart
:310:19)
#7      DatabaseFactory.executeQuery (file:///C:/Users/Nadir/Downloads/dart/dart
-sdk/bin/prueba/DatabaseFactory.dart:46:28)
#8      main.<anonymous closure>.<anonymous closure> (file:///C:/Users/Nadir/Dow
nloads/dart/dart-sdk/bin/prueba/Server.dart:27:49)
#9      _rootRunUnary (dart:async/zone.dart:717)
#10     _RootZone.runUnary (dart:async/zone.dart:854)
#11     _BaseZone.runUnaryGuarded (dart:async/zone.dart:569)
#12     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:333)

#13     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:263)
#14     _StreamController&&_SyncStreamControllerDispatch._sendData (dart:async/s
tream_controller.dart:529)
#15     _StreamController._add (dart:async/stream_controller.dart:438)
#16     _StreamController.add (dart:async/stream_controller.dart:395)
#17     _HttpServer._handleRequest (http_impl.dart:2116)
#18     _HttpConnection._HttpConnection.<anonymous closure> (http_impl.dart:1954
)
#19     _rootRunUnary (dart:async/zone.dart:717)
#20     _RootZone.runUnary (dart:async/zone.dart:854)
#21     _BaseZone.runUnaryGuarded (dart:async/zone.dart:569)
#22     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:333)

#23     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:263)
#24     _StreamController&&_SyncStreamControllerDispatch._sendData (dart:async/s
tream_controller.dart:529)
#25     _StreamController._add (dart:async/stream_controller.dart:438)
#26     _StreamController.add (dart:async/stream_controller.dart:395)
#27     _HttpParser._doParse (http_parser.dart:687)
#28     _HttpParser._parse (http_parser.dart:343)
#29     _onData (http_parser.dart:813)
#30     _rootRunUnary (dart:async/zone.dart:717)
#31     _RootZone.runUnary (dart:async/zone.dart:854)
#32     _BaseZone.runUnaryGuarded (dart:async/zone.dart:569)
#33     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:333)

#34     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:263)
#35     _StreamController&&_SyncStreamControllerDispatch._sendData (dart:async/s
tream_controller.dart:529)
#36     _StreamController._add (dart:async/stream_controller.dart:438)
#37     _StreamController.add (dart:async/stream_controller.dart:395)
#38     _onData (dart:io-patch/socket_patch.dart:1356)
#39     _rootRunUnary (dart:async/zone.dart:717)
#40     _RootZone.runUnary (dart:async/zone.dart:854)
#41     _BaseZone.runUnaryGuarded (dart:async/zone.dart:569)
#42     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:333)

#43     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:263)
#44     _StreamController&&_SyncStreamControllerDispatch._sendData (dart:async/s
tream_controller.dart:529)
#45     _StreamController._add (dart:async/stream_controller.dart:438)
#46     _StreamController.add (dart:async/stream_controller.dart:395)
#47     _RawSocket._RawSocket.<anonymous closure> (dart:io-patch/socket_patch.da
rt:948)
#48     multiplex (dart:io-patch/socket_patch.dart:604)
#49     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dar
t:115)


Unhandled exception:
Class 'String' has no instance method '>'.

NoSuchMethodError : method not found: '>'
Receiver: "5"
Arguments: [0]
#0      _rootHandleUncaughtError.<anonymous closure>.<anonymous closure> (dart:a
sync/zone.dart:700)
#1      _asyncRunCallbackLoop (dart:async/schedule_microtask.dart:23)
#2      _asyncRunCallback (dart:async/schedule_microtask.dart:32)
#3      _asyncRunCallback (dart:async/schedule_microtask.dart:36)
#4      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dar
t:119)

1 个答案:

答案 0 :(得分:1)

在DatabaseFactory()中,您创建一个ConnectionPool并使用max:Config.DB_CONNECTION_POOL_SIZE.初始化它

Config.DB_CONNECTION_POOL_SIZE似乎是String,但必须是int。将intString package:sqljocky/src/connection_pool.dart:64:29进行比较时,会发生异常。

Config.DB_CONNECTION_POOL_SIZE更改为int。