我正在尝试重新组织我的一项活动。基本上我想做的就是将一个线性布局元素和文本元素从页面底部移动到中间。但是当我这样做并运行我的应用程序时,我收到了这个错误:
06-26 13:37:38.385: E/AndroidRuntime(11578): FATAL EXCEPTION: main
06-26 13:37:38.385: E/AndroidRuntime(11578): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.beerportfoliopro/com.example.beerportfoliopro.BeerPage}: java.lang.ClassCastException: android.widget.LinearLayout cannot be cast to android.widget.TextView
06-26 13:37:38.385: E/AndroidRuntime(11578): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2332)
06-26 13:37:38.385: E/AndroidRuntime(11578): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2368)
06-26 13:37:38.385: E/AndroidRuntime(11578): at android.app.ActivityThread.access$600(ActivityThread.java:151)
06-26 13:37:38.385: E/AndroidRuntime(11578): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1330)
06-26 13:37:38.385: E/AndroidRuntime(11578): at android.os.Handler.dispatchMessage(Handler.java:99)
06-26 13:37:38.385: E/AndroidRuntime(11578): at android.os.Looper.loop(Looper.java:155)
06-26 13:37:38.385: E/AndroidRuntime(11578): at android.app.ActivityThread.main(ActivityThread.java:5536)
06-26 13:37:38.385: E/AndroidRuntime(11578): at java.lang.reflect.Method.invokeNative(Native Method)
06-26 13:37:38.385: E/AndroidRuntime(11578): at java.lang.reflect.Method.invoke(Method.java:511)
06-26 13:37:38.385: E/AndroidRuntime(11578): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1074)
06-26 13:37:38.385: E/AndroidRuntime(11578): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:841)
06-26 13:37:38.385: E/AndroidRuntime(11578): at dalvik.system.NativeStart.main(Native Method)
06-26 13:37:38.385: E/AndroidRuntime(11578): Caused by: java.lang.ClassCastException: android.widget.LinearLayout cannot be cast to android.widget.TextView
06-26 13:37:38.385: E/AndroidRuntime(11578): at com.example.beerportfoliopro.BeerPage.onCreate(BeerPage.java:49)
06-26 13:37:38.385: E/AndroidRuntime(11578): at android.app.Activity.performCreate(Activity.java:5066)
06-26 13:37:38.385: E/AndroidRuntime(11578): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1102)
06-26 13:37:38.385: E/AndroidRuntime(11578): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2288)
我原来的xml是:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/beerTitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ems="10"
android:textSize="20sp"
android:textStyle = "bold"
android:padding="5dip"
>
</TextView>
<ImageView android:id="@+id/image"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:layout_margin="10dip"/>
<TableLayout
android:id="@+id/tableLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:shrinkColumns="*"
android:stretchColumns="*">
<TableRow
android:id="@+id/tableStatTitles"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dip" >
<TextView
android:id="@+id/abvTitle"
android:text="ABV"
android:gravity="center"
android:textStyle = "bold"
android:textSize="20sp"
android:layout_weight="1"
></TextView>
<TextView
android:id="@+id/IBUTitle"
android:text="IBU"
android:gravity="center"
android:textStyle = "bold"
android:textSize="20sp"
android:layout_weight="1"
></TextView>
<TextView
android:id="@+id/glassTitle"
android:text="Glass"
android:gravity="center"
android:textStyle = "bold"
android:textSize="20sp"
android:layout_weight="1"
android:layout_width="wrap_content"
></TextView>
</TableRow>
<TableRow
android:id="@+id/tableStat"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dip" >
<TextView
android:id="@+id/abv"
android:text=""
android:gravity="center"
android:textSize="15sp"
android:layout_width="wrap_content"
></TextView>
<TextView
android:id="@+id/IBU"
android:text=""
android:gravity="center"
android:textSize="15sp"
android:layout_width="wrap_content"
></TextView>
<TextView
android:id="@+id/glass"
android:text=""
android:gravity="center"
android:textSize="15sp"
android:layout_width="wrap_content"
></TextView>
</TableRow>
</TableLayout>
<Button
android:id="@+id/buttonBrewery"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dip"
android:text=""
android:onClick="viewBrewery"
/>
<Button
android:id="@+id/buttonStyle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dip"
android:text=""
android:onClick="viewStyle"
/>
<TextView
android:id="@+id/beerDescriptionTitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ems="10"
android:padding="5dip"
android:text="Description:"
android:textSize="20sp"
android:textStyle="bold" >
</TextView>
<TextView
android:id="@+id/beerDescription"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ems="10"
android:textSize="15sp"
android:padding="5dip"
></TextView>
<TextView
android:id="@+id/yourPortfolio"
android:textStyle = "bold"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ems="10"
android:textSize="20sp"
android:text="Your Portfolio:"
android:padding="5dip"
></TextView>
<LinearLayout
android:id="@+id/addBeerLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
</LinearLayout>
</ScrollView>
我想要的和强制关闭应用程序的一个是:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/beerTitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ems="10"
android:textSize="20sp"
android:textStyle = "bold"
android:padding="5dip"
>
</TextView>
<ImageView android:id="@+id/image"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:layout_margin="10dip"/>
<TableLayout
android:id="@+id/tableLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:shrinkColumns="*"
android:stretchColumns="*">
<TableRow
android:id="@+id/tableStatTitles"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dip" >
<TextView
android:id="@+id/abvTitle"
android:text="ABV"
android:gravity="center"
android:textStyle = "bold"
android:textSize="20sp"
android:layout_weight="1"
></TextView>
<TextView
android:id="@+id/IBUTitle"
android:text="IBU"
android:gravity="center"
android:textStyle = "bold"
android:textSize="20sp"
android:layout_weight="1"
></TextView>
<TextView
android:id="@+id/glassTitle"
android:text="Glass"
android:gravity="center"
android:textStyle = "bold"
android:textSize="20sp"
android:layout_weight="1"
android:layout_width="wrap_content"
></TextView>
</TableRow>
<TableRow
android:id="@+id/tableStat"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dip" >
<TextView
android:id="@+id/abv"
android:text=""
android:gravity="center"
android:textSize="15sp"
android:layout_width="wrap_content"
></TextView>
<TextView
android:id="@+id/IBU"
android:text=""
android:gravity="center"
android:textSize="15sp"
android:layout_width="wrap_content"
></TextView>
<TextView
android:id="@+id/glass"
android:text=""
android:gravity="center"
android:textSize="15sp"
android:layout_width="wrap_content"
></TextView>
</TableRow>
</TableLayout>
<Button
android:id="@+id/buttonBrewery"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dip"
android:text=""
android:onClick="viewBrewery"
/>
<Button
android:id="@+id/buttonStyle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dip"
android:text=""
android:onClick="viewStyle"
/>
<TextView
android:id="@+id/yourPortfolio"
android:textStyle = "bold"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ems="10"
android:textSize="20sp"
android:text="Your Portfolio:"
android:padding="5dip"
></TextView>
<LinearLayout
android:id="@+id/addBeerLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
<TextView
android:id="@+id/beerDescriptionTitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ems="10"
android:padding="5dip"
android:text="Description:"
android:textSize="20sp"
android:textStyle="bold" >
</TextView>
<TextView
android:id="@+id/beerDescription"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ems="10"
android:textSize="15sp"
android:padding="5dip"
></TextView>
</LinearLayout>
</ScrollView>