0

I am a newbie in android and I have a source code downloaded but it is not running can anyone help me. There is no my cross signature but also my program is not running and I am unable to know the error output from logcat this is my mainactivity code

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

This is my logcat output

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

Please Help me.

1
  • seems like you have no coding error..there is an issue with your pc/machine..dont fedup..be positive..give me your machine configuration...is your emulator freezing ? or machine got stucked ? please upload new version of eclipse and android sdk.. if your emulator isn't working please try to debug with your android phone... in android emulator is slow but phone is fast.. in iphone emulator is fast phone is slow... tc.. Commented Aug 24, 2012 at 4:58

1 Answer 1

2

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

That should give you something to start investigating.

This error means somewhere an object of type TextView is being cast to type ViewGroup. From the code that you have posted, I cannot see any such problems at one look. Could be an issue in your activity_main.xml. I hope your root tag is of type *Layout.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.