首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ArrayList出现TypeToken错误

ArrayList出现TypeToken错误
EN

Stack Overflow用户
提问于 2012-12-11 03:57:31
回答 1查看 689关注 0票数 0

我正在尝试遵循本教程的www.josecgomez.com/2010/05/03/android-putting-custom-objects-in-listview/,而不是webservice,我正在从本地json文件中获取数据。我已经实现了几乎所有的东西,但我总是得到相同的错误。logcat显示:

代码语言:javascript
复制
java.lang.NoClassDefFoundError: src.blablabla.List_Messages$1
at src.blablabla.soundboard.List_Messages.onCreate(List_Messages.java:72)

第72行是:

代码语言:javascript
复制
Type collectionType = new TypeToken<ArrayList<messages>>(){}.getType();

我不熟悉类型和TypeTokens,我哪里做错了?

为了给您提供更多上下文,下面是我的代码的其余部分,包括第72行

代码语言:javascript
复制
public class List_Messages extends Activity {
JSONArray myJsonArray = null;
String s = "";

//ListView that will hold our items references back to main.xml
ListView listView;
//Array Adapter that will hold our ArrayList and display the items on the ListView
MessagesAdapter arrayAdapter;     
//List that will host our items and allow us to modify that array adapter
ArrayList<messages> messagesArray=null;



@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_list_messages);
    //Initialize ListView
    listView = (ListView)findViewById(R.id.listView);

  //Initialize our ArrayList
    messagesArray = new ArrayList<messages>();
    //Initialize our array adapter notice how it references the ress_list_row.xml layout
    arrayAdapter = new MessagesAdapter(List_Messages.this, R.layout.ress_list_row, messagesArray);

  //Set the above adapter as the adapter of choice for our list
    listView.setAdapter(arrayAdapter);

  //Pass the parameters if needed , if not then pass dummy one as follows
    Map<String, String> params = new HashMap<String, String>();
    params.put("var", "");

    myJsonArray = fromJsonFileToJsonArray("mssg_source.txt", this);  
    String response = myJsonArray.toString();

    try
    {
        //Parse Response into our object
        Type collectionType = new TypeToken<ArrayList<messages>>(){}.getType();

        //JSON expects an list so can't use our ArrayList from the lstart
        List<messages> lst= new Gson().fromJson(response, collectionType);

        //Now that we have that list lets add it to the ArrayList which will hold our items.
        for(messages m : lst)
        {
            messagesArray.add(m);
        }

        //Since we've modified the arrayList we now need to notify the adapter that
        //its data has changed so that it updates the UI
        arrayAdapter.notifyDataSetChanged();
    }
    catch(Exception e)
    {
        Log.d("Error: ", e.getMessage());
    }

感谢您的宝贵时间

EN

回答 1

Stack Overflow用户

发布于 2012-12-11 20:40:57

看起来jar没有正确地包含在我的项目中,它现在不再触发错误。但是,我仍然有一个问题,因为视图是空的,它不能正常显示消息

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13808213

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档