2012-12-10 2 views
0

이 자습서를 따르려고합니다. www.josecgomez.com/2010/05/03/android-putting-custom-objects-in-listview/ webservice 대신 로컬 json에서 데이터를 가져옵니다. 파일. 거의 모든 것을 구현했지만 항상 같은 오류가 발생합니다. 로그 캣 쇼 :TypeToken 오류 ArrayList

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(); 

나는, 유형 및 TypeTokens에 익숙하지 않은 나는 그것이 내가 잘못하고 있어요 무엇?

답변

0

는 단지 것 같은데, 여러분의 귀중한 시간 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()); 
    } 

감사가 제대로 내 프로젝트에 포함되지 않았습니다 라인을 포함, 아래에있는 내 코드의 나머지 부분입니다, 당신에게 더 많은 컨텍스트를 부여하려면 더 이상 오류가 발생하지 않습니다. 뷰가 비어있어 메시지를 표시하지 않기 때문에 여전히 문제가 있습니다.