通过控制器访问 HashMap 时出现问题
我在通过 Controller 类从 HashMap 返回值时遇到一些麻烦,
public class Controller {
private User user;
private FileRead fileRead;
private ICS1Activity start;
public Controller(){
user = new User();
fileRead = new FileRead();
start = new ICS1Activity();
}
public User getUser() {
return user;
}
public FileRead getFileRead() {
return fileRead;
}
public ICS1Activity getStart() {
return start;
}
}
public class FileRead {
Controller controller;
private HashMap <String,String> userList = new HashMap <String,String>();
public HashMap<String, String> getUserList() {
userList.put("fredkr", "value");
return userList;
}
public void setUserList(HashMap<String, String> userList) {
this.userList = userList;
}
然后在第三个类(ICS1Activity)中我想将 TextView 字段的文本设置为 HashMap 的值,我尝试使用
testTxt 执行此操作。 setText(controller.getFileRead().getUserList().get("fredkr"));
但这不起作用,程序崩溃了,我很确定这与我访问 HashMap 的方式有关,如果有人可以帮助我,我将非常感激(我知道它一团糟......)
问候,
设法解决了我在这里遇到的问题,但我又遇到了类似的问题。我想我需要阅读控制器和 MVC 结构。有人有什么好的阅读技巧、视频或其他东西吗?
Im having some troubles with returning values from a HashMap trough a Controller class,
public class Controller {
private User user;
private FileRead fileRead;
private ICS1Activity start;
public Controller(){
user = new User();
fileRead = new FileRead();
start = new ICS1Activity();
}
public User getUser() {
return user;
}
public FileRead getFileRead() {
return fileRead;
}
public ICS1Activity getStart() {
return start;
}
}
public class FileRead {
Controller controller;
private HashMap <String,String> userList = new HashMap <String,String>();
public HashMap<String, String> getUserList() {
userList.put("fredkr", "value");
return userList;
}
public void setUserList(HashMap<String, String> userList) {
this.userList = userList;
}
then in a third class (ICS1Activity) i want to set the the text of a TextView field to the value of the HashMap, I've tried doing this with
testTxt.setText(controller.getFileRead().getUserList().get("fredkr"));
But this does not work and the program crashes, I'm quite sure it has to do with how i access the HashMap, if someone can help me it would me much appreciated (i know its a mess...)
Regards,
Manage to solve the problem i had here, but I'm stuck again with similar issue. think i need to read up on controller and MVC structure. Anyone got any good reading tips, videos or something?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
日志猫告诉您有些内容为空,所以也许您忘记初始化控制器?
看一下这个文件:
fredkr.ics1.ICS1Activity.onCreate(ICS1Activity.java:46)
The Log cat tells you that something is null, so maybe you forgot to initialize the controller?
Have a look at this file:
fredkr.ics1.ICS1Activity.onCreate(ICS1Activity.java:46)