質問
src> myproject.test> HomeViewでカスタムビューがあります
私のメインレイアウトXMLには、次のことがあります。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/home_root"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<myproject.test.HomeView
android:id="@+id/home_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
</myproject.test.HomeView>
</LinearLayout>
Homeactivityでは、OnCreateメソッドでこのような呼び出しがあります。
setContentView(R.layout.main);
HomeView mHomeView = (HomeView) this.findViewById(R.id.home_view);
SetContentViewメソッドが呼び出されたときに、アプリの力が閉じられました。私の主なXMLは正しくないようです。
何か案は?
解決
あなたはそれが到達しないということですか?
HomeView mHomeView = (HomeView) this.findViewById(R.id.home_view);
そして、それの前にラインでクラッシュしますか?
コンストラクターがあるかどうかを確認してください
HomeView(final Context context, final AttributeSet attrs){
super(context, attrs);
そしてそうではありません
HomeView(final Context context){
super(context);
属性セットが必要です
他のヒント
ホームビューが実装するコンストラクターを確認してください。
public HomeView(Context context, AttributeSet atts) {
super(context, atts);
}
<LinearLayout xmlns:android =
http://schemas.android.com/apk/res/android"
android:id="@+id/home_root"
android:orientation="vertical"
私のレイアウトはどれも持っていません @+id
. 。多分あなたはビューを設定する必要があります home_root
. 。あなたにチェックしてください R.Java レイアウトの名前については、または試してください
setContentView(R.layout.home_root);
所属していません StackOverflow