久久久久久久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 | 亚洲成人精品一区 | 午夜性色a√在线视频观看9 | 日本视频免费观看 | 91高清在线视频 | 天天精品在线 | 国产精品99久久久久久动医院 | 国产成人免费视频网站视频社区 | 久久精品这里精品 | 国内自拍偷拍一区 | 欧美日韩国产传媒 | 一区二区免费在线 | 一级片av | 精品久久久久香蕉网 | 自拍视频在线观看 | 国产片侵犯亲女视频播放 | 欧美网站一区 | 欧美国产精品久久久 | 免费国产黄网站在线观看视频 | 99热这里| 成人久久 | 中文字幕日韩欧美一区二区三区 | 国产91在线 | 亚洲 | 国产精品夜色一区二区三区 | 亚洲精品久久久 | 国产亚洲精品精品国产亚洲综合 | 国外成人在线视频网站 | 91久久精品国产 | 国产中的精品av涩差av | 亚洲国产成人久久综合一区,久久久国产99 | 亚洲成人黄色 | 成人免费网站在线 | www.4虎影院| 国产精品激情 | 曰批视频在线观看 | 欧美精品一区二区在线观看 | 欧美九九| www操操| 丝袜一区二区三区 | 久草在线在线精品观看 |