android程序没有在eclipse上运行

时间:2012-08-24 04:24:54

标签: android-layout

我是Android的新手,我已经下载了源代码,但它没有运行,任何人都可以帮助我。没有我的交叉签名,但我的程序没有运行,我无法知道logcat的错误输出 这是我的主要活动代码

public class MainActivity extends Activity {

/** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.activity_main);

       TextView JsonSrc = (TextView)findViewById(R.id.json_src);
       TextView JsonResult = (TextView)findViewById(R.id.json_result);
       /*
        * JSON:
        * {"id":12,"name":12,"status":"ok","volumes":[{"id":17592,"name":"root","status":"ok"}]}
        */
       final String customJSON = "{\"id\":12,\"name\":12,\"status\":\"ok\",\"volumes\":[{\"id\":17592,\"name\":\"root\",\"status\":\"ok\"}]}";
       JsonSrc.setText(customJSON);
       try {
   JSONObject jsonObject = new JSONObject(customJSON);
   String myId = jsonObject.getString("id");
   String myName = jsonObject.getString("name");
   String myStatus = jsonObject.getString("status");
   String stringJsonResult = "id: " + myId + "\n"
        + "name: " + myName + "\n"
        + "status: " + myStatus;


   JSONArray jsonArray = jsonObject.getJSONArray("volumes");
   JSONObject arrayElement_0 = jsonArray.getJSONObject(0);
   String ele0_id = arrayElement_0.getString("id");
   String ele0_name = arrayElement_0.getString("name");
   String ele0_status = arrayElement_0.getString("status");
   stringJsonResult += "\n\nArray Element 0 - \n"
        + "id: " + ele0_id + "\n"
        + "name: " + ele0_name + "\n"
        + "status: " + ele0_status;

   JsonResult.setText("\n" + stringJsonResult);

  } catch (JSONException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
   Toast.makeText(MainActivity.this, e.toString(), Toast.LENGTH_LONG).show();
  }
   }
}

这是我的logcat输出

08-24 10:01:56.662: E/AndroidRuntime(798): java.lang.RuntimeException: Unable to start  activityComponentInfo{com.mokshya.androidparse/com.mokshya.androidparse.MainActivity}: java.lang.ClassCastException: android.widget.TextView cannot be cast to android.view.ViewGroup

请帮助我。

1 个答案:

答案 0 :(得分:2)

java.lang.ClassCastException: android.widget.TextView cannot be cast to android.view.ViewGroup

那应该给你一些开始调查的东西。

此错误表示类型为TextView的对象正在转换为ViewGroup类型。从您发布的代码中,我一眼就看不到任何此类问题。可能是您activity_main.xml中的问题。我希望你的root标签的类型是* Layout。