0

Whenever I run this application I keep getting this Error .

11-26 17:38:52.973: E/AndroidRuntime(2220): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.footballtesting/com.example.footballtesting.MainActivity}: java.lang.ClassCastException: android.widget.ImageButton cannot be cast to android.widget.TextView

Thats My XML Code:

<RelativeLayout
    android:id="@+id/relativeLayout1"
    android:layout_width="wrap_content"
    android:layout_height="150dp"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="94dp" >

    <ImageButton
        android:id="@+id/imgbtn_lsave"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:background="@null"
        android:src="@drawable/btn1" />

    <EditText
        android:id="@+id/txt_teamID"
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:layout_above="@+id/imgbtn_lsave"
        android:layout_alignParentRight="true"
        android:layout_marginBottom="24dp"
        android:background="#ffffff"
        android:ems="10"
        android:inputType="textPersonName"
        android:paddingTop="10dp" >

        <requestFocus />
    </EditText>

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/txt_teamID"
        android:layout_alignBottom="@+id/txt_teamID"
        android:layout_alignParentLeft="true"
        android:layout_marginLeft="16dp"
        android:text="チームID"
        android:textColor="#ffffff" />

</RelativeLayout>

<RelativeLayout
    android:id="@+id/Relativelayoutrequest"
    android:layout_width="wrap_content"
    android:layout_height="120dp"
    android:layout_alignLeft="@+id/relativeLayout1"
    android:layout_below="@+id/relativeLayout1" >

    <TextView
        android:id="@+id/layout2textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="21dp"
        android:text="チームから参加要請があります"
        android:textColor="#ffffff"
        android:textSize="18dp" />

    <ImageButton
        android:id="@+id/imgbtn_layout2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/layout2textView1"
        android:layout_centerHorizontal="true"
        android:background="@null"
        android:src="@drawable/btn2" />
</RelativeLayout>

<TextView
    android:id="@+id/textView1"
    android:layout_width="288dp"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/relativeLayout1"
    android:layout_alignTop="@+id/relativeLayout1"
    android:text="   参加したいチームのIDを入カしてください"
    android:textColor="#ffffff" />

Thats My Java code: package com.example.footballtesting;

import java.util.ArrayList;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONException;
import org.json.JSONObject;
import com.example.footballtesting.CustomHttpClient;
import android.os.Bundle;
import android.os.StrictMode;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.RelativeLayout;

import android.widget.TextView;

public class MainActivity extends Activity {

TextView txt_view1;
TextView txt_view3;
TextView txt_view2;
EditText txt_teamID;
ImageButton btn_save;
ImageButton btn_show;
RelativeLayout Relativelayoutrequest;



@Override
protected void onCreate(Bundle savedInstanceState) {





    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);


    txt_view1=(TextView)findViewById(R.id.textView1);
    txt_view2=(TextView)findViewById(R.id.textView2);
    txt_view3=(TextView)findViewById(R.id.layout2textView1);
    txt_teamID=(EditText)findViewById(R.id.txt_teamID);
    btn_save=(ImageButton)findViewById(R.id.imgbtn_lsave);
    btn_show=(ImageButton)findViewById(R.id.imgbtn_layout2);
    Relativelayoutrequest=(RelativeLayout)findViewById(R.id.Relativelayoutrequest);
    checkOnCreate();

}

public void checkOnCreate()
{

    StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
    .detectDiskReads().detectDiskWrites().detectNetwork() 
    .penaltyLog().build());
    Relativelayoutrequest=(RelativeLayout)findViewById(R.id.Relativelayoutrequest);
    String response=null;
    String st=null;
    String str=null;
    String memberID="000000011";

    int status=1;
    //To pass to php
    ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
    postParameters.add(new BasicNameValuePair("userID",memberID

    ArrayList<NameValuePair> pp = new ArrayList<NameValuePair>();
    postParameters.add(new BasicNameValuePair("userID","409"));
    try {

          st=CustomHttpClient.executeHttpGet     ("http://192.168.200.14/football365/DBConnection.php");
          str= CustomHttpClient.executeHttpPost(
                     "http://192.168.200.14/football365/responseJson.php",
                      pp);
         response = CustomHttpClient.executeHttpPost(
                 "http://10.0.2.2/football365/checkRequestFromTeam.php",
                  postParameters);
        }
   catch (Exception e) {

        e.printStackTrace();
    }



    String result = response.toString();
    try{

        JSONObject jArray = new JSONObject (result);
        for(int i=0;i<jArray.length();i++){

              status=jArray.getInt("requestStatus");
        }
}
catch(JSONException e){
        Log.e("log_tag", "Error parsing data "+e.toString());
}


    status=1;
    if(status==0){

        if(Relativelayoutrequest.getVisibility()==View.VISIBLE){
            Relativelayoutrequest.setVisibility(View.GONE);
        }
      else{
        if(Relativelayoutrequest.getVisibility()==View.INVISIBLE){
            Relativelayoutrequest.setVisibility(View.VISIBLE);

        }
}

}

} }

7
  • 1
    once clean your project and try again... Commented Nov 26, 2013 at 11:15
  • both post and get should be executed in a thread or asynctask or use volley Commented Nov 26, 2013 at 11:17
  • Clean the project and run again!! Commented Nov 26, 2013 at 11:18
  • ids are unique i think . @ Raghunandan >> I dunno how to execute in a thread or asynctask or use volley :( Commented Nov 26, 2013 at 11:19
  • Use Asytask instead of using StrictMode Commented Nov 26, 2013 at 11:21

2 Answers 2

8

Code Look Fine ...Clean your Project & Run

Hope this could help Alt + P + N--->Eclipse

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

2 Comments

Thanks . It worked . I Cleaned The project and It worked :) Really Really Thanks
If you have added proguard obfuscation, then clean of project is very much required.
0

Go to project and select Clean and then select your project from a list. It should do the trick.

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.