Hello everyone,
Can anyone tell me how to get a value for a key in java ?
I need it in my extension.
Any help is appreciated !
Thanks.
Want to get values from appinventor from dictionaries to extension? do you just need to save something in the extension as a key-value?
You can use HashMap:
HashMap<String, Integer> saveData = new HashMap<String, Integer>();
Use:
saveData.put("apple",2);
saveData.remove("apple");
saveData.containsKey("apple");
saveData.get("apple");
Any imports needed ?
java.util.HashMap
Thanks, trying it now itself and I'll tell you the result.
Your method is working. Thank you !
Oops, its showing 'cannot find symbol' - 'get'. How to solve it ?
What and where does it show? PrintScren and show code.
[javac] /compiler/androidX/src/kppin/com/aquib/searchy/Searchy.java:76: error: cannot find symbol
[javac] res = text.get("answer");
[javac] ^
[javac] symbol: method get(String)
[javac] location: variable text of type String
[javac] 1 error
It's not a problem with "get", just java basics ...
String res = text.get("answer");
Tried that too......
Not working.
Make such code and compile. "Not working" is not enough.
If the value is of type Integer, it must be:
int res = text.get("...");
[javac] /compiler/androidX/src/CsZdF/com/aquib/searchy/Searchy.java:75: error: cannot find symbol
[javac] String res = text.get("answer");
[javac] ^
[javac] symbol: method get(String)
[javac] location: variable text of type String
[javac] 1 error
Show me the HashMap initialization line.
HashMap<text, text> saveData = new HashMap<text, text>();
Is it consistent with what I wrote in post 2?
HashMap<String, String> text = new HashMap<String, String>();
Now the key and value must be of type String.
And now:
text.put("apple", "two");
text.remove("apple");
text.containsKey("apple");
String value = text.get("apple");
Its string only.
You are given as on a tray, copy and paste - must work.
Just a min.... trying...
Its showing cannot find symbol - 'HashMap'
[javac] /compiler/androidX/src/KyBYH/com/aquib/searchy/Searchy.java:75: error: cannot find symbol
[javac] HashMap text = new HashMap();
[javac] ^
[javac] symbol: class text
[javac] /compiler/androidX/src/KyBYH/com/aquib/searchy/Searchy.java:75: error: cannot find symbol
[javac] HashMap text = new HashMap();
[javac] ^
[javac] symbol: class text
[javac] /compiler/androidX/src/KyBYH/com/aquib/searchy/Searchy.java:75: error: cannot find symbol
[javac] HashMap text = new HashMap();
[javac] ^
[javac] symbol: class text
[javac] /compiler/androidX/src/KyBYH/com/aquib/searchy/Searchy.java:75: error: cannot find symbol
[javac] HashMap text = new HashMap();
[javac] ^
[javac] symbol: class text
[javac] 4 errors