具有自己的数据类型的地图(Java)
Map<String,MyData> map = new HashMap<String,MyData>();
...
static class MyData {
String theString;
Bitmap theBitmap;
int theInt;
...
}
我怎样才能把数据放到这张地图上???
map.put("xxx", new MyData()); // Does not work
谢谢;)
是的,抱歉我问错了问题;)
我想知道如何在...中写入dada,
例如theString =“aaa”,theInt = 22等...
谢谢
Map<String,MyData> map = new HashMap<String,MyData>();
...
static class MyData {
String theString;
Bitmap theBitmap;
int theInt;
...
}
How can I put data in this map???
map.put("xxx", new MyData()); // Does not work
Thank you ;)
Yes sorry I aked the wrong question ;)
I ment how can I write dada in in ...
like for theString="aaa", theInt=22, etc....
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
看看这个是不是更好。
See if this is better.
当然可以:
编译良好,并打印:
Sure it works:
This compiles fine, and prints:
也许你想做:
Maybe you want to do :
根据您的评论(呃...答案?)我猜测您忘记向 MyData 类添加构造函数。
构造函数应该类似于:
但是,当提出此类问题时,请包含错误消息的文本,以便我们不必猜测给您答案。另外,如果您对问题进行了更改,请将其放在问题中,请勿回复(stackoverflow 并不真正用作讨论板:-)
Based on your comment (er... answer?) I am going to guess that you forgot to add a constructor to the MyData class.
The constructor should be something like:
However, when asking this kind of question please include the text of the error message so that we don't have to guess to give you answers. Also if you have changes to your question put them up in the question don't reply (stackoverflow isn't really used as a discussion board :-)