当前位置:网站首页>Auto.js学习笔记10:实例化自定义对象,在子线程使用JSON.stringify()方法导致报错(已解决)
Auto.js学习笔记10:实例化自定义对象,在子线程使用JSON.stringify()方法导致报错(已解决)
2022-06-12 09:20:00 【PYB3】
申明本人使用的autojs是4.1.1版本
JSON.stringify()使用导致autojs软件直接奔溃退出。
报错核心局部代码
var sendInfoObj = { //对象
areaCode : "John", //区域参数
evaInfos : {}, //过期和即将过期信息
days : 1, //过期天数
curGroupName : "", //当前群
groupSize : 0, //群个数
size : 0, //总个数
timerState : false, //定时发送开关
timingTime : "9:00" //定时发送时间
};
function toString2(){
log("对象数据是:\n"+JSON.stringify(sendInfoObj));
}
function send_wx_info(evaInfos) {
var thread2 = threads.start(function(){
// 群发消息
var i = 0;
var 定时器 = thread2.setInterval(function(){
sleep(600);
var content = '';
if(i==0){
content = '*发布时间:'+myUtils.formatDate() +"*\n";
}
if(i < sendInfoObj.size){
setText(content);
text("发送").click();
}else{
toString2();
/* 结束流程 */
// back();
clearInterval(定时器);
thread2.interrupt();
exeNextGroup();
// sleep(2666);
// exit();
}
i++;
}, 1600);
});
}
toString2()调用导致报错及相关错误信息
子线程调用报错
workbench.desktop.main.js:71 [Extension Host] 10:13:44.865/E: Thread[main (Spawn-1),5]: Wrapped java.lang.IllegalArgumentException: class android.content.res.ColorStateList declares multiple JSON fields named mChangingConfigurations (file:///android_asset/modules/__json2__.js#234)Wrapped java.lang.IllegalArgumentException: class android.content.res.ColorStateList declares multiple JSON fields named mChangingConfigurations at str (file:///android_asset/modules/__json2__.js:234:0) at str (file:///android_asset/modules/__json2__.js:338:0) at toString2 ([remote]AutoWeiXinNews.js:132:0) at [remote]AutoWeiXinNews.js:496:0
主线程调用报错
JavaException: java.lang.IllegalArgumentException: class android.content.res.ColorStateList declares multiple JSON fields named mChangingConfigurations
分析错误原因并解决
通过多次联调,细细排查,确认是对象属性赋值ui控件返回值的问题
UI局部布局代码
<input id = "qunNameIt" singleLine = 'true' text="微信机器人群,机器人群聊2" hint="输入群名或用户名"></input>
<input id = "areaCodeIt" singleLine = "true" hint="例如:自贡市" text='510300-自贡市'></input>
<input id = "countIt" digit="1234567890" singleLine = "true" text = "3" hint="输入过期天次数" ></input>
<input id = "endTxt" text = ""></input> 错误的赋值方式如下:(myTrim函数是我自定义的不用管它)
sendInfoObj.days = myUtils.myTrim(ui.countIt.getText().toString());
sendInfoObj.areaCode = myUtils.myTrim(ui.areaCodeIt.getText().toString());
sendInfoObj.endHint = ui.endTxt.getText().toString();正确的赋值方式如下:
sendInfoObj["days"] = myUtils.myTrim(ui.countIt.getText().toString());
sendInfoObj["areaCode"] = myUtils.myTrim(ui.areaCodeIt.getText().toString());
sendInfoObj['endHint'] = ui.endTxt.getText().toString();ui错误赋值导致报错:
sendInfoObj['endHint'] = ui.endTxt.getText();切记要加入toString()
正确是这样的: sendInfoObj['endHint'] = ui.endTxt.getText().toString();
总结
当赋值错误后,和赋值相关的错误日志却和赋值没关系是其它错误(这点最头大,很不好确认问题)。
ui布局要使用 sendInfoObj["days"] = myUtils.myTrim(ui.countIt.getText().toString()); 才能进行正确的赋值。
其它值可以 直接以“=”号进行赋值,例如:
var json = res.body.string();//接口获取的json数据
var objj = JSON.parse(json); //转为对象
sendInfoObj.evaInfos = JSON.parse(objj); //转为可访问对象并赋值目前我看的情况和解决方法就是如此,有大佬可以留言交流。
边栏推荐
- 抽象类和接口
- (15) Tweenrunner
- Common technical questions in functional test interview. Would you like to summarize them?
- How should the test plan be written? A thought teaches you
- 自动化测试框架的设计原则有哪些?我帮你总结好了快来看
- Sword finger offer:[day 9 dynamic planning (medium)] --- > maximum sum of continuous subarrays
- Solve the problem that when unity is opened, you will be prompted that the project has been opened, but you have not opened it before (it may be closed abnormally before)
- Grab screen and ground glass effect
- mySql学习记录——三、mysql查询语句
- Is it necessary to separate databases and tables for MySQL single table data of 5million?
猜你喜欢
APP测试面试题汇总,面试必考一定要看

EIP-1559

Swagger documentation details

NiO principle

Distributed transaction solution 1: TCC (compensation transaction)

Technology cloud report: how will the industrial Internet rebuild the security boundary in 2022?

Hotspot Metaspace

Machine learning notes - circular neural network memo list
Selenium面试题分享
ADB命令集锦,一起来学吧
随机推荐
SQL basic syntax II
软件测试面试官问这些问题的背后意义你知道吗?
Permutation (greedy strategy)
There must be something you want to know about software testing experience sharing
Thread deadlock and its solution
++ problems in C language
128. 最長連續序列-哈希錶
Financial test interview questions to help you get the offer
Subtractive integer (number theory)
More than 90% of the software companies will ask the software test interview questions. Hurry to recite them
Binary tree calculation problem
ThreadLocal
測試用例和bug描述規範參考
Grab screen and ground glass effect
Do you know how to improve software testing ability?
Codecraft-22 and codeforces round 795 (Div. 2)
Basic SQL syntax i
2024. 考试的最大困扰度-滑动窗口
Solution of hmaster process flash back after starting
软件测试基础知识分享,写点你不知道的