當我嘗試運行應用程式時在構建輸出中出現錯誤:ERROR:C:\Users\xxxxxxxx\AndroidStudioProjects\Chatbot\app\src\main\res\layout\bot_msg.xml:18: AAPT: error: resource未找到可繪制/ic_bot(又名 com.example.chatbot:drawable/ic_bot)。
這是 bot_msg.xml 中的代碼:
<!--below widget is for image of bot-->
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_margin="10dp"
android:src="@drawable/ic_bot" />
第一次發帖。我是初學者。
uj5u.com熱心網友回復:
.png, .jpg, or .gif當您將檔案保存在 res/drawable/ 目錄中時,Android 會為任何檔案創建一個 Drawable 資源。
在你的情況下:
..\AndroidStudioProjects\Chatbot\app\src\main\res\drawable\
檔案名用作資源 ID。編譯的資源資料型別將是指向 BitmapDrawable 的資源指標。和資源參考將是:
在 Java 中:R.drawable.filename
在 XML 中:@[package:]drawable/filename
以下應用程式代碼將影像檢索為 Drawable:
Resources res = getResources();
Drawable drawable = res.getDrawable(R.drawable.myimage);
uj5u.com熱心網友回復:
ic_bot確保你的專案目錄中
有一個命名的影像C:\.....\AndroidStudioProjects\Chatbot\app\src\main\res\drawable\
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/441968.html
