久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何在出現“無法解析放置符號"錯誤時向

How to add keys and values to a Hashmap while getting #39;cannot resolve put symbol#39; error(如何在出現“無法解析放置符號錯誤時向 Hashmap 添加鍵和值)
本文介紹了如何在出現“無法解析放置符號"錯誤時向 Hashmap 添加鍵和值的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在使用 Android Studio 1.4.1,我剛剛創建了一個 Hashmap,并且正在學習如何填充和操作它的教程(關于 java).但是,我收到無法解析符號放置"錯誤,并且放置"命令為紅色.我添加的圖像顯示了自動完成快照,盡管導入了 java.util.HashMap,但自動完成中沒有可用的put"命令.可用的命令也以紅色顯示.我嘗試使用它們而不是put"命令.我一直有這種類型的問題.任何人都可以幫忙嗎?提前謝謝你...

I am working with Android Studio 1.4.1 and I had just created a Hashmap and was following a tutorial (on java) on how to populate and manipulate it. However I get a 'cannot resolve symbol put' error and the "put" command is in red. The image I added shows the auto complete snapshot and although java.util.HashMap is imported there is no "put" command that is available in autocomplete. The available commands also are showing in red. I tried to use them instead of the "put" command. I keep having this type of problem all along. Can anyone help? Thank you in advance...

import java.util.HashMap;

HashMap<String, String> pozisyon = new HashMap<String, String>();
pozisyon.put("SKale", "a8");

推薦答案

您不能在方法之外的 HashMap 字段中添加元素.這樣的事情是行不通的:

You cannot add elements in HashMap fields outside of methods. Things like this wont work:

public class Class {
    HashMap<String, String> hashMap = new HashMap<String, String>();
    hashMap.put("one", "two");
}

如果你想實現它,把它放在構造函數中,像這樣:

If you want to achieve that, put it in the constructors, like so:

public class Class {
    HashMap<String, String> hashMap = new HashMap<String, String>();

    public Class() {
        hashMap.put("one", "two");
    }
}

您可以使用 static 塊來執行此操作.

Other way you can do it is in a static block.

這篇關于如何在出現“無法解析放置符號"錯誤時向 Hashmap 添加鍵和值的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Convert List of Strings into Map using Java-8 Streams API(使用 Java-8 Streams API 將字符串列表轉換為 Map)
Getting data from JSON(從 JSON 獲取數據)
java linkedhashmap iteration(javalinkedhashmap迭代)
Converting a list of objects to Map(將對象列表轉換為 Map)
Create a HashMap with a fixed Key corresponding to a HashSet. point of departure(用一個固定的Key對應一個HashSet創建一個HashMap.出發點)
HttpMessageConverter exception : RestClientException: Could not write request: no suitable HttpMessageConverter found(HttpMessageConverter 異常:RestClientException:無法寫入請求:找不到合適的 HttpMessageConverter) - IT屋-程序員
主站蜘蛛池模板: 毛片99| 亚洲在线一区二区 | 日韩中文字幕在线 | 国产精品69久久久久水密桃 | 日本免费一区二区三区视频 | www精品美女久久久tv | 美女黄色在线观看 | 久久久.com| 精品国产一二三区 | 日韩精品 电影一区 亚洲 | 日韩视频在线一区 | 国产精品乱码一区二三区小蝌蚪 | 欧美男人亚洲天堂 | 中文在线播放 | 97成人在线 | 欧美一区二区三区在线 | 91精品在线播放 | 夜夜爽99久久国产综合精品女不卡 | 国产欧美一区二区三区日本久久久 | 一区二区在线免费播放 | 久久久久免费精品国产 | 免费国产一区二区 | 国产精品18毛片一区二区 | 在线国产视频 | 午夜三级在线观看 | 夜夜草 | 精品香蕉一区二区三区 | 91精品久久久久久久久中文字幕 | 亚洲成人自拍 | 日韩欧美一级精品久久 | 免费视频一区 | 伊人伊人伊人 | 九色网址| 91视频在线看 | 亚洲第一在线 | 日本天天操 | 日韩高清中文字幕 | 日日夜夜精品视频 | 亚洲一区二区在线电影 | 中文字幕在线免费 | 亚洲精品久久久久中文字幕二区 |