我已经为我的一项活动设计了布局,但出现了奇怪的错误。这是一个简单的活动,实际上它是主菜单活动,其中包含图像按钮。
"07-12 16:40:22.599: E/AndroidRuntime(1857): Caused by: java.lang.ClassCastException: android.widget.LinearLayout
"
这是我的布局 xml 代码
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="fill_parent" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:background="@drawable/rpg"
android:orientation="vertical" >
<TableLayout
android:id="@+id/tableLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center" >
<TextView android:text=" " />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center" >
<TextView android:text=" " />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center" >
<TextView android:text=" " />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center" >
<TextView android:text=" " />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center" >
<TextView android:text=" " />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center" >
<TextView android:text=" " />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center" >
<TextView android:text=" " />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center" >
<TextView android:text=" " />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center" >
<TextView android:text=" " />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center" >
<TextView android:text=" " />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center" >
<TextView android:text=" " />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center" >
<ImageButton
android:id="@+id/profile_btn"
android:layout_width="100dp"
android:layout_height="100dp"
android:src="@drawable/a1" />
<TextView android:text=" " />
<ImageButton
android:id="@+id/share_btn"
android:layout_width="100dp"
android:layout_height="100dp"
android:src="@drawable/a2" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center" >
<TextView android:text=" " />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center" >
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center" >
<TextView android:text=" " />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center" >
<ImageButton
android:id="@+id/settings_btn"
android:layout_width="100dp"
android:layout_height="100dp"
android:src="@drawable/a3" />
<TextView android:text=" " />
<ImageButton
android:id="@+id/contacts_btn"
android:layout_width="100dp"
android:layout_height="100dp"
android:src="@drawable/a4" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center" >
<TextView android:text=" " />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center" >
<ImageButton
android:id="@+id/exit_btn"
android:layout_width="100dp"
android:layout_height="100dp"
android:src="@drawable/a5" />
<TextView android:text=" " />
<ImageButton
android:id="@+id/amazon_btn"
android:layout_width="100dp"
android:layout_height="100dp"
android:src="@drawable/amazon" />
</TableRow>
</TableLayout>
<LinearLayout
android:id="@+id/ban2_mainmenu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="@drawable/ban_2" >
</LinearLayout>
<LinearLayout
android:id="@+id/ban1_mainmenu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignRight="@+id/ban2_mainmenu"
android:background="@drawable/ban_1" >
</LinearLayout>
</RelativeLayout>
</ScrollView>
在下面这段代码的第一行的java中,我收到错误
ImageButton amazon = (ImageButton) findViewById(R.id.amazon_btn);
amazon.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent browse = new Intent(Intent.ACTION_VIEW, Uri
.parse("http://www.amazon.com/gp/product/B0084FCDKS"));
startActivity(browse);
}
});
错误是
07-12 16:40:22.599: E/AndroidRuntime(1857): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.colony.rpgbluetoothchatlite/com.colony.rpgbluetoothchatlite.Menu_Main}: java.lang.ClassCastException: android.widget.LinearLayout
07-12 16:40:22.599: E/AndroidRuntime(1857): Caused by: java.lang.ClassCastException: android.widget.LinearLayout