Android ArrayList的TypeToken错误

Android ArrayList的TypeToken错误,android,json,Android,Json,我正在努力学习本教程www.josecgomez.com/2010/05/03/android-put-custom-objects-in-listview/ 我从本地json文件中获取数据,而不是webservice。 我已经实现了几乎所有的东西,但我总是得到同样的错误。 日志显示: java.lang.NoClassDefFoundError: src.blablabla.List_Messages$1 at src.blablabla.soundboard.List_Messages.on

我正在努力学习本教程www.josecgomez.com/2010/05/03/android-put-custom-objects-in-listview/ 我从本地json文件中获取数据,而不是webservice。 我已经实现了几乎所有的东西,但我总是得到同样的错误。 日志显示:

java.lang.NoClassDefFoundError: src.blablabla.List_Messages$1
at src.blablabla.soundboard.List_Messages.onCreate(List_Messages.java:72)
第72行是:

Type collectionType = new TypeToken<ArrayList<messages>>(){}.getType();
Type collectionType=new-TypeToken(){}.getType();
我不熟悉类型和类型标记,我做错了什么

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

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());
    }
公共类列表\u消息扩展活动{
JSONArray myJsonArray=null;
字符串s=“”;
//将项目引用保留回main.xml的ListView
列表视图列表视图;
//用于保存ArrayList并在ListView上显示项的数组适配器
消息适配器阵列适配器;
//列表将承载我们的项目,并允许我们修改该阵列适配器
ArrayList messagesArray=null;
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity\u list\u消息);
//初始化列表视图
listView=(listView)findViewById(R.id.listView);
//初始化我们的ArrayList
messagesArray=newarraylist();
//初始化数组适配器请注意它是如何引用ress_list_row.xml布局的
arrayAdapter=newmessagesadapter(List_Messages.this,R.layout.ress_List_row,messagesArray);
//将上面的适配器设置为列表中的可选适配器
setAdapter(arrayAdapter);
//如果需要,传递参数,如果不需要,则按如下方式传递伪参数
Map params=新的HashMap();
参数put(“var”和“);
myJsonArray=来自JSonfiletoJSonarray(“mssg_source.txt”,this);
字符串响应=myJsonArray.toString();
尝试
{
//将响应解析到我们的对象中
Type collectionType=new-TypeToken(){}.getType();
//JSON需要一个列表,因此无法使用lstart中的ArrayList
List lst=new Gson().fromJson(响应,collectionType);
//现在我们有了这个列表,让我们把它添加到ArrayList中,它将保存我们的项目。
用于(消息m:lst)
{
messagesArray.add(m);
}
//由于我们已经修改了arrayList,现在需要通知适配器
//其数据已更改,因此会更新UI
arrayAdapter.notifyDataSetChanged();
}
捕获(例外e)
{
Log.d(“错误:,e.getMessage());
}

感谢您宝贵的时间

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