在LoginClick上我希望在我的ViewSwitcher切换到ProgressBar时在后台运行用户验证。我在实现AsyncTask时遇到了困难。
OnClick EventHander:
void LoginClick (Object o, EventArgs e)
{
_v.ShowNext ();
LoginUser lu = new LoginUser (this, _user.Text, _pw.Text);
lu.Execute ("run");
}
LoginUser类:
class LoginUser: AsyncTask
{
private readonly string _userName;
private readonly string _password;
private readonly Context _context;
private User user;
public LoginUser (Context context, string userName, string password)
{
_context = context;
_userName = userName;
_password = password;
}
protected override Java.Lang.Object DoInBackground (Java.Lang.Object[] @params)
{
WS ws = new WS ();
user = ws.validateUser (_userName, _password);
return true;
}
protected override void OnPostExecute (Java.Lang.Object result)
{
Toast.MakeText (_context, user.Market, ToastLength.Long).Show ();
}
}
但是当我构建项目时,我得到一个构建错误“LoginUser.DoInBackground被标记为覆盖但没有找到合适的方法来覆盖。”
更新:因此MonoDevelop在扩展AsyncTask类方面略有不同。几乎到处都有我的User类,我需要放置Java.Lang.Object。我现在可以毫无错误地构建。但是,现在应用程序只是在LoginClick时立即崩溃。
E/mono (18020): Unhandled Exception: Java.Lang.NoClassDefFoundError: Exception of type 'Java.Lang.NoClassDefFoundError' was thrown.
E/mono (18020): at Android.Runtime.JNIEnv.FindClass (System.String classname) [0x00000] in <filename unknown>:0
E/mono (18020): at Android.Runtime.JNIEnv.FindClass (System.Type type) [0x00000] in <filename unknown>:0
E/mono (18020): --- End of managed exception stack trace ---
E/mono (18020): java.lang.NoClassDefFoundError: cpec_fm.LoginUser
E/mono (18020): at mono.android.view.View_OnClickListenerImplementor.n_onClick(Native Method)
E/mono (18020): at mono.android.view.View_OnClickListenerImplementor.onClick(View_OnClickListenerImplementor.java:29)
E/mono (18020): at android.view.View.performClick(View.java:3110)
E/mono (18020): at android.view.View$PerformClick.run(View.java:11934)
E/mono (18020): at android.os.Handler.handleCallback(Handler.java:587)
E/mono (18020): at android.os.Handler.dispatchMessage(Handler.java:92)
E/mono (18020): at android.os.Looper.loop(Looper.java:132)
E/mono (18020): at android.app.ActivityThread.main(ActivityThread.java:4143)
E/mono (18020): at java.lang.reflect.Method.invokeNative(Native Method)
E/mono (18020): at java.lang.reflect.Method.invoke(Method.java:491)
E/mono (18020):
上面更新的原始代码。
答案 0 :(得分:0)
所以刚刚在Visual Studio中打开并部署并且它可以工作。到目前为止,MonoDevelop一直非常失望。