久久久久久久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屋-程序員
主站蜘蛛池模板: 国产视频久久 | 18成人在线观看 | 免费久久99精品国产婷婷六月 | 欧美精品在线一区 | 成人午夜激情 | 99精品欧美一区二区三区综合在线 | 国产午夜精品久久久久 | 久久福利电影 | 欧美高清dvd | 一区二区三区视频 | 亚洲一区免费视频 | 欧美一区不卡 | 中文字幕在线视频网站 | 欧洲视频一区二区 | 久干网 | 免费在线观看91 | 中文字幕在线一区二区三区 | 成人av在线播放 | 亚洲aⅴ| 性国产丰满麻豆videosex | 夜夜摸天天操 | 成人一区二区三区在线 | 99精品久久久久久 | 精品无码久久久久久国产 | 亚洲免费在线观看视频 | 51ⅴ精品国产91久久久久久 | 中文av字幕 | 日韩视频―中文字幕 | 久久97精品| 91久久国产综合久久 | 91视频国产一区 | 七七婷婷婷婷精品国产 | av日日操| 欧美日韩不卡在线 | 午夜爽爽男女免费观看hd | av大片 | 欧美一级片a| 国产乱码精品一区二区三区中文 | 国产在线高清 | 夜夜骑综合 | 天天影视色综合 |