【问题标题】:how to solve XMLHttpRequest error on flutter?如何解决 Flutter 上的 XMLHttpRequest 错误?
【发布时间】:2021-11-11 11:34:00
【问题描述】:

当我运行我的代码时,我收到以下错误,我的应用程序用于从 youtube 下载视频声音。

错误

调试服务监听 ws://127.0.0.1:57539/2eLyP6sNDkg=/ws XMLHttpRequest 错误。 TypeError:无法读取 null 的属性(读取“缩略图”) 在 YoutubeMP3._YoutubeMP3State.new.getInfo (http://localhost:62257/packages/utube_mp3/YoutubeMP3.dart.lib.js:507:40) 在getInfo.throw() 在 http://localhost:62257/dart_sdk.js:40652:38 在 _RootZone.runBinary (http://localhost:62257/dart_sdk.js:40508:58) 在 _FutureListener.thenAwait.handleError (http://localhost:62257/dart_sdk.js:35445:33) 在句柄错误(http://localhost:62257/dart_sdk.js:36033:51) 在 Function._propagateToListeners (http://localhost:62257/dart_sdk.js:36059:17) 在 _Future.new.[_completeError] (http://localhost:62257/dart_sdk.js:35905:23) 在 async._AsyncCallbackEntry.new.callback (http://localhost:62257/dart_sdk.js:35944:31) 在 Object._microtaskLoop (http://localhost:62257/dart_sdk.js:40808:13) 在 _startMicrotaskLoop (http://localhost:62257/dart_sdk.js:40814:13) 在 http://localhost:62257/dart_sdk.js:36279:9

函数获取信息


 //

 Future<void> getInfo() async {
   insertBody(videoURL.text);
   setState(() {
     progress = "";
     status = "Download";
     downloadsuccess = false;
     isDownloading = false;
     isFetching = true;
     fetchSuccess = false;
   });
   try {
     var response = await http.post("https://www.y2mate.com/fr22",
         body: body, headers: headers);

     video = Result.convertResult(response.body);
     setState(() {
       isFetching = false;
       fetchSuccess = true;
     });
   } catch (e) {
     print(e.toString());
     setState(() {
       isFetching = true;
       fetchSuccess = false;
     });
   }
   print("${video.thumbnail}\n${video.audioName}\n${video.vid}\n${video.id}");
 }

【问题讨论】:

  • 试试我的回答here希望对你有帮助
  • 谢谢,但还是不行
  • 现在是什么问题

标签: flutter android-studio xmlhttprequest


【解决方案1】:

您的错误消息表明 getInfo 正在尝试访问 (null).thumbnail。这可能是您最后的打印声明。如果 Result.convertResult() 因异常而失败并且 video=null,则执行将移至您的 catch() 块,然后尝试打印“video.thumbnail”(不存在)

您可以尝试使用 if (video!=null) 包装您的最后一个打印语句,或者将其移到您的 try{} 块中。

【讨论】:

  • 我将最后一个打印语句重写为 print("error");我在运行我的程序时得到它,我该怎么做才能得到正确的结果?
猜你喜欢
  • 2022-08-19
  • 2013-10-12
  • 2021-11-05
  • 2021-12-29
  • 2022-10-02
  • 2022-11-03
  • 1970-01-01
  • 2021-09-24
  • 2019-02-10
相关资源
最近更新 更多