gpt4 book ai didi

android - 连接两个布局

转载 作者:行者123 更新时间:2023-11-30 03:09:52 24 4
gpt4 key购买 nike

我正在尝试将页脚与用户数据连接起来,但应用程序崩溃了。有人可以帮忙吗?

登录类:

public class Login extends Activity {
EditText fullname, mobilenumber, occupation;
Button save;
ImageView ad1, ad2, ad3, ad4, ad5, ad6;
HorizontalScrollView horizontalScrollView1;

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.userdata);
fullname = (EditText) findViewById(R.id.fullname);
mobilenumber = (EditText) findViewById(R.id.mobile);
occupation = (EditText) findViewById(R.id.occupation);
save = (Button) findViewById(R.id.btnSave);
ad1 = (ImageView) ad1.findViewById(R.id.ad1);
ad2 = (ImageView) ad2.findViewById(R.id.ad2);
ad3 = (ImageView) ad3.findViewById(R.id.ad3);
ad4 = (ImageView) ad4.findViewById(R.id.ad4);
ad5 = (ImageView) ad5.findViewById(R.id.ad5);
ad6 = (ImageView) ad6.findViewById(R.id.ad6);
horizontalScrollView1 = (HorizontalScrollView) horizontalScrollView1
.findViewById(R.id.horizontalScrollView1);
}
}

fullname,mobilenumber, occupation Button save,这些来自main layout和ImageView ad1,ad2,ad3,ad4,ad5,ad6; horizo​​ntalScrollView1,这些来自footerlayout。我正在从主布局调用 footer.layout。像这样:

 <include layout="@layout/footer" />

从主布局中可以看到页脚布局,但应用程序崩溃了。不知道为什么!!

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="10dip" >

<!-- Full Name Label -->

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Full Name"
android:textColor="#372c24"
tools:ignore="HardcodedText" />

<EditText
android:id="@+id/fullname"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dip"
android:layout_marginTop="5dip"
android:singleLine="true" />
<!-- Email Label -->

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Mobile number"
android:textColor="#372c24"
tools:ignore="HardcodedText" />

<EditText
android:id="@+id/mobile"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dip"
android:layout_marginTop="5dip"
android:singleLine="true"
android:inputType="phone" />


<!-- Password Label -->

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Occupation"
android:textColor="#372c24"
tools:ignore="HardcodedText" />

<EditText
android:id="@+id/occupation"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:singleLine="true"
tools:ignore="TextFields" />

<!-- Register Button -->

<Button
android:id="@+id/btnSave"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dip"
android:text="Save"
tools:ignore="HardcodedText" />
<include layout="@layout/footer" /> </LinearLayout><!-- Registration Form Ends -->

日志猫

    01-16 15:48:54.048: E/AndroidRuntime(9072): Uncaught handler: thread main exiting due to uncaught exception
01-16 15:48:54.058: E/AndroidRuntime(9072): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mixorg.parsefooter/com.mixorg.parsefooter.Login}: java.lang.ClassCastException: android.widget.RelativeLayout
01-16 15:48:54.058: E/AndroidRuntime(9072): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2503)
01-16 15:48:54.058: E/AndroidRuntime(9072): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2519)
01-16 15:48:54.058: E/AndroidRuntime(9072): at android.app.ActivityThread.access$2200(ActivityThread.java:123)
01-16 15:48:54.058: E/AndroidRuntime(9072): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1870)
01-16 15:48:54.058: E/AndroidRuntime(9072): at android.os.Handler.dispatchMessage(Handler.java:99)
01-16 15:48:54.058: E/AndroidRuntime(9072): at android.os.Looper.loop(Looper.java:123)
01-16 15:48:54.058: E/AndroidRuntime(9072): at android.app.ActivityThread.main(ActivityThread.java:4370)
01-16 15:48:54.058: E/AndroidRuntime(9072): at java.lang.reflect.Method.invokeNative(Native Method)
01-16 15:48:54.058: E/AndroidRuntime(9072): at java.lang.reflect.Method.invoke(Method.java:521)
01-16 15:48:54.058: E/AndroidRuntime(9072): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
01-16 15:48:54.058: E/AndroidRuntime(9072): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
01-16 15:48:54.058: E/AndroidRuntime(9072): at dalvik.system.NativeStart.main(Native Method)
01-16 15:48:54.058: E/AndroidRuntime(9072): Caused by: java.lang.ClassCastException: android.widget.RelativeLayout
01-16 15:48:54.058: E/AndroidRuntime(9072): at com.mixorg.parsefooter.Login.onCreate(Login.java:22)
01-16 15:48:54.058: E/AndroidRuntime(9072): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-16 15:48:54.058: E/AndroidRuntime(9072): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2466)
01-16 15:48:54.058: E/AndroidRuntime(9072): ... 11 more
01-16 15:48:54.088: E/SemcCheckin(9072): Get crash dump level : java.io.FileNotFoundException: /data/semc-checkin/crashdump

最佳答案

你只是在这里出错了:

horizontalScrollView1 = (HorizontalScrollView) horizontalScrollView1
.findViewById(R.id.horizontalScrollView1);

将其替换为以下内容:

horizontalScrollView1 = (HorizontalScrollView)findViewById(R.id.horizontalScrollView1);

试试这个。

关于android - 连接两个布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21158513/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com