2012-06-15 4 views
2

그래서 Android 앱을 개발 중이며 마지막 며칠 동안 을 가졌습니다.
나는이 오류가 반환의 문제로 인한 것이라고 stackoverflow 게시물을 읽었습니다 (예상 반환 값은 가져온 것이 아닙니다).Android : 일반 클래스로 인해 VerifyError

저는 이것이 String으로 형변환 된 일반 클래스로 인해서 누군가가 해결책을 찾고 있기를 바란다고 믿습니다! 나는 두 가지를 넣을 때

public void LoginBtn_OnClick(View v){ 
    ItemAdapter adapter = (ItemAdapter)this.itemListView.getAdapter(); 
    //Clearing the ListView 
    if(adapter != null) { 
     this.itemListView.setAdapter(null); 
    } 
    //Fetch the AplicationName 
    String username = this.editTextUsername.getText().toString(); 
    String appName = RESTClient.connect("ip/DevTest/WcfApi/Api1.svc/api1/appName", username); 

    try { 
     appName = (String)ProcessJson.ProcessResult(MessageType.GetAppName, appName); 
     appNameTextView.setText("Logged in as: " + appName); 
    } catch (MalformedJsonException e) { 
     e.printStackTrace(); 
     appNameTextView.setText("Cannot Login"); 
    } 
    catch (JsonSyntaxException e){ 
     e.printStackTrace(); 
     appNameTextView.setText("Cannot Login"); 
    } 

    //Fetch the itemList 
    String itemList = RESTClient.connect("ip/DevTest/WcfApi/Api1.svc/api1/items", username); 
    try{ 
     Item[] items = (Item[])ProcessJson.ProcessResult(MessageType.GetItemsList, itemList); 
     //Binding itemList to UI 
     //ItemAdapter itemAdapter = new ItemAdapter(this, R.layout.item_row, items); 
     //this.itemListView.setAdapter(itemAdapter); 

    } catch (MalformedJsonException e) { 
     e.printStackTrace(); 
     appNameTextView.setText("Cannot Login"); 
    } 
    catch (JsonSyntaxException e){ 
     e.printStackTrace(); 
     appNameTextView.setText("Cannot Login"); 
    } 
} 

나는 충돌을 피하기 위해 관리 :

이 일반 클래스 : I 클래스 캐스팅 곳에있다

public class ProcessJson { 
public enum MessageType{ 
    GetAppName, 
    GetItemsList 
} 
public static Object ProcessResult(MessageType messageType, String result) throws MalformedJsonException{ 
    Gson gson = new Gson(); 
    Object returnValue = null; 

    switch(messageType){ 
    case GetAppName : 
     returnValue = gson.fromJson(result, String.class); 
     return returnValue; 
    case GetItemsList : 
     returnValue = gson.fromJson(result, Item[].class); 
     return returnValue; 
    } 

    return null; 
} 
} 

입니다 try/catch 블록을 주석으로 사용하십시오. 이것이 내가 ProcessJson 클래스에 의한 것이라고 믿게 만드는 원인입니다.

미리 감사드립니다.

+0

아무도 없습니까? :/나는 몇 가지 테스트를 해봤지만 컴파일러가 멈춘 코드의 어느 지점에서 보려고했으나 실제로는 코드 시작 부분에 도달하지 못했고 실행을 시작하기 전에 직접 충돌합니다. –

답변

0

시도하십시오 this 해결 방법을 사용하면 문제를 해결할 수 있습니다.

관련 문제