2012-03-18 13 views
0

私はカスタムTextViewを使用しています。しかし、私がIdでビューを見つけることを使用してそれを取得するとき、私はClassCastExceptionを取得します。カスタムビューを使用中にfindViewByIdでClassCastExceptionが発生する

<View class="com.android.smsapp.MsgTextView" android:id="@+id/text"

そして、このようなjavaファイルでそれを使用した:私はこのようなXMLファイルでそれを使用しています。

MsgTextView text = (MsgTextView) row.findViewById(R.id.text);

私が間違って何をしているのですか?


@Pavandroid

私は私が適切にチェックすると、LogCatではなく、上記の1行

03-19 14:30:41.476: E/AndroidRuntime(24089): Caused by: java.lang.NoSuchMethodException: MsgTextView(Context,AttributeSet).. But I have defined this constructor. 
+1

だけusee com.android.smsapp.MsgTextViewとは –

答えて

1

を示している正しいファイルも

package com.android.smsapp; 

    import android.content.Context; 
    import android.util.AttributeSet; 
    import android.widget.TextView; 

    public class MsgTextView extends TextView { 
    private String sender; 

    MsgTextView(Context c){ 
     super(c); 
    } 

    MsgTextView(Context context, AttributeSet attrs) { 
     super(context, attrs); 
    } 

    MsgTextView(Context context, AttributeSet attrs, int defStyle) { 
     super(context, attrs, defStyle); 
    } 

    public void setSender(String s) { 
     sender = s; 
    } 

    public String getSender() { 
     return (sender); 
    } 
}` 

にそれが含まれていますコードは以下のコードを使用します。代わりに、XMLの部分でのTextViewの

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

はそれを試みたのTextViewクラスのMsgTextViewが伸びることを確認します..しかし、今、私は3月19日13」取得しています:03:30.632: E/AndroidRuntime(22775):java.lang.RuntimeException:アクティビティを開始できませんComponentInfo {com.android.smsapp/com.android.smsapp.SMSAppActivity}:android.view.InflateException:バイナリXMLファイルの行#22: com.android.smsapp.MsgTextView " – Sumit

+0

MsgTextViewを適切なパッケージ、つまりcom.android.smsapp ??に配置しますか?これをチェックして、もう一度やり直してください。 – Pavandroid

+0

問題がまだ解決しています...すべてうまく見えます... MsgTextViewクラスをペーストしました – Sumit

関連する問題