Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/223.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 使用自定义视图时findViewById中的ClassCastException_Android_Android Layout - Fatal编程技术网

Android 使用自定义视图时findViewById中的ClassCastException

Android 使用自定义视图时findViewById中的ClassCastException,android,android-layout,Android,Android Layout,我正在使用自定义文本视图。但是当我使用find view by Id检索它时,我得到了ClassCastException。我在XML文件中使用它,如下所示: 使用下面的代码代替上面的代码 <com.android.smsapp.MsgTextView android:id="@+id/text" additional parameters here....> </com.android.smsapp.MsgTextView>

我正在使用自定义文本视图。但是当我使用find view by Id检索它时,我得到了ClassCastException。我在XML文件中使用它,如下所示:


使用下面的代码代替上面的代码

<com.android.smsapp.MsgTextView 
          android:id="@+id/text"
          additional parameters here....>
</com.android.smsapp.MsgTextView>


只需在xml部分中使用e com.android.smsapp.MsgTextView而不是textview,并确保您的类MsgTextView扩展了textview。。但是现在我得到了“03-19 13:03:30.632:E/AndroidRuntime(22775):java.lang.RuntimeException:无法启动活动组件信息{com.android.smsapp/com.android.smsapp.smsapp活动}:android.view.InflateException:二进制XML文件行#22:错误膨胀类com.android.smsapp.MsgTextView”您是否将MsgTextView放入正确的软件包,即com.android.smsapp??请对此进行交叉检查,然后重试…仍然存在问题。。。一切看起来都很好。。。已粘贴MsgTextView类
03-19 14:30:41.476: E/AndroidRuntime(24089): Caused by: java.lang.NoSuchMethodException: MsgTextView(Context,AttributeSet).. But I have defined this constructor. 
<com.android.smsapp.MsgTextView 
          android:id="@+id/text"
          additional parameters here....>
</com.android.smsapp.MsgTextView>