HarmonyOS鸿蒙Next中@Concurrent编译错误

HarmonyOS鸿蒙Next中@Concurrent编译错误 按照指南链接的并发代码,放到自己工程代码的时候,编译报红,提示A function or a method can only be decorated by one of the ‘Extend, Builder and Styles’.

其他人也遇到了,希望鸿蒙的同事处理下


更多关于HarmonyOS鸿蒙Next中@Concurrent编译错误的实战教程也可以访问 https://www.itying.com/category-93-b0.html

12 回复

我也遇到了这个问题,无法解决

更多关于HarmonyOS鸿蒙Next中@Concurrent编译错误的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html


请问楼主解决了吗,我也遇到了

没有,楼上有人能编译过,虽让都是API9,但他的版本比我的高,SDK 也没提示升级,

我也是。

我拿api9编译过的啊

你看看升级下api版本呢

我这里api 版本 3.2.12.5,devEco没有提示升级到3.2.14.6,是没有推送给我们么,

解决了吗 我也是3.2.12.5

没有,估计得等推送新版本才能解决吧,

请提供下完整代码,sdk版本以及API版本

sdk是openharmony:3.2.12.5,API 9,下面是代码

import taskpool from '@ohos.taskpool';

@Concurrent
function imageProcessing(dataSlice: ArrayBuffer) {
  // 步骤1: 具体的图像处理操作及其他耗时操作
  return dataSlice;
}

function histogramStatistic(pixelBuffer: ArrayBuffer) {
  // 步骤2: 分成三段并发调度
  let number = pixelBuffer.byteLength / 3;
  let buffer1 = pixelBuffer.slice(0, number);
  let buffer2 = pixelBuffer.slice(number, number * 2);
  let buffer3 = pixelBuffer.slice(number * 2);

  let task1 = new taskpool.Task(imageProcessing, buffer1);
  let task2 = new taskpool.Task(imageProcessing, buffer2);
  let task3 = new taskpool.Task(imageProcessing, buffer3);

  taskpool.execute(task1).then((ret: ArrayBuffer[]) => {
    // 步骤3: 结果处理
  });
  taskpool.execute(task2).then((ret: ArrayBuffer[]) => {
    // 步骤3: 结果处理
  });
  taskpool.execute(task3).then((ret: ArrayBuffer[]) => {
    // 步骤3: 结果处理
  });
}

@Entry
@Component
struct Index {
  @State message: string = 'Hello World'

  build() {
    Row() {
      Column() {
        Text(this.message)
          .fontSize(50)
          .fontWeight(FontWeight.Bold)
          .onClick(() => {
            let data: ArrayBuffer;
            histogramStatistic(data);
          })
      }
      .width('100%')
    }
    .height('100%')
  }
}

在HarmonyOS鸿蒙Next中,@Concurrent注解用于标记并发任务。编译错误可能由以下原因引起:

  1. 注解使用不当:确保@Concurrent仅用于异步任务方法,且方法签名符合要求。
  2. 依赖缺失:检查是否导入了正确的并发库或框架。
  3. 语法错误:确认代码中无其他语法错误,如拼写错误或参数不匹配。
  4. 版本兼容性:确认使用的HarmonyOS SDK版本支持@Concurrent注解。

建议检查代码、依赖和SDK版本,或查阅官方文档获取更多信息。

回到顶部