2

java.lang.VerifyError因此,我正在开发一个 Android 应用程序,并且在过去的几天里我一直在开发。
我在 stackoverflow 帖子中读到,这个错误是由于退货中的问题造成的(预期的回报不是它得到的回报)。

所以我相信这是由于一个泛型类被转换成一个字符串,我希望有人有一个解决方案!

这是通用类:

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;
}
}

这是我上课的地方:

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");
    }
}

当我将两个 try/catch 块作为注释时,我设法避免了崩溃。这就是让我相信问题出在 ProcessJson 类的原因。

提前致谢。

4

1 回答 1

0

试试这个解决方法,它可能会解决你的问题。

于 2015-03-01T13:57:06.903 回答