Soru & Cevap

openfire, xmpp, smack kullanırken connect() olamıyorum

08.04.2014 - 11:11

smack jar'larını kullanarak kendi kurduğum openfire sunucusuna bağlanmak istiyorum. Android programını yazdım, programı similatörde çalıştırdığımda "Unfortunately, <App Adı> has stopped" hatası alıyorum ve uygulama kendisini kapatıyor. Aşağıda kodları ve hata raporunu ekledim. sorunumu nasıl giderebilirim?

  

[code] @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        if (savedInstanceState == null) {
            getFragmentManager().beginTransaction()
                    .add(R.id.container, new PlaceholderFragment()).commit();
        }
        
AlertDialog alertMessage = new AlertDialog.Builder(this).create();
        alertMessage.setMessage("1c");alertMessage.show();
        ConnectionConfiguration config = new ConnectionConfiguration("192.168.10.149", 5222);
        XMPPConnection connection = new XMPPConnection(config);
        

        try {
            connection.connect();
        } catch (XMPPException e) {
            alertMessage.setMessage("HATA 2: " + e.getMessage());alertMessage.show();
            e.printStackTrace();
        }
        
    }[/code]

CHATLOG

[code]04-04 12:45:46.961: E/Trace(1209): error opening trace file: No such file or directory (2)
04-04 12:45:47.621: D/dalvikvm(1209): GC_FOR_ALLOC freed 46K, 7% free 2572K/2740K, paused 36ms, total 54ms
04-04 12:45:47.621: I/dalvikvm-heap(1209): Grow heap (frag case) to 3.233MB for 635812-byte allocation
04-04 12:45:47.661: D/dalvikvm(1209): GC_FOR_ALLOC freed 2K, 6% free 3190K/3364K, paused 38ms, total 38ms
04-04 12:45:47.721: D/dalvikvm(1209): GC_CONCURRENT freed <1K, 5% free 3210K/3364K, paused 23ms+14ms, total 53ms
04-04 12:45:47.781: I/SmackConfiguration(1209): No configuration file found
04-04 12:45:47.791: D/AndroidRuntime(1209): Shutting down VM
04-04 12:45:47.791: W/dalvikvm(1209): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
04-04 12:45:47.801: E/AndroidRuntime(1209): FATAL EXCEPTION: main
04-04 12:45:47.801: E/AndroidRuntime(1209): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mrt.chatsmack17/com.mrt.chatsmack17.MainActivity}: android.os.NetworkOnMainThreadException
04-04 12:45:47.801: E/AndroidRuntime(1209):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
04-04 12:45:47.801: E/AndroidRuntime(1209):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
04-04 12:45:47.801: E/AndroidRuntime(1209):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
04-04 12:45:47.801: E/AndroidRuntime(1209):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
04-04 12:45:47.801: E/AndroidRuntime(1209):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-04 12:45:47.801: E/AndroidRuntime(1209):     at android.os.Looper.loop(Looper.java:137)
04-04 12:45:47.801: E/AndroidRuntime(1209):     at android.app.ActivityThread.main(ActivityThread.java:5041)
04-04 12:45:47.801: E/AndroidRuntime(1209):     at java.lang.reflect.Method.invokeNative(Native Method)
04-04 12:45:47.801: E/AndroidRuntime(1209):     at java.lang.reflect.Method.invoke(Method.java:511)
04-04 12:45:47.801: E/AndroidRuntime(1209):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
04-04 12:45:47.801: E/AndroidRuntime(1209):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
04-04 12:45:47.801: E/AndroidRuntime(1209):     at dalvik.system.NativeStart.main(Native Method)
04-04 12:45:47.801: E/AndroidRuntime(1209): Caused by: android.os.NetworkOnMainThreadException
04-04 12:45:47.801: E/AndroidRuntime(1209):     at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1117)
04-04 12:45:47.801: E/AndroidRuntime(1209):     at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:84)
04-04 12:45:47.801: E/AndroidRuntime(1209):     at libcore.io.IoBridge.connectErrno(IoBridge.java:127)
04-04 12:45:47.801: E/AndroidRuntime(1209):     at libcore.io.IoBridge.connect(IoBridge.java:112)
04-04 12:45:47.801: E/AndroidRuntime(1209):     at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
04-04 12:45:47.801: E/AndroidRuntime(1209):     at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:459)
04-04 12:45:47.801: E/AndroidRuntime(1209):     at java.net.Socket.connect(Socket.java:842)
04-04 12:45:47.801: E/AndroidRuntime(1209):     at java.net.Socket.connect(Socket.java:785)
04-04 12:45:47.801: E/AndroidRuntime(1209):     at org.jivesoftware.smack.proxy.DirectSocketFactory.createSocket(DirectSocketFactory.java:45)
04-04 12:45:47.801: E/AndroidRuntime(1209):     at org.jivesoftware.smack.XMPPConnection.connectUsingConfiguration(XMPPConnection.java:557)
04-04 12:45:47.801: E/AndroidRuntime(1209):     at org.jivesoftware.smack.XMPPConnection.connect(XMPPConnection.java:1010)
04-04 12:45:47.801: E/AndroidRuntime(1209):     at com.mrt.chatsmack17.MainActivity.onCreate(MainActivity.java:41)
04-04 12:45:47.801: E/AndroidRuntime(1209):     at android.app.Activity.performCreate(Activity.java:5104)
04-04 12:45:47.801: E/AndroidRuntime(1209):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
04-04 12:45:47.801: E/AndroidRuntime(1209):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)[/code]

18 Görüntülenme

3 Cevap

Sitedeki sorulara cevap verebilmek için giriş yapın ya da üye olun.

Profile picture for user yesilce
yesilce
03.07.2014 - 05:11

smack jar'ını projeye referans ekleyerek sorunu çözdüm.

Profile picture for user ademkoc
ademkoc
23.04.2014 - 01:11

İlk olarak "C:\Program Files (x86)\Openfire\conf " içindeki openfire.xml dosyasına bunu ekle (</jive> etiketinden önce)
[code]
<network>
<interface>ip adresin</interface>
</network>
[/code]
AndroidManifest.xml dosyanındada <uses-permission android:name="android.permission.INTERNET" /> ekle ve "android:targetSdkVersion" yazan kısmı sil.
[code]

public class openFireBaglan extends AsyncTask<XMPPConnection, XMPPConnection, XMPPConnection> {

        @Override
        protected XMPPConnection doInBackground(XMPPConnection... arg0) {
            ConnectionConfiguration config = new ConnectionConfiguration("192.168.1.2", 5222);
            XMPPConnection connection = new XMPPConnection(config);
            config.setCompressionEnabled(true);
            config.setSASLAuthenticationEnabled(false);
            return connection;
        }
        
        @Override
        protected void onPostExecute(XMPPConnection result) {
           super.onPostExecute(result);
           try {
               result.connect();
               result.login("adem", "1234");
               Presence p = new Presence(Presence.Type.available);
               p.setFrom(result.getUser());
               p.setMode(Presence.Mode.available);
               result.sendPacket(p);
            } catch (XMPPException e) {
                
            }
        }
        
        
    
    }

[/code]

[code]new openFireBaglan().execute((XMPPConnection) null);[/code]
Eğer olmazsa güvenik duvarını kapatıp dene

Profile picture for user yesilce
yesilce
21.04.2014 - 02:27

hala aynı hatayı almaya devam ediyorum...