0

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 が正しくないようです。

何か案は?

4

3 に答える 3

2

に到達していないということですか?

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);

AttributeSet が必要です

于 2010-10-21T22:24:36.703 に答える
0

HomeView が実装するコンストラクターを確認します。

 public HomeView(Context context, AttributeSet atts) {
     super(context, atts); 
 } 
于 2010-10-21T22:28:52.453 に答える
0
<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);
于 2010-10-21T22:29:22.493 に答える