Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ClassCastException: android.widget.EditText

Tags:

android

I always get the error:

10-03 09:55:44.517: ERROR/AndroidRuntime(819): Caused by: java.lang.ClassCastException: android.widget.EditText

In my code I don't have the word EditText so why does that error occur?

The MultiAutoCompleteTextView was a EditText before. Please help

Code:

public class AddPizza extends Activity {
    private ImageView iv;
    private MultiAutoCompleteTextView name;
    private RatingBar rating;
    private SQLiteDatabase myDB;
    final String MY_DB_NAME = "PizzaCounter";
    final String MY_DB_TABLE = "Pizza";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.addpizza);

        iv = (ImageView) findViewById(R.id.imageViewPizza);
        name = (MultiAutoCompleteTextView) findViewById(R.id.multiAutoCompleteTextView1);
        rating = (RatingBar) findViewById(R.id.ratingBar1);
        Button bt = (Button) findViewById(R.id.bt_addform);

        iv.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                startActivityForResult(new Intent(MediaStore.ACTION_IMAGE_CAPTURE),1337);
            }
        });

        bt.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                addData();
                finish();
            }


        });

         addAutoSuggest();
    }
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == 1337) {
            iv.setImageBitmap((Bitmap) data.getExtras().get("data"));
        }
    }
    private void addData() {
        myDB = this.openOrCreateDatabase(MY_DB_NAME, MODE_PRIVATE, null);
        //myDB.execSQL("DROP TABLE " + MY_DB_TABLE);
        myDB.execSQL("CREATE TABLE IF NOT EXISTS " + MY_DB_TABLE
                    + " (_id integer primary key autoincrement, name varchar(100), rate integer(1), eattime varchar(100),image BLOB)"
                    +";");
        if(!name.getText().equals("") && rating.getRating()!=0.0)
        {
            Log.e("XXX", "Enter_Insert");
            Calendar cal = Calendar.getInstance(); 
            DateFormat formatter = new SimpleDateFormat(); 
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            Bitmap bt = ((BitmapDrawable)iv.getDrawable()).getBitmap();
            bt.compress(Bitmap.CompressFormat.PNG, 100, out);
            ContentValues cv = new ContentValues();
            cv.put("image", out.toByteArray());            
            cv.put("name", name.getText().toString());
            cv.put("eattime", formatter.format(cal.getTime()));
            cv.put("rate", rating.getRating());
            myDB.insert(MY_DB_TABLE, null, cv);

            //myDB.execSQL("INSERT INTO "+ MY_DB_TABLE + "(name,rate,eattime,image) VALUES +" +  + ", " ++ " , datetime('now', 'localtime'), " );
        }

    }

    void addAutoSuggest ()

    {
         myDB = this.openOrCreateDatabase(MY_DB_NAME, MODE_PRIVATE, null);
         ArrayList<String> list = new ArrayList<String>();
         Cursor cursor = this.myDB.query(MY_DB_TABLE, new String[] {"name"},null,null,null,null,null,null);
          if (cursor.moveToFirst()) {
             do {
                list.add(cursor.getString(0)); 
                } 
             while (cursor.moveToNext());
          }
          if (cursor != null && !cursor.isClosed()) {
             cursor.close();
          }
        name.setAdapter( new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, list));
    }


}

Layout:

<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent" android:orientation="vertical">
    <TextView android:text="Name" android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
    <MultiAutoCompleteTextView android:id="@+id/multiAutoCompleteTextView1" android:layout_height="wrap_content" android:text="MultiAutoCompleteTextView" android:layout_width="fill_parent"></MultiAutoCompleteTextView>

    <TextView android:text="Bewertung" android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
    <RatingBar android:id="@+id/ratingBar1" android:layout_width="wrap_content" android:layout_height="wrap_content"></RatingBar>
    <TextView android:text="Foto hinzufügen" android:id="@+id/textView3" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
    <ImageView android:layout_height="wrap_content" android:src="@drawable/icon" android:layout_width="wrap_content" android:id="@+id/imageViewPizza"></ImageView>
    <RelativeLayout android:id="@+id/relativeLayout1" android:layout_width="fill_parent" android:layout_height="fill_parent">
        <Button android:text="hinzufügen" android:layout_height="wrap_content" android:id="@+id/bt_addform" android:layout_alignParentBottom="true" android:layout_width="fill_parent"></Button>
    </RelativeLayout>
</LinearLayout>
like image 387
test123123 Avatar asked Oct 03 '11 09:10

test123123


1 Answers

  1. Clean project
  2. Save files
  3. Build & Run

have fun ^^!

like image 80
Pete Houston Avatar answered Nov 08 '22 02:11

Pete Houston