【发布时间】:2015-02-27 14:51:02
【问题描述】:
参考:Android:- How to Make dynamic HashMap Accessible in whole application? 我已经设置了一个 CustomHashMap(只是 3 个 LinkedHashMaps 的集合),以便我可以从 2 个活动中访问它,但我是 无法从 SecondActivity 访问它!删除 Manifest.xml 中的红色错误的唯一方法是设置以下行。如果我 使用 android:name="com.example.intents.CustomHashMap" (按照在线示例)我收到一条错误消息,说 'is not an enclosure 类'。
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher_icon"
android:label="@string/app_name"
android:theme="@style/CustomActionBarTheme"
android:name="com.example.intents.MainActivity$CustomHashMap"> //--- The system added the $ parts here.
<activity
....
protected CustomHashMap thisMap;
....
thisMap = (MainActivity.CustomHashMap)getApplication();
在 MainActivity 中,我可以执行 thisMap.getKeyValue(4) 之类的操作,但从 SecondActivity 中只返回 null。我觉得我好像 这里缺少一些非常简单的东西。有什么想法吗?
【问题讨论】:
-
你为什么不把它变成一个包含这些哈希图的静态类呢?您的错误是告诉您您的课程嵌套在第一个活动中。请发布此活动。
标签: android