各位好,小弟遇到了这样的问题:
- Java code
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); setContentView(R.layout.edit_contact); getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title); initVars(); initFields(); } private void initVars() { mTitle = (TextView) findViewById(R.id.title); mName = (EditText) findViewById(R.id.txt_name); <-----这一行报错 line:56 mMobile = (EditText) findViewById(R.id.txt_mobile); mHome = (EditText) findViewById(R.id.txt_home); mEmail = (EditText) findViewById(R.id.txt_email); mRelation = (EditText) findViewById(R.id.txt_relation); mBlog = (EditText) findViewById(R.id.txt_blog); mSave = (Button) findViewById(R.id.btn_save); mRes = getResources(); }
- XML code
<!-- name --> <LinearLayout android:orientation="horizontal" android:layout_margin="5dip" android:layout_width="fill_parent" android:layout_height="wrap_content"> <TextView android:layout_width="0dip" android:layout_height="wrap_content" android:layout_weight="2" android:text="@string/field_name"></TextView> <EditText android:id="@+id/txt_name" android:layout_width="0dip" android:layout_height="wrap_content" android:layout_weight="8" android:singleLine="true"></EditText> </LinearLayout>
E/AndroidRuntime( 1768): Caused by: java.lang.ClassCastException: android.widget.TextView
E/AndroidRuntime( 1768): at com.uery.contacts.EditContactActivity.initVars(EditContactActivity.java:56)
E/AndroidRuntime( 1768): at com.uery.contacts.EditContactActivity.onCreate(EditContactActivity.java:48)
E/AndroidRuntime( 1768): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
E/AndroidRuntime( 1768): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
E/AndroidRuntime( 1768): ... 11 more
运行的时候,会报如上的错误,明明类型是一样的啊,怎么破!?
PS:以前也有过这种情况,不知道怎么的,过一会它自己就好了-v-
------解决方案--------------------
project -- > clean ,就好了。