0

I programmed small app for android by xamarin. It sends some data to windows via Lan. After installing I tried to open app and I got error:

code application:

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);
    }
}
}

Searching forums:

  • I reinstalled app
  • I cleared cash
  • I added all permissions
  • My version android 2.3.5 is valid, program needs 2.3 API 10 lvl
Shabbir Dhangot
  • 8,954
  • 10
  • 58
  • 80
Cenarius
  • 175
  • 1
  • 1
  • 12

0 Answers0