我正在尝试从模板复制设计,但是出现转换错误。我是使用3rd party库和Android编程的新手,所以我希望这不会成为问题。

另外,我有2个文本字段和2个按钮(注册,登录)。谁能看到我正确设置的登录代码type来告诉我。非常感谢。

错误日志:

1-17 16:26:18.136 7038-7038/mypackage.restaurantlunchify E/AndroidRuntime: FATAL EXCEPTION: main
11-17 16:26:18.136 7038-7038/mypackage.restaurantlunchify E/AndroidRuntime: Process: mypackage.restaurantlunchify, PID: 7038
11-17 16:26:18.136 7038-7038/mypackage.restaurantlunchify E/AndroidRuntime: java.lang.ClassCastException: mypackage.restaurantlunchify.Templates.FloatLabeledEditText cannot be cast to android.widget.EditText
11-17 16:26:18.136 7038-7038/mypackage.restaurantlunchify E/AndroidRuntime:     at mypackage.restaurantlunchify.Login.Login$2.onClick(Login.java:61)
11-17 16:26:18.136 7038-7038/mypackage.restaurantlunchify E/AndroidRuntime:     at android.view.View.performClick(View.java:4785)
11-17 16:26:18.136 7038-7038/mypackage.restaurantlunchify E/AndroidRuntime:     at mypackage.restaurantlunchify.Templates.MaterialRippleLayout$PerformClickEvent.run(MaterialRippleLayout.java:568)
11-17 16:26:18.136 7038-7038/mypackage.restaurantlunchify E/AndroidRuntime:     at mypackage.restaurantlunchify.Templates.MaterialRippleLayout$3.onAnimationEnd(MaterialRippleLayout.java:315)
11-17 16:26:18.136 7038-7038/mypackage.restaurantlunchify E/AndroidRuntime:     at android.animation.AnimatorSet$AnimatorSetListener.onAnimationEnd(AnimatorSet.java:829)
11-17 16:26:18.136 7038-7038/mypackage.restaurantlunchify E/AndroidRuntime:     at android.animation.ValueAnimator.endAnimation(ValueAnimator.java:1089)
11-17 16:26:18.136 7038-7038/mypackage.restaurantlunchify E/AndroidRuntime:     at android.animation.ValueAnimator$AnimationHandler.doAnimationFrame(ValueAnimator.java:666)
11-17 16:26:18.136 7038-7038/mypackage.restaurantlunchify E/AndroidRuntime:     at android.animation.ValueAnimator$AnimationHandler.run(ValueAnimator.java:682)
11-17 16:26:18.136 7038-7038/mypackage.restaurantlunchify E/AndroidRuntime:     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:792)
11-17 16:26:18.136 7038-7038/mypackage.restaurantlunchify E/AndroidRuntime:     at android.view.Choreographer.doCallbacks(Choreographer.java:596)
11-17 16:26:18.136 7038-7038/mypackage.restaurantlunchify E/AndroidRuntime:     at android.view.Choreographer.doFrame(Choreographer.java:556)
11-17 16:26:18.136 7038-7038/mypackage.restaurantlunchify E/AndroidRuntime:     at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:778)
11-17 16:26:18.136 7038-7038/mypackage.restaurantlunchify E/AndroidRuntime:     at android.os.Handler.handleCallback(Handler.java:739)
11-17 16:26:18.136 7038-7038/mypackage.restaurantlunchify E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:95)
11-17 16:26:18.136 7038-7038/mypackage.restaurantlunchify E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:155)
11-17 16:26:18.136 7038-7038/mypackage.restaurantlunchify E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5696)
11-17 16:26:18.136 7038-7038/mypackage.restaurantlunchify E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Native Method)
11-17 16:26:18.136 7038-7038/mypackage.restaurantlunchify E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Method.java:372)
11-17 16:26:18.136 7038-7038/mypackage.restaurantlunchify E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1028)
11-17 16:26:18.136 7038-7038/mypackage.restaurantlunchify E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)


登录代码:

public class Login extends Activity {

    public static RestTemplate rest = StaticRestTemplate.rest;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login);


        TextView restaurantRegister = (TextView) findViewById(R.id.registerRestaurantButton);
        restaurantRegister.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!(v == null)) {
                    Intent intent = new Intent(Login.this, AddRestaurant.class);
                    startActivity(intent);
                    finish();

                }
            }
        });

        TextView loginButton = (TextView) findViewById(R.id.LoginButton);
        loginButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!(v == null)) {
                    EditText userEmail = (EditText) findViewById(R.id.usernameText);
                    EditText userPassword = (EditText) findViewById(R.id.PasswordField);
}
}


Login.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/login_background_dark"
    android:orientation="vertical"
    android:padding="24dp"
    android:weightSum="1">


    <mypackage.restaurantlunchify.Templates.FontelloTextView
        android:id="@+id/logo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="64dp"
        android:layout_marginLeft="140dp"
        android:layout_marginStart="140dp"
        android:layout_marginTop="64dp"
        android:text="@string/fontello_logo"
        android:textColor="@color/main_color_50"
        android:textSize="64dp"
        tools:ignore="SpUsage" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_vertical"
        >
        <mypackage.restaurantlunchify.Templates.FontelloTextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="4dp"
            android:text="@string/fontello_user"
            android:textColor="@color/main_color_50"
            android:textSize="16dp"
            tools:ignore="SpUsage" />

        <mypackage.restaurantlunchify.Templates.FloatLabeledEditText
            android:id="@+id/usernameText"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="16dp"
            android:layout_weight="1"
            app:fletHintTextColor="@color/main_color_A100"
            app:fletSingleLine="true"
            app:fletFloatingHint="Username"
            app:fletTextColor="@color/main_color_grey_50"/>

    </LinearLayout>


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="6dp"
        android:gravity="center_vertical"
        >

        <mypackage.restaurantlunchify.Templates.FontelloTextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="4dp"
            android:text="@string/fontello_password"
            android:textColor="@color/main_color_50"
            android:textSize="16dp"
            tools:ignore="SpUsage" />

        <mypackage.restaurantlunchify.Templates.FloatLabeledEditText
            android:id="@+id/PasswordField"

            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="16dp"
            android:layout_weight="1"
            app:fletFloatingHint="@string/password"
            app:fletHintTextColor="@color/main_color_A100"
            app:fletPassword="true"
            app:fletSingleLine="true"
            app:fletTextColor="@color/main_color_grey_50" />
    </LinearLayout>



    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="40dp"
        android:layout_marginTop="54dp">

        <mypackage.restaurantlunchify.Templates.MaterialRippleLayout
            style="@style/RippleStyle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginEnd="3dp"
            android:layout_marginRight="3dp"
            android:text="@string/fontello_password"

            app:rippleColor="@color/main_color_grey_400">

            <mypackage.restaurantlunchify.Templates.RobotoTextView
                android:id="@+id/LoginButton"
                style="@style/ButtonStyle.RaisedEmpty"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:layout_weight="0.08"
                android:background="@color/main_color_900"
                app:fletFloatingHint="@string/password"
                android:minWidth="112dp"
                android:text="Login"
                android:textColor="#fff" />


        </mypackage.restaurantlunchify.Templates.MaterialRippleLayout>

        <mypackage.restaurantlunchify.Templates.MaterialRippleLayout
            style="@style/RippleStyle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="end"
            android:layout_marginTop="54dp"
            app:rippleColor="@color/main_color_grey_400">

            <mypackage.restaurantlunchify.Templates.RobotoTextView
                android:id="@+id/registerRestaurantButton"
                style="@style/ButtonStyle.RaisedEmpty"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@color/main_color_900"
                android:minWidth="112dp"
                android:text="Register"
                android:textColor="#fff" />
        </mypackage.restaurantlunchify.Templates.MaterialRippleLayout>
    </LinearLayout>


</LinearLayout>


如果需要其他文件或信息,请告诉我。参考模板甚至没有处理Java代码中的输入,因此我不知道该如何命名。

这是每个UI文件扩展的内容:

公共类FontelloTextView扩展了TextView
公共类FloatLabeledEditText扩展LinearLayout
公共类MaterialRippleLayout扩展了FrameLayout {
公共类RobotoTextView扩展了TextView {

谢谢.. :-)

最佳答案

FloatLabeledEditText太多。所以我不知道您使用的是哪种FloatLabeledEditText

 



     <mypackage.restaurantlunchify.Templates.FloatLabeledEditText
            android:id="@+id/usernameTextFloat"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="16dp"
            android:layout_weight="1"
            app:fletHintTextColor="@color/main_color_A100"
            app:fletSingleLine="true"
            app:fletFloatingHint="Username"
            app:fletTextColor="@color/main_color_grey_50">

<EditText @+id/usernameText android:layout_height="wrap_content" android:layout_width="match_parent" />

<mypackage.restaurantlunchify.Templates.FloatLabeledEditText/>

10-07 13:39