首页 文章

类型'String'不是'index'的'index'类型的子类型

提问于
浏览
1

我的应用程序可以在针对Android模拟器进行调试时成功进行身份验证,但如果我尝试使用针对物理设备的调试进行身份验证(具有相同的操作系统版本),则会在等待超过一分钟后出现错误消息:

发生了例外情况 . _TypeError(类型'String'不是'index'的'int'类型的子类型)

错误消息指向以下代码:

if (responseJson[AuthUtils.authTokenKey] != null) {
          AuthUtils.insertDetails(
              userNameController.text, passwordController.text, responseJson);
...
        } else {
...
        };

在DEBUG CONSOLE我得到以下内容:

I / flutter(9531):Auth:SocketException:OS Error:连接超时,errno = 110,address = example.com,port = 38975 V / InputMethodManager(9531):开始输入:tba = android.view.inputmethod . EditorInfo @ 4aece4e nm:example.com.todoapp ic = null

这是截图:
enter image description here

我在这做错了什么?

1 回答

  • 1

    我相信在线:

    responseJson[AuthUtils.authTokenKey]
    

    您正在通过索引 AuthUtils.authTokenKey 引用列表 responseJson 中的项目

    由于 AuthUtils.authTokenKey 是一个String,因此不能将其用作数组的索引 .

    所以你需要先获得 AuthUtils.authTokenKey 的索引,然后用它来引用该项:

    responseJson[responseJson.indexOf(AuthUtils.authTokenKey)]
    

相关问题