2017-01-16 45 views
1

我面对的问题,而我试图使用小吃吧在Xamarin.Android

这里是错误堆栈

Java.Lang.ClassCastException: android.support.v7.widget.AppCompatTextView cannot be cast to android.widget.Button 

任何一个可以指导我,为什么这个问题提出

我的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" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/login_layout"> 
    <android.support.v7.widget.Toolbar 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@color/pumpkin_orange" 
     android:id="@+id/loginToolBar"> 
     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 
      <ReadyApps.Xamarin.Framework.Droid.Controls.ExtImageView 
       android:id="@+id/closeImageView" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       app:srcCompat="@drawable/ic_arrow_back_white_24dp" 
       android:layout_centerVertical="true" /> 
      <ReadyApps.Xamarin.Framework.Droid.Controls.ExtTextView 
       android:id="@+id/toolbarTitle" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       style="@style/TextStyle7" 
       android:layout_toRightOf="@+id/closeImageView" 
       android:layout_toEndOf="@+id/closeImageView" 
       android:layout_marginLeft="25dp" 
       android:layout_marginStart="25dp" 
       android:text="@string/signin" 
       android:layout_centerVertical="true" /> 
     </RelativeLayout> 
    </android.support.v7.widget.Toolbar> 
    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@color/white" 
     android:layout_gravity="center_horizontal"> 
     <ReadyApps.Xamarin.Framework.Droid.Controls.ExtImageView 
      android:src="@drawable/ic_launcher" 
      android:layout_width="wrap_content" 
      android:layout_height="150dp" 
      android:id="@+id/imageView1" 
      android:layout_centerHorizontal="true" /> 
     <LinearLayout 
      android:id="@+id/layout" 
      android:orientation="vertical" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="40dp" 
      android:layout_marginRight="40dp" 
      android:layout_below="@+id/imageView1"> 
      <android.support.design.widget.TextInputLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:textColorHint="@color/orange_two"> 
       <ReadyApps.Xamarin.Framework.Droid.Controls.ExtEditText 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:textSize="13.3sp" 
        android:hint="@string/storecode" 
        android:id="@+id/login_storeCode" 
        android:drawablePadding="7.3dp" 
        android:tag="Required" /> 
      </android.support.design.widget.TextInputLayout> 
      <android.support.design.widget.TextInputLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:textColorHint="@color/orange_two"> 
       <ReadyApps.Xamarin.Framework.Droid.Controls.ExtEditText 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:textSize="13.3sp" 
        android:hint="@string/username_email" 
        android:id="@+id/login_userName" 
        android:tag="Required" 
        android:drawablePadding="7.3dp" /> 
      </android.support.design.widget.TextInputLayout> 
      <android.support.design.widget.TextInputLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:textColorHint="@color/orange_two"> 
       <ReadyApps.Xamarin.Framework.Droid.Controls.ExtEditText 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:textSize="13.3sp" 
        android:inputType="textPassword" 
        android:hint="@string/password" 
        android:id="@+id/login_password" 
        android:tag="Required" 
        android:drawablePadding="7.3dp" /> 
      </android.support.design.widget.TextInputLayout> 
     </LinearLayout> 
     <ReadyApps.Xamarin.Framework.Droid.Controls.ExtTextView 
      android:text="@string/signin" 
      android:layout_marginTop="50dp" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/signIn" 
      android:layout_below="@+id/layout" 
      android:textAllCaps="true" 
      android:layout_centerHorizontal="true" 
      android:textSize="14.7sp" 
      android:padding="5dp" 
      style="@style/TextStyle11" /> 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="50dp" 
      android:layout_marginLeft="40dp" 
      android:layout_marginRight="40dp" 
      android:layout_below="@+id/signIn"> 
     <ReadyApps.Xamarin.Framework.Droid.Controls.ExtTextView 
      android:id="@+id/login_forgetpassword" 
      android:text="@string/forgetpassword" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      style="@style/TextStyle12" /> 
     <ReadyApps.Xamarin.Framework.Droid.Controls.ExtTextView 
       android:id="@+id/login_signUp" 
       android:text="@string/signup" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textAllCaps="true" 
       android:layout_alignParentRight="true" 
       android:layout_alignParentEnd="true" 
       style="@style/TextStyle12" 
       /> 
     </RelativeLayout> 
    </RelativeLayout> 
</LinearLayout> 

我的代码

public class LoginActivity : BaseActivity<LoginActivityLogic> 
    { 

    private ExtEditText et_vendorCode, et_userName, et_password; 
    private ExtTextView tv_forgetpassword , tv_signUp , bt_signIn;  
    private LinearLayout login_layout; 
    private string vendorCode; 

     protected override void OnCreate(Bundle savedInstanceState) 
     { 
     SetContentView(Resource.Layout.Login); 
     base.OnCreate(savedInstanceState); 

     initView(); 
     } 

    private void initView() 
    { 
     login_layout = FindViewById<LinearLayout>(Resource.Id.login_layout); 
     tv_signUp = FindViewById<ExtTextView>(Resource.Id.login_signUp); 
     bt_signIn = FindViewById<ExtTextView>(Resource.Id.signIn); 
     tv_forgetpassword = FindViewById<ExtTextView>(Resource.Id.login_forgetpassword); 
     et_vendorCode = FindViewById<ExtEditText>(Resource.Id.login_storeCode); 
     et_userName = FindViewById<ExtEditText>(Resource.Id.login_userName); 

     et_password = FindViewById<ExtEditText>(Resource.Id.login_password); 

     tv_forgetpassword.Click += Tv_forgetpassword_Click; 
     bt_signIn.Click += Bt_signIn_Click; 
     et_vendorCode.Text = vendorCode; 

     tv_signUp.Click += Tv_signUp_Click; 

     ExtImageView iv_Close = FindViewById<ExtImageView>(Resource.Id.closeImageView); 
     iv_Close.Click += delegate { Finish(); }; 

     // android: drawableLeft = "@drawable/ic_business_bluey_grey_24dp" 
     et_vendorCode.SetCompoundDrawablesWithIntrinsicBounds(Resource.Drawable.ic_business_bluey_grey_24dp , 0 , 0 , 0); 

     //android: drawableLeft = "@drawable/ic_account_blue_grey_24dp" 
     et_userName.SetCompoundDrawablesWithIntrinsicBounds(Resource.Drawable.ic_account_blue_grey_24dp, 0, 0, 0); 

     //android: drawableLeft = "@drawable/ic_lock_blue_grey_24dp" 
     et_password.SetCompoundDrawablesWithIntrinsicBounds(Resource.Drawable.ic_lock_blue_grey_24dp, 0, 0, 0); 

    } 

// I call it in method 

Snackbar.Make(login_layout, "mystring", Snackbar.LengthShort).Show(); 


} 

,但我得到了错误

我的错误日志

java.lang.ClassCastException: android.support.v7.widget.AppCompatTextView cannot be cast to android.widget.Button 
android.support.design.widget.Snackbar$SnackbarLayout.onFinishInflate()Snackbar.java:696 
android.view.LayoutInflater.rInflate()LayoutInflater.java:814 
android.view.LayoutInflater.inflate()LayoutInflater.java:504 
android.view.LayoutInflater.inflate()LayoutInflater.java:414 
android.support.design.widget.Snackbar.<init>()Snackbar.java:188 
android.support.design.widget.Snackbar.make()Snackbar.java:215 
mono.java.lang.RunnableImplementor.n_run(Native Method) 
mono.java.lang.RunnableImplementor.run()RunnableImplementor.java:30 
android.os.Handler.handleCallback()Handler.java:739 
android.os.Handler.dispatchMessage()Handler.java:95 
android.os.Looper.loop()Looper.java:135 
android.app.ActivityThread.main()ActivityThread.java:5221 
java.lang.reflect.Method.invoke(Native Method) 
java.lang.reflect.Method.invoke()Method.java:372 
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run()ZygoteInit.java:899 
com.android.internal.os.ZygoteInit.main()ZygoteInit.java:694 
Xamarin caused by: Java.Lang.ClassCastException: android.support.v7.widget.AppCompatTextView cannot be cast to android.widget.Button 
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()exceptionservicescommon.cs:143 
Java.Interop.JniEnvironment.StaticMethods.CallStaticObjectMethod(JniObjectReference type, JniMethodInfo method, JniArgumentValue* args)JniEnvironment.g.cs:12649 
Android.Runtime.JNIEnv.CallStaticObjectMethod(IntPtr jclass, IntPtr jmethod, JValue* parms)JNIEnv.g.cs:562 
Android.Support.Design.Widget.Snackbar.Make(View view, ICharSequence text, int duration)<0d997552ddad494094d94e2a353b2022>:0 
Android.Support.Design.Widget.Snackbar.Make(View view, string text, int duration)<0d997552ddad494094d94e2a353b2022>:0 
DSP.Droid.Activities.Orders.LoginActivity.AfterSaveResponse(object sender, EventArgs args) 
DSP.Core.UILogic.Orders.LoginActivityLogic.<SignIn>d__1.MoveNext() 
Android.App.SyncContext.<Post>c__AnonStorey0.<>m__0()SyncContext.cs:18 
Java.Lang.Thread.RunnableImplementor.Run()Thread.cs:36 
Java.Lang.IRunnableInvoker.n_Run(IntPtr jnienv, IntPtr native__this)Java.Lang.IRunnable.cs:81 
at (wrapper dynamic-method) System.Object:4ae9575e-e099-4bc0-bb97-0bb4377e913d (intptr,intptr) 
--- End of managed Java.Lang.ClassCastException stack trace --- 
java.lang.ClassCastException: android.support.v7.widget.AppCompatTextView cannot be cast to android.widget.Button 
android.support.design.widget.Snackbar$SnackbarLayout.onFinishInflate()Snackbar.java:696 
android.view.LayoutInflater.rInflate()LayoutInflater.java:814 
android.view.LayoutInflater.inflate()LayoutInflater.java:504 
android.view.LayoutInflater.inflate()LayoutInflater.java:414 
android.support.design.widget.Snackbar.<init>()Snackbar.java:188 
android.support.design.widget.Snackbar.make()Snackbar.java:215 
mono.java.lang.RunnableImplementor.n_run(Native Method) 
mono.java.lang.RunnableImplementor.run()RunnableImplementor.java:30 
android.os.Handler.handleCallback()Handler.java:739 
android.os.Handler.dispatchMessage()Handler.java:95 
android.os.Looper.loop()Looper.java:135 
android.app.ActivityThread.main()ActivityThread.java:5221 
java.lang.reflect.Method.invoke(Native Method) 
java.lang.reflect.Method.invoke()Method.java:372 
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run()ZygoteInit.java:899 
com.android.internal.os.ZygoteInit.main()ZygoteInit.java:694 
+0

PLZ Java代码添加更多细节 – W4R10CK

+0

更新我的回答,请检查 –

+0

错误日志显示铸造错误(从'AppCompatTextView'到'Button'错误投)。所以我想,错误发生在你的项目的其他地方。你能不能分享一个可以重现问题的基本演示? –

回答

0

在运行时引发此随机错误,你将与老版本面临

如何修复?升级到支持库V25以上