9

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>
3
  • on which line do you get the error? Commented Oct 3, 2011 at 10:09
  • name = (MultiAutoCompleteTextView) findViewById(R.id.multiAutoCompleteTextView1); Commented Oct 3, 2011 at 10:11
  • 1
    This may sound weird, but all i can see is problem with incomplete build. edit some of your code in the file that is generating this error. and build it again. Commented Oct 3, 2011 at 10:13

1 Answer 1

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

have fun ^^!

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.