【问题标题】:SimpleExpandableListAdapter issue in android applicationandroid 应用程序中的 SimpleExpandableListAdapter 问题
【发布时间】:2013-09-02 08:47:49
【问题描述】:

我尝试更改从 android 2 传递到 android 4 的源代码。代码没有让我出错,应用程序启动。但一开始有一个登录。当我单击“登录”时,应用程序崩溃。 logcat 显示SimpleExpandableListAdapter 有问题。这是使用 SimpleExpandableListAdapter 的代码部分:

expListAdapter = new SimpleExpandableListAdapter(_ContactScreen_object,
                _groupSections, // groupData describes the first-level entries
                R.layout.group_row, // Layout for the first-level entries
                new String[] { "sectionName" }, // Key in the groupData maps to
                // display
                new int[] { R.id.groupname }, // Data under "friendName" key
                // goes into this TextView
                _result, // childData describes second-level entries
                R.layout.child_row, // Layout for second-level entries
                new String[] { "friendName", "status" }, // Keys in childData
                // maps to display
                new int[] { R.id.childname, R.id.rgb } // Data under the keys
        // above go into these
        // TextViews
        ) 

日志猫:

您认为问题在于代码旧吗? SimpleExpandableListAdapter的结构现在不一样了?我有什么要改变的?

【问题讨论】:

  • 请发布异常堆栈跟踪。

标签: java android sdk android-listview expandablelistadapter


【解决方案1】:

Context 参数_ContactScreen_objectnull。这是SimpleExpandableListAdapter.java的第210行:

mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

需要更多代码上下文(原文如此)才能提供进一步帮助。

【讨论】:

  • 如果您可以自己解决null 上下文,我不需要额外的代码。否则,请包含显示 _ContactScreen_object 是什么以及它是如何初始化的代码。
  • 你是这个意思吗? public static ContactScreen _ContactScreen_object = null;
  • 是的,这里它被显式初始化为null。您需要向SimpleExpandableListAdapter 构造函数传递一个有效的、非空的Context 对象,例如对您的Activity 的引用。
  • 但是您认为问题出在我发布的代码部分吗?
  • 但是,在第 95 行有 import org.apache.http.client.HttpClient; 并给我一个错误
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-10-02
  • 2012-10-29
  • 1970-01-01
相关资源
最近更新 更多