我正在尝试从模板中复制设计,但我遇到了投射错误。我是第一方使用第三方库和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 {
谢谢..: - )
答案 0 :(得分:3)
有很多test(1);
test(2);
public void test(int i){
}
。所以我不知道你正在使用哪种FloatLabeledEditText
。
到
FloatLabeledEditText