Android.Content.Res.Resources + NotFoundException:资源ID#0x7f03005e

时间:2016-12-07 11:57:29

标签: android android-layout xamarin xamarin.android

在较低版本的Android Mobile中运行代码时出现此错误。请帮我解决这个问题。我搜索这个问题,但我没有找到确切的错误。

 protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);
        //RequestedOrientation = Android.Content.PM.ScreenOrientation.Portrait;
        // Create your application here
        SetContentView(Resource.Layout.Login);
        getUser();
        //play background video
        //videoView = FindViewById<VideoView>(Resource.Id.BackVideo);

        IP_Address = FindViewById<EditText>(Resource.Id.IPAddress_Text);
        Username_IV = FindViewById<EditText>(Resource.Id.UserName);
        Password_IV = FindViewById<EditText>(Resource.Id.Password);
        Remember = FindViewById<CheckBox>(Resource.Id.Rembember);
        login = FindViewById<Button>(Resource.Id.Login);
        //speech = new TextToSpeech(this, this);
        IP_Address.Text = "192.168.x.xxx/Sample";
        login.Click += login_Click;
        //login_Click();

        dialog = new ProgressDialog(this);
        dialog.Indeterminate = true;
        dialog.SetCanceledOnTouchOutside(false);
        dialog.SetProgressStyle(ProgressDialogStyle.Spinner);
        dialog.SetMessage("Authenticating...");


    }
  async void login_Click(object sender, EventArgs e)
    {
        try {
            HideKeyBoard();
        dialog.Show();

        var p = new Dictionary<string, string>();
        //speech.Speak("Authenticating", QueueMode.Flush, p);
        if (IP_Address.Text.Length <= 0)
        {
            Toast.MakeText(this, "Please Enter IP Address", ToastLength.Long).Show();
            IP_Address.Focusable = true;
            //speech.Speak("Please Enter Password", QueueMode.Flush, p);
            dialog.Dismiss();
            return;
        }
        if (Username_IV.Text.Length <= 0)
        {
            Toast.MakeText(this, "Please Enter UserName", ToastLength.Long).Show();
            Username_IV.Focusable = true;
            //speech.Speak("Please Enter UserName", QueueMode.Flush, p);
            dialog.Dismiss();
            return;
        }
         if (Password_IV.Text.Length <= 0)
        {
            Toast.MakeText(this, "Please Enter Password", ToastLength.Long).Show();
            Password_IV.Focusable = true;
            //speech.Speak("Please Enter Password", QueueMode.Flush, p);
            dialog.Dismiss();
            return;
        }           
        else
        {

            IPAddress = IP_Address.Text.Trim();
            string API = "http://" + IPAddress + "/api/Sample/LoginCheck?username=" + Username_IV.Text + "&password=" + this.Encrypt(Password_IV.Text) + "";
            HttpClient httpClient = new HttpClient();
            string dataResult = await httpClient.GetStringAsync(API);
            if (Convert.ToBoolean(dataResult))
            {
                Toast.MakeText(this, "Login Success", ToastLength.Long).Show();
                //speech.Speak("Log in Success", QueueMode.Flush,p);                   
                dialog.Dismiss();
                rememberMe();
                StartActivity(typeof(HomeActivity));
            }
            else
            {
                Toast.MakeText(this, "Login failed", ToastLength.Long).Show();

                //speech.Speak("Log in Failed Please Check Your Credentials", QueueMode.Flush, p);
                dialog.Dismiss();
            }
        }
    }
        catch (Exception ex)
        {
            Toast.MakeText(this, "Login failed", ToastLength.Long).Show();
            dialog.Dismiss();
        }
    }

这是我的代码

kicad_git_src$ mkdir build
kicad_git_src$ cd build
build$ cmake ../
build$ bzr whoami "Your Name <name@example.com>"
build$ make

1 个答案:

答案 0 :(得分:0)

需要做很多改变。我已经用一些更改替换了您的代码,并根据您做了其他更改。像UI的ID应该是正确的。

@override 
protected void OnCreate(Bundle savedInstanceState)
    {
        super.OnCreate(savedInstanceState);
        //RequestedOrientation = Android.Content.PM.ScreenOrientation.Portrait;
        // Create your application here
        setContentView(R.layout.Login);
        getUser();
        //play background video
        //videoView = FindViewById<VideoView>(Resource.Id.BackVideo);

        IP_Address = (EditText)findViewById(R.id.IPAddress_Text);
        Also edit other UI componenets Like this.
}