2

だから私はAndroidアプリを開発しています.私はjava.lang.VerifyErrorここ数日間持っています.
このエラーはリターンの問題が原因であるというスタックオーバーフローの投稿を読みました(期待されるリターンは取得したものではありません)。

だから私はこれが文字列にキャストされたジェネリッククラスによるものだと信じており、誰かが解決策を持っていることを望んでいました!

これはジェネリック クラスです。

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

2 つの try/catch ブロックをコメントとして入れると、なんとかクラッシュを回避できました。これが、問題が ProcessJson クラスによるものであると私が信じるようになった理由です。

前もって感謝します。

4

1 に答える 1

0

この回避策を試してください。問題が解決する場合があります。

于 2015-03-01T13:57:06.903 に答える