[Android Q&A, Help & Troubleshooting] tkansara:
Hey Guys

I am developing a chat client that would connect to gtalk server.. I am just doing this to learn Android programming. I know that I have to use XMPP to connect to google talk server. I am having issues when attempting to do Connection.connect(). I get a whole bunch of errors from FatalException, Networkmainthreadexception and so on...

I ran the same code in a seperate java project and the whole thing ran without any problems.. I have enabled internet in the manifest file.

<uses-sdk android:minSdkVersion="15" />

<uses-permission android:name="android.permission.INTERNET"/>

<application​

Here is my main.xml

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="(removed due to # of post restriction...)://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="1">

<TableRow>
<TextView
android:text="@string/user_name"
android:id="@+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>

<EditText
android:text=""
android:id="@+id/txtUname"
android:layout_width="fill_parent"
android:hint="@string/userName_hint"
android:layout_height="wrap_content">
</EditText>
</TableRow>

<TableRow>
<TextView
android:text="@string/password"
android:id="@+id/TextView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>

<EditText
android:text=""
android:id="@+id/txtPwd"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="@string/password_hint"
android:password="true">
</EditText>
</TableRow>

<TableRow>
<Button
android:text="Cancel"
android:id="@+id/btnCancel"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</Button>

<Button
android:text="Login"
android:id="@+id/btnLogin"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</Button>

</TableRow>

</TableLayout>

MyGtalkActivity.java

package com.tanmay.gtalk;

import android.app.Activity;
import android.os.Bundle;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.Presence;

public class MyGTalkActivity extends Activity {

EditText txtUserName;
EditText txtPassword;
Button btnLogin;
Button btnCancel;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

txtUserName = (EditText) this.findViewById(R.id.txtUname);
txtPassword = (EditText) this.findViewById(R.id.txtPwd);
btnLogin = (Button) this.findViewById(R.id.btnLogin);
btnLogin = (Button) this.findViewById(R.id.btnLogin);
//String userName = (String) getText(R.id.txtUname);

btnLogin.setOnClickListener(new OnClickListener() {

public void onClick(View v) {
// TODO Auto-generated method stub

//Log.i(tag, msg)
/*ConnectionConfiguration connConfig =
new ConnectionConfiguration("talk.google.com", 5222, "gmail.com");

XMPPConnection connection = new XMPPConnection(connConfig);*/

ConnectionConfiguration cc = new ConnectionConfiguration("talk.google.com", 5222, "gmail.com");
XMPPConnection xmpp = new XMPPConnection(cc);

try {
System.out.println("testtt");
xmpp.connect();
xmpp.login("tester32.test@gmail.com", "***");
Presence presence = new Presence(Presence.Type.available);
xmpp.sendPacket(presence);
System.out.println("testt123");
//Log.i("XMPPClient", "[SettingsDialog] Connected to " + connection.getHost());
} catch (XMPPException e) {
// TODO Auto-generated catch block
Log.e("XMPPClient", "[SettingsDialog] Failed to connect to " + xmpp.getHost());
Log.e("XMPPClient", e.toString());
//e.printStackTrace();
}

//dismiss();
}
});
}
}

I have attached the errors that i get on my console...Any sugestions ?

thanks

Tanmay