【问题标题】:Accessing tabhost's JSONObject or JSONArray访问 tabhost 的 JSONObject 或 JSONArray
【发布时间】:2012-04-19 20:43:53
【问题描述】:

我要做的只是拥有一个可以从子选项卡访问的 JSONObject,以便我可以将信息放入其中。

 public class Example extends TabActivity{
            private JSONObject testtt = new JSONObject();
        public void writeJSON(String key, String value) throws JSONException {
         testtt.put(key, value);
         }
        public String getJSON(){
            return testtt.toString();
        }
     public void onCreate(Bundle savedInstanceState) {
                    super.onCreate(savedInstanceState);
            setContentView(R.layout.example);
                    //Creating the tabs and everything
                    //Is Here
     }
    }

我有下一个/上一个按钮,而不是来回导航标签 选项卡之一:

public void onClick(View v) {
 //Pre-alertDialog.setmessage stuff here.
   alertDialog.setMessage(Example.this.getJSON());
// Example.this gives this error: No enclosing instance of the type Example is accessible in scope
}

我已经尝试了很多替代的东西,并且已经到了寻求帮助的地步(对我来说非常罕见)。 很明显,我对 android 开发比较陌生。

编辑: 通过类扩展应用程序尝试全局变量时{

【问题讨论】:

标签: android json tabs arraylist android-tabhost


【解决方案1】:

最简单的做法是使用 Application 对象:将 JSON 粘贴到 Application 对象中的共享变量上,然后在您的其他活动中从那里访问它。

【讨论】:

  • 我试过了...强制关闭(我也将它作为应用程序添加到清单中)
  • 什么是崩溃错误?从 logcat 添加整个异常跟踪。
  • 这可能需要一段时间......愚蠢的我删除了所有代码而不是注释掉。
  • logcat screenshot...它在这行代码处中断:Jason jason = (Jason)getApplicationContext();
猜你喜欢
  • 2017-05-01
  • 2021-09-28
  • 2015-09-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多