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.
java.lang.ClassCastException: android.widget.TextView cannot be cast to android.view.ViewGroupThat should give you something to start investigating.
This error means somewhere an object of type
TextViewis being cast to typeViewGroup. From the code that you have posted, I cannot see any such problems at one look. Could be an issue in youractivity_main.xml. I hope your root tag is of type *Layout.