FATAL异常:java.lang.RuntimeException:无法启动活动ComponentInfo

时间:2016-07-19 11:34:59

标签: android

我尝试解决这个问题,但我找不到任何解决方案,所以请帮我解决。 1)我的Package.java文件:

b_indian=(Button)findViewById(R.id.b_indian);
        b_classic=(Button)findViewById(R.id.b_classic);
        b_royal=(Button)findViewById(R.id.b_royal);
        t_pkg=(TextView)findViewById(R.id.t_pkg);
        t_indian=(TextView)findViewById(R.id.t_indian);
        t_classic=(TextView)findViewById(R.id.t_classic);
        t_royal=(TextView)findViewById(R.id.t_royal);

        b_indian.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i=new Intent(Package.this,Indianpkg.class);
                startActivity(i);
            }
        });

        b_classic.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i=new Intent(Package.this,Classicpkg.class);
                startActivity(i);
            }
        });

        b_royal.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i=new Intent(Package.this,Royalpkg.class);
                startActivity(i);
            }
        });

    }
}

2)activity_package.xml

 <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="Package"
        android:id="@+id/t_pkg"
        android:layout_gravity="center_horizontal"
        style="@style/Title"/>

    <TableLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">


    <TableRow
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:weightSum="1"
        android:layout_weight="0.5">

        <RelativeLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="0.5">


        <Button
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/b_indian"

            android:textSize="18sp"
            android:gravity="center"
            android:singleLine="false"
            android:paddingBottom="10dp"
            android:layout_margin="25dp"/>


</RelativeLayout>

            <RelativeLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="0.5">
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:text="INDIAN"
                android:id="@+id/t_indian"
                android:layout_margin="55dp"
                android:gravity="center_horizontal"
                style="@style/SimpleText"/>

        </RelativeLayout>
        </TableRow>

        <TableRow
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:weightSum="1"
            android:layout_weight="0.5">

            <RelativeLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="0.5">


                <Button
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:id="@+id/b_classic"

                    android:textSize="18sp"
                    android:gravity="center"
                    android:singleLine="false"
                    android:paddingBottom="10dp"
                    android:layout_margin="25dp" />


            </RelativeLayout>

            <RelativeLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="0.5">
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textAppearance="?android:attr/textAppearanceLarge"
                    android:text="CLASSIC"
                    android:layout_margin="50dp"
                    android:id="@+id/t_classic"
                    android:layout_gravity="center_horizontal"
                    style="@style/SimpleText"/>

            </RelativeLayout>
        </TableRow>

        <TableRow
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:weightSum="1"
            android:layout_weight="0.5">

            <RelativeLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="0.5">


                <Button
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:id="@+id/b_royal"

                    android:textSize="18sp"
                    android:gravity="center"
                    android:singleLine="false"
                    android:paddingBottom="10dp"
                    android:layout_margin="25dp"/>



            </RelativeLayout>


            <RelativeLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="0.5">
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textAppearance="?android:attr/textAppearanceLarge"
                    android:text="ROYAL"
                    android:layout_margin="55dp"
                    android:id="@+id/t_royal"
                    android:layout_gravity="center_horizontal"
                    style="@style/SimpleText"/>

            </RelativeLayout>
        </TableRow>

    </TableLayout>

这是我的包文件,我把相同的代码用于意图在该文件中的三个不同的包,但我只意图印度包和其余的两个包不是意图,我有错误:FATAL例外。 关注所有文件: 1)Indianpkg.java

b_i_venue=(Button)findViewById(R.id.b_i_venue);
        b_i_decor=(Button)findViewById(R.id.b_i_decor);
        b_i_caterer=(Button)findViewById(R.id.b_i_caterer);
        b_i_photo=(Button)findViewById(R.id.b_i_photo);
        b_i_mehandi=(Button)findViewById(R.id.b_i_mehandi);
        b_i_dj=(Button)findViewById(R.id.b_i_dj);
        t1=(TextView)findViewById(R.id.t1);

        b_i_venue.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i=new Intent(Indianpkg.this,Indian_venue.class);
                startActivity(i);
            }
        });

        b_i_decor.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i=new Intent(Indianpkg.this,Indian_decoration.class);
                startActivity(i);
            }
        });

        b_i_caterer.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i=new Intent(Indianpkg.this,Indian_decoration.class);
                startActivity(i);
            }
        });

        b_i_photo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i=new Intent(Indianpkg.this,Indian_caterer.class);
                startActivity(i);
            }
        });

        b_i_mehandi.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i=new Intent(Indianpkg.this,Indian_mehandi.class);
                startActivity(i);
            }
        });

        b_i_dj.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i=new Intent(Indianpkg.this,Indian_dj.class);
                startActivity(i);
            }
        });


    }
}

2)activity_indianpkg.xml

 <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text=" Indian Wedding"
        android:id="@+id/t1"
        android:layout_gravity="center_horizontal"
        style="@style/Title"/>

    <TableLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TableRow
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:weightSum="1"
            android:layout_weight="0.5">
            <RelativeLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="0.5">

                <Button
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:id="@+id/b_i_venue"
                    android:background="@drawable/i_venue"
                    android:text="Venue"
                    android:textSize="18sp"
                    android:gravity="center|bottom"
                    android:singleLine="false"
                    android:paddingBottom="10dp"
                    android:layout_margin="10dp"
                    style="@style/Title"/>
            </RelativeLayout>
            <RelativeLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="0.5">
                <Button
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:id="@+id/b_i_decor"
                    android:background="@drawable/i_decoration"
                    android:text="Decoration"
                    android:textSize="18sp"
                    android:gravity="center|bottom"
                    android:singleLine="false"
                    android:paddingBottom="10dp"
                    android:layout_margin="10dp"
                    style="@style/Title"/>
            </RelativeLayout>
        </TableRow>

        <TableRow
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:weightSum="1"
            android:layout_weight="0.5">
            <RelativeLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="0.5">
                <Button
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:id="@+id/b_i_caterer"
                    android:text="Caterer"
                    android:background="@drawable/i_caterer"
                    android:textSize="18sp"
                    android:gravity="center|bottom"
                    android:layout_margin="10dp"
                    android:paddingBottom="10dp"
                    style="@style/Title"/>

            </RelativeLayout>
            <RelativeLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="0.5">
                <Button
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:id="@+id/b_i_photo"
                    android:text="Photography"
                    android:background="@drawable/i_photography"
                    android:textSize="18sp"
                    android:gravity="center|bottom"
                    android:paddingBottom="10dp"
                    android:layout_margin="10dp"
                    style="@style/Title"/>
            </RelativeLayout>
        </TableRow>

        <TableRow
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:weightSum="1"
            android:layout_weight="0.5">
            <RelativeLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="0.5">
                <Button
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:id="@+id/b_i_mehandi"
                    android:text="Mehandi"
                    android:background="@drawable/i_mahendi"
                    android:textSize="18sp"
                    android:gravity="center|bottom"
                    android:layout_margin="10dp"
                    android:paddingBottom="10dp"
                    style="@style/Title"/>

            </RelativeLayout>
            <RelativeLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="0.5">
                <Button
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:id="@+id/b_i_dj"
                    android:text="DJ"
                    android:background="@drawable/i_dj"
                    android:textSize="18sp"
                    android:gravity="center|bottom"
                    android:layout_margin="10dp"
                    style="@style/Title"
                    android:paddingBottom="10dp"/>

            </RelativeLayout>
        </TableRow>

    </TableLayout>

以上代码成功运行。但是下面的代码也是相同但仍然没有运行并给出了FATAL异常。

3)Classic.java

b_c_venue=(Button)findViewById(R.id.b_i_venue);
        b_c_decor=(Button)findViewById(R.id.b_i_decor);
        b_c_caterer=(Button)findViewById(R.id.b_i_caterer);
        b_c_photo=(Button)findViewById(R.id.b_i_photo);
        b_c_mehandi=(Button)findViewById(R.id.b_i_mehandi);
        b_c_dj=(Button)findViewById(R.id.b_i_dj);
        t2=(TextView)findViewById(R.id.t2);

        b_c_venue.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i=new Intent(Classicpkg.this,Classic_venue.class);
                startActivity(i);
            }
        });

        b_c_decor.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i=new Intent(Classicpkg.this,Classic_decoration.class);
                startActivity(i);
            }
        });

        b_c_caterer.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i=new Intent(Classicpkg.this,Classic_caterer.class);
                startActivity(i);
            }
        });

        b_c_photo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i=new Intent(Classicpkg.this,Classic_photography.class);
                startActivity(i);
            }
        });

        b_c_mehandi.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i=new Intent(Classicpkg.this,Classic_mehandi.class);
                startActivity(i);
            }
        });

        b_c_dj.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i=new Intent(Classicpkg.this,Classic_dj.class);
                startActivity(i);
            }
        });

    }
}

4)activity_classic.xml

<TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text=" Classic Wedding"
        android:id="@+id/t2"
        android:layout_gravity="center_horizontal"
        style="@style/Title"/>

    <TableLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TableRow
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:weightSum="1"
            android:layout_weight="0.5">
            <RelativeLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="0.5">

                <Button
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:id="@+id/b_c_venue"
                    android:background="@drawable/i_venue"
                    android:text="Venue"
                    android:textSize="18sp"
                    android:gravity="center|bottom"
                    android:singleLine="false"
                    android:paddingBottom="10dp"
                    android:layout_margin="10dp"
                    style="@style/Title"/>
            </RelativeLayout>
            <RelativeLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="0.5">
                <Button
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:id="@+id/b_c_decor"
                    android:background="@drawable/i_decoration"
                    android:text="Decoration"
                    android:textSize="18sp"
                    android:gravity="center|bottom"
                    android:singleLine="false"
                    android:paddingBottom="10dp"
                    android:layout_margin="10dp"
                    style="@style/Title"/>
            </RelativeLayout>
        </TableRow>

        <TableRow
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:weightSum="1"
            android:layout_weight="0.5">
            <RelativeLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="0.5">
                <Button
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:id="@+id/b_c_caterer"
                    android:text="Caterer"
                    android:background="@drawable/i_caterer"
                    android:textSize="18sp"
                    android:gravity="center|bottom"
                    android:layout_margin="10dp"
                    android:paddingBottom="10dp"
                    style="@style/Title"/>

            </RelativeLayout>
            <RelativeLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="0.5">
                <Button
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:id="@+id/b_c_photo"
                    android:text="Photography"
                    android:background="@drawable/i_photography"
                    android:textSize="18sp"
                    android:gravity="center|bottom"
                    android:paddingBottom="10dp"
                    android:layout_margin="10dp"
                    style="@style/Title"/>
            </RelativeLayout>
        </TableRow>

        <TableRow
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:weightSum="1"
            android:layout_weight="0.5">
            <RelativeLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="0.5">
                <Button
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:id="@+id/b_c_mehandi"
                    android:text="Mehandi"
                    android:background="@drawable/i_mahendi"
                    android:textSize="18sp"
                    android:gravity="center|bottom"
                    android:layout_margin="10dp"
                    android:paddingBottom="10dp"
                    style="@style/Title"/>

            </RelativeLayout>
            <RelativeLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="0.5">
                <Button
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:id="@+id/b_c_dj"
                    android:text="DJ"
                    android:background="@drawable/i_dj"
                    android:textSize="18sp"
                    android:gravity="center|bottom"
                    android:layout_margin="10dp"
                    style="@style/Title"
                    android:paddingBottom="10dp"/>

            </RelativeLayout>
        </TableRow>

    </TableLayout>

enter image description here

2 个答案:

答案 0 :(得分:0)

您的经典视图中的ID是错误的,更改... ... for .... c ...在您的经典活动中,就像这样:

b_c_venue=(Button)findViewById(R.id.b_c_venue);

答案 1 :(得分:0)

可能是你没有在AndroidMaifest.xml中添加活动类
如果你不这样做!

将活动添加到AndroidMaifest.xml

像这样

        <activity
           android:name=".Classic"
           android:label="your_activity_label">
        </activity>

然后在Classic.java中编辑代码

    b_c_venue=(Button)findViewById(R.id.b_c_venue);
    b_c_decor=(Button)findViewById(R.id.b_c_decor);
    b_c_caterer=(Button)findViewById(R.id.b_c_caterer);
    b_c_photo=(Button)findViewById(R.id.b_c_photo);
    b_c_mehandi=(Button)findViewById(R.id.b_c_mehandi);
    b_c_dj=(Button)findViewById(R.id.b_c_dj);
    t2=(TextView)findViewById(R.id.t2);