我正在尝试使用userdata连接Footer,但应用程序正在崩溃。任何人都可以帮忙吗?
登录课程:
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,职业按钮保存,这些来自主要布局和ImageView ad1,ad2,ad3,ad4,ad5,ad6; horizontalScrollView1,这些来自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 -->
log cat
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
答案 0 :(得分:1)
你在这里出错:
horizontalScrollView1 = (HorizontalScrollView) horizontalScrollView1
.findViewById(R.id.horizontalScrollView1);
用以下代替:
horizontalScrollView1 = (HorizontalScrollView)findViewById(R.id.horizontalScrollView1);
试试这个。
答案 1 :(得分:0)
试试这个..
将 footer_lay 作为包含布局ID,如下所示
<强> XML 强>
<include
android:id="@+id/footer_lay"
layout="@layout/footer" />
<强>爪哇强>
并将footer_lay视为LinearLayout
并将您的页脚显示为ImageView
footer_lay.findViewById(R.id.ad1);
,如下面的代码所示
RelativeLayout footer_lay = (RelativeLayout) findViewById(R.id.footer_lay);
ad1= (ImageView) footer_lay.findViewById(R.id.ad1);
ad2= (ImageView) footer_lay.findViewById(R.id.ad2);
ad3= (ImageView) footer_lay.findViewById(R.id.ad3);
ad4= (ImageView) footer_lay.findViewById(R.id.ad4);
ad5= (ImageView) footer_lay.findViewById(R.id.ad5);
ad6= (ImageView) footer_lay.findViewById(R.id.ad6);
horizontalScrollView1=(HorizontalScrollView) footer_lay.findViewById(R.id.horizontalScrollView1);
答案 2 :(得分:0)
替换这个:
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);
使用:
ad1 = (ImageView) findViewById(R.id.ad1);
ad2 = (ImageView)findViewById(R.id.ad2);
ad3 = (ImageView)findViewById(R.id.ad3);
ad4 = (ImageView)findViewById(R.id.ad4);
ad5 = (ImageView)findViewById(R.id.ad5);
ad6 = (ImageView)findViewById(R.id.ad6);
horizontalScrollView1 =
(HorizontalScrollView)findViewById(R.id.horizontalScrollView1);