【问题标题】:After applying Android Studio 2.3.3 suggested changes (to remove warnings) I now get either of two errors. What to do?应用 Android Studio 2.3.3 建议的更改(以删除警告)后,我现在遇到两个错误之一。该怎么办?
【发布时间】:2017-08-26 22:25:46
【问题描述】:

这里有一点背景。在我的应用程序中查询数据库 (QueryDB) 的过程从 MainActivity.onCreate 开始,我有这段代码:

assets = getAssets(); // the SQLite database

DatabaseConnector 
  dbc = new DatabaseConnector(getApplicationContext(), assets);
  dbc.setDbProcesslistener(this); // set way to know matches has been defined
  dbc.findDBMatches();

在我的问题(名为DatabaseConnector)的文件中,我有:

  void findDBMatches()
  {
    mContext.startService(new Intent(mContext, QueryDB.class));
  }

这就是问题所在。这个代码段...

  public static class QueryDB extends IntentService
  {
    public QueryDB(String name)
    {
      super(name);
    }

导致此错误:

? E/libprocessgroup: failed to make and chown /acct/uid_10058: Read-only file system ? W/Zygote: createProcessGroup failed, kernel missing CONFIG_CGROUP_CPUACCT? com.dslomer64.servyhelperton E/AndroidRuntime: FATAL EXCEPTION: main Process: com.dslomer64.servyhelperton, PID: 335 java.lang.RuntimeException: Unable to instantiate service com.dslomer64.servyhelperton.DatabaseConnector$QueryDB: java.lang.InstantiationException: class com.dslomer64.servyhelperton.DatabaseConnector$QueryDB 没有零参数构造函数

错误没有告诉我一行,但确实提到了QueryDB。所以我为QueryDB 插入一个零参数构造函数并立即得到一个错误:

我圈出了extends IntentService,因为在findDBMatches 中,我为QueryDB 启动了一项服务,并且第一条错误消息显示Unable to instantiate service。但是,在调试中,我发现在mContext.startService(new Intent(mContext, QueryDB.class)); 行处执行并没有失败。我在 QueryDB 的构造函数中设置了断点,但没有执行。

我迷路了。

在(愚蠢地)接受 AS 的更改建议之前,该应用运行良好。现在我可以回顾历史并恢复到开始更改之前的版本,但是有很多(警告)我已经摆脱了,我宁愿不这样做。 如果有人可以用这么短的 sn-ps 代码提出修复建议,我可以尝试一下,也许会很好。

补充说明:

如果没有 QueryDB 扩展 IntentService,应用将无法运行(出现其他即时错误)。

请注意,mContext 被声明为 static(由于内存泄漏,我现在知道不要这样做),但它是否为 static 并不重要。同样的错误。

【问题讨论】:

    标签: android android-intent service database-connection intentservice


    【解决方案1】:

    在构造函数中使用super("QueryDB");

    public QueryDB {
    super("QueryDB");
    }
    

    【讨论】:

    • 好吧,这消除了这两个错误,但是还有另一个错误导致手机崩溃,并且 Logcat 有很多行说 com.android.inputmethod.latin E/RichInputConnection: Unable to connect to the editor to retrieve text. 所以我不能说它是固定的,但我已经过去了我曾是。到底他妈发生了什么?我已经收到了数百次这条消息,断断续续,一整天。重新启动或清除 Logcat 无济于事。将退出 AS 并使用不同的模拟器,最后我的手机看看我是否最终得到错误的位置。
    • 并不是没有消除这两个错误。嗯,它确实,但现在有一种可预测的新错误:`java.lang.RuntimeException:无法实例化服务 com.dslomer64.servyhelperton.DatabaseConnector$QueryDB:java.lang.IllegalAccessException:`不允许访问构造函数。我真的怀疑你的建议能解决我的问题。而且,这甚至不合法
    • 发布您的代码以进行检查。您的意思是我的解决方案没有帮助吗?
    • 我认为您的数据库连接有问题。或数据库内的数据不正确
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-30
    • 2018-01-24
    • 2020-10-23
    • 1970-01-01
    • 1970-01-01
    • 2017-10-13
    相关资源
    最近更新 更多