错误 - 安装android后启动应用程序

时间:2016-08-28 20:47:20

标签: c# android xamarin launching

我为xamarin设计了针对android的小应用程序。它通过Lan向Windows发送一些数据。安装后我试图打开应用程序,我收到错误:

代码申请:

using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
 using Android.OS;
 using System.Net.Sockets;
 using System.Net;
 using System.IO;
 using System.ComponentModel;
using System.Threading;
using System.Text;

namespace Android4programm
{
 [Activity(Label = "Controller", MainLauncher = true, Icon =       "@drawable/icon")]
public class MainActivity : Activity
{
    public EditText editTextMessage;
    public Button buttonConnect;
    public Button buttonDisconnect;
    public Button buttonSend;
    TcpClient client;

    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);
        SetContentView(Resource.Layout.Main);
        buttonConnect = FindViewById<Button>(Resource.Id.button_Connect);
        buttonDisconnect = FindViewById<Button>(Resource.Id.button_Disconnect);
        buttonSend = FindViewById<Button>(Resource.Id.button_Send);
        //editTextMessage = FindViewById<EditText>(Resource.Id.edittext_message);
        editTextMessage = FindViewById<EditText>(Resource.Id.edittext_Message);

        buttonConnect.Click += Connect;
        buttonDisconnect.Click += Disconnect;
        buttonSend.Click += Send;
        client = new TcpClient();

        buttonDisconnect.Enabled = false;
        buttonSend.Enabled = false;
        editTextMessage.Enabled = false;
    }  
    private void Connect(object sender, EventArgs e)
    {
        IPEndPoint IP_End = new IPEndPoint(IPAddress.Parse("192.168.1.1"), 12345);
        client.Connect(IP_End);
        buttonConnect.Text = "Connected";
        buttonConnect.Enabled = false;
        buttonDisconnect.Enabled = true;
        buttonSend.Enabled = true;
        editTextMessage.Enabled = true;
    }
    private void Disconnect(object sender, EventArgs e)
    {
        string msg = "CancelConnection";
        byte[] buff = Encoding.ASCII.GetBytes(msg);
        client.GetStream().Write(buff, 0, buff.Length);
        client.Close();
    }
    private void Send(object sender, EventArgs e)
    {
        string msg;
        if (editTextMessage.Text!=null)
        {
            msg = editTextMessage.Text;
        }
        else
        {
            msg = "Deafult message";
        }

        byte[] buff = Encoding.ASCII.GetBytes(msg);
        client.GetStream().Write(buff, 0, buff.Length);
    }
}
}

搜索论坛:

  • 我重新安装了应用
  • 我清理现金
  • 我添加了所有权限
  • 我的版本android 2.3.5有效,程序需要2.3 API 10 lvl

0 个答案:

没有答案