HarmonyOS 鸿蒙Next 标准化数据通路删除异常
HarmonyOS 鸿蒙Next 标准化数据通路删除异常
我调用标准数据通路删除方法时,直接返回异常。code,message都是空字符串’’。 代码如下:
static deleteShareFile() {
let options: unifiedDataChannel.Options = { intention: unifiedDataChannel.Intention.DATA_HUB, }
try {
unifiedDataChannel.deleteData(options, (err, data) => {
//此处返回异常
if (err === undefined) {
console.info(`Succeeded in deleting data. size = ${data.length}`);
for (let i = 0; i < data.length; i++) {
let records = data[i].getRecords();
for (let j = 0; j < records.length; j++) {
if (records[j].getType() === uniformTypeDescriptor.UniformDataType.PLAIN_TEXT) {
let text = records[j] as unifiedDataChannel.PlainText;
console.info(`${i + 1}.${text.textContent}`);
}
}
}
} else {
console.error(`Failed to delete data. code is ${err.code},message is ${err.message} `);
}
});
} catch (e) {
let error: BusinessError = e as BusinessError;
console.error(`Delete data throws an exception. code is ${error.code},message is ${error.message} `);
}
}
异常stack: Cannot get SourceMap info, dump raw stack:
=====================Backtrace========================
#00 pc 00000000005e5498 /system/lib64/platformsdk/libark_jsruntime.so #01 pc 00000000005e5a0c /system/lib64/platformsdk/libark_jsruntime.so #02 pc 000000000029c3fc /system/lib64/platformsdk/libark_jsruntime.so #03 pc 0000000000164204 /system/lib64/platformsdk/libark_jsruntime.so #04 pc 0000000000163da0 /system/lib64/platformsdk/libark_jsruntime.so #05 pc 00000000001de0d8 /system/lib64/platformsdk/libark_jsruntime.so #06 pc 00000000004fbb20 /system/lib64/platformsdk/libark_jsruntime.so #07 pc 00000000004d3abc /system/lib64/platformsdk/libark_jsruntime.so #08 pc 000000000004c334 /system/lib64/platformsdk/libace_napi.z.so #09 pc 000000000005e640 /system/lib64/libudmf_data_napi.z.so topstack
=====================Backtrace========================
#00 pc 00000000005e5498 /system/lib64/platformsdk/libark_jsruntime.so #01 pc 00000000005e5a0c /system/lib64/platformsdk/libark_jsruntime.so #02 pc 000000000029c3fc /system/lib64/platformsdk/libark_jsruntime.so #03 pc 0000000000164204 /system/lib64/platformsdk/libark_jsruntime.so #04 pc 0000000000163da0 /system/lib64/platformsdk/libark_jsruntime.so #05 pc 00000000001de0d8 /system/lib64/platformsdk/libark_jsruntime.so #06 pc 00000000004fbb20 /system/lib64/platformsdk/libark_jsruntime.so #07 pc 00000000004d3abc /system/lib64/platformsdk/libark_jsruntime.so #08 pc 000000000004c334 /system/lib64/platformsdk/libace_napi.z.so #09 pc 000000000005e640 /system/lib64/libudmf_data_napi.z.so
</pre
更多关于HarmonyOS 鸿蒙Next 标准化数据通路删除异常的实战教程也可以访问 https://www.itying.com/category-93-b0.html
如果不能解决,麻烦提供一份可以运行的最小复现demo。
import { unifiedDataChannel, uniformTypeDescriptor } from '@kit.ArkData';
import { BusinessError } from '@kit.BasicServicesKit';
import { promptAction } from '@kit.ArkUI';
@Entry
@Component
struct Index {
@State message: string = ‘删除’;
build() {
Row() {
Column({ space: 10 }) {
Button(“insert”).onClick(() => {
this.insert()
})
Button(“delete”).onClick(() => {
this.delete()
})
}.width(<span class="hljs-string">'100%'</span>)
}.height(<span class="hljs-string">'100%'</span>)
}
insert() {
let plainText = new unifiedDataChannel.PlainText();
plainText.textContent = ‘hello world!’;
let unifiedData = new unifiedDataChannel.UnifiedData(plainText);
<span class="hljs-comment">// 指定要插入数据的数据通路枚举类型</span>
<span class="hljs-keyword">let</span> options: unifiedDataChannel.Options = {
intention: unifiedDataChannel.Intention.DATA_HUB
}
<span class="hljs-keyword">try</span> {
unifiedDataChannel.insertData(options, unifiedData, (err, key) => {
<span class="hljs-keyword">if</span> (err === <span class="hljs-literal">undefined</span>) {
console.info(`Succeeded <span class="hljs-keyword">in</span> inserting data. key = ${key}`);
} <span class="hljs-keyword">else</span> {
console.error(`Failed to insert data. code is ${err.code},message is ${err.message} `);
}
});
} <span class="hljs-keyword">catch</span> (e) {
<span class="hljs-keyword">let</span> error: BusinessError = e as BusinessError;
console.error(`Insert data throws an exception. code is ${error.code},message is ${error.message} `);
}
}
delete() {
// 指定要删除数据的数据通路枚举类型
let options: unifiedDataChannel.Options = {
intention: unifiedDataChannel.Intention.DATA_HUB
};
<span class="hljs-keyword">try</span> {
unifiedDataChannel.deleteData(options, (err, data) => {
<span class="hljs-keyword">if</span> (err === <span class="hljs-literal">undefined</span>) {
console.info(`Succeeded <span class="hljs-keyword">in</span> deleting data. size = ${data.length}`);
<span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> i = <span class="hljs-number">0</span>; i < data.length; i++) {
<span class="hljs-keyword">let</span> records = data[i].getRecords();
<span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> j = <span class="hljs-number">0</span>; j < records.length; j++) {
<span class="hljs-keyword">if</span> (records[j].getType() === uniformTypeDescriptor.UniformDataType.PLAIN_TEXT) {
<span class="hljs-keyword">let</span> text = records[j] as unifiedDataChannel.PlainText;
console.info(`${i + <span class="hljs-number">1</span>}.${text.textContent}`);
}
}
}
promptAction.showToast({ message: <span class="hljs-string">'删除成功'</span> })
} <span class="hljs-keyword">else</span> {
console.error(<span class="hljs-string">"message"</span> + <span class="hljs-built_in">JSON</span>.stringify(err, <span class="hljs-built_in">Object</span>.getOwnPropertyNames(err), <span class="hljs-number">2</span>))
console.error(`Failed to <span class="hljs-keyword">delete</span> data. code is ${err.code},message is ${err.message} `);
promptAction.showToast({ message: <span class="hljs-string">'删除失败'</span> })
}
});
} <span class="hljs-keyword">catch</span> (e) {
<span class="hljs-keyword">let</span> error: BusinessError = e as BusinessError;
console.error(`Delete data throws an exception. code is ${error.code},message is ${error.message} `);
promptAction.showToast({ message: <span class="hljs-string">'删除失败'</span> })
}
}
}
<button style="position: absolute; padding: 4px 8px 0px; cursor: pointer; top: 8px; right: 8px; font-size: 14px;">复制</button>
尝试如下demo,您这边报错主要是直接调用删掉方法是没有数据的,抛出了异常,需要先insert数据再进行删除。
更多关于HarmonyOS 鸿蒙Next 标准化数据通路删除异常的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
针对HarmonyOS 鸿蒙Next标准化数据通路删除异常的问题,可以从以下几个方面进行排查:
- 查看日志:利用DevEco Studio的Logcat功能,检查崩溃或异常时的日志,特别是包含E/或FATAL等关键字的堆栈跟踪信息,以确定异常的具体位置和原因。
- 检查连接:确保数据库连接信息正确,同时检查应用是否已声明必要的存储权限。
- 验证SQL语句:检查涉及的SQL语句,确保语法正确且数据类型匹配。
- 分析并发控制:确保数据库操作的并发控制得当,避免多个写操作并发引起报错。
- 检查权限:确保执行删除操作的用户具有足够的权限,包括数据库权限和系统权限。
- 代码审查:检查代码实现,确保在调用删除方法时传递了正确的参数和选项。
如果在进行上述排查后问题依旧无法解决,建议联系官网客服。官网地址是:https://www.itying.com/category-93-b0.html 。他们将提供更专业的技术支持和解决方案。