From: Caisking <3449750381@qq.com> Date: Tue, 9 Jul 2024 02:29:26 +0000 (+0800) Subject: 增加读取信息错误的默认 X-Git-Tag: release_V1.2.70_20241020_135402~828^2~11^2~8 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=1c9c7ce4f747958ee5e1a140a73f13b7dd2f4d90;p=mirrors%2FFD230.git 增加读取信息错误的默认 --- diff --git a/code/sdk/application/wearable/fd230app/nativeui/message/src/MessageModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/message/src/MessageModel.cpp index 2b7499db0..0dfc1a595 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/message/src/MessageModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/message/src/MessageModel.cpp @@ -290,8 +290,11 @@ namespace OHOS std::vector messageVector = LoadMessageData(); numberOfItems = messageVector.size(); WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "the numberOfItems is %d", numberOfItems); - - return &messageVector[numberOfItems - 1]; + if (numberOfItems >= 0) + { + return &messageVector[numberOfItems - 1]; + } + return nullptr; } // 设置当前项 void MessageModel::SetCurrentIndex(uint8_t index) diff --git a/code/sdk/application/wearable/service/msg_center/src/notify/message_notification.cpp b/code/sdk/application/wearable/service/msg_center/src/notify/message_notification.cpp index 0ccbe24f7..e4b1463e9 100644 --- a/code/sdk/application/wearable/service/msg_center/src/notify/message_notification.cpp +++ b/code/sdk/application/wearable/service/msg_center/src/notify/message_notification.cpp @@ -93,7 +93,7 @@ namespace OHOS return nullptr; } MessageGroupView->SetOnDragListener(dragListener); - #ifdef FD230 +#ifdef FD230 /*获取最新message*/ MessageData *data = MessageModel::GetInstance().GetNewestData(); if (data != nullptr) @@ -102,7 +102,13 @@ namespace OHOS timeStr = data->labelTime; messageStr = data->labelDetails; } - #endif + else + { + titleStr = "--"; + timeStr = "--"; + messageStr = "--"; + } +#endif /*初始化label*/ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitView"); /* -------------------------------------------------------------------------- */ @@ -164,7 +170,7 @@ namespace OHOS return nullptr; // 内存分配失败,返回 } deleteButton->SetPosition(0, 366); - deleteButton->Resize(466,100); + deleteButton->Resize(466, 100); deleteButton->SetViewId(DELETEBUTTON); deleteButton->SetText("Close"); deleteButton->SetStyle(STYLE_TEXT_FONT, 30);