1 Replies - 515 Views - Last Post: 05 December 2014 - 08:20 AM

#1 cybepheonix   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 22-October 12

Android: NullPointerException when registering to SIP server

Posted 05 December 2014 - 07:54 AM

Hello,

My name is Danny and i had been working on this VOIP system. I am currently doing the programming for the mobile app which will be running on android. Android has an SIP library built in it. Documentation found here. The problem is when i run the app it closes because of null pointer exception error. The logcat is attached. according to the log the error is triggered at his particular line

manager.open(me, pi, null);


I would really appreciate any help you can shed here. I am debugging for some time now already and i think i needed help from the development community.

Full Project here

Thanks in advance :)


package com.BZ.buzzapp;

import android.support.v7.app.ActionBarActivity;
import android.net.sip.SipException;
import android.net.sip.SipManager;
import android.net.sip.SipProfile;
import android.net.sip.SipRegistrationListener;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.*;

import android.app.AlertDialog;
import android.app.PendingIntent;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.ParseException;
import android.net.sip.SipException;
import android.net.sip.SipManager;
import android.net.sip.SipProfile;
import android.net.sip.SipRegistrationListener;
import android.util.Log;


public class MainActivity extends ActionBarActivity {
	
	public static SipManager manager = null;
	public static SipProfile me = null;
	public static String extension = "4482";
	public static String password  = "264350";
	public static String domain    = "192.241.219.238";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    	
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        
        Button callInvoked = (Button)findViewById(R.id.callInvoke);
        final TextView output = (TextView) findViewById (R.id.output);
        
        callInvoked.setonclickListener(new View.onclickListener() {
            public void onclick(View v) {
            	// Register to VOIP server pbx1.cybermesh.tk on click call
            	output.setText("Registration Initiated");
            	initializeManager();
            	register();
            }
        });
        
        
    }
  
    @Override
    public void onstart() {
        super.onstart();
        // When we get back from the preference setting Activity, assume
        // settings have changed, and re-login with new auth info.
        initializeManager();
    }
    
    
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
    
    /* This code allows the android application to register to the sip sever 
     * with the SIP manager initated this will try to connect to server using the SIP profile
     * given the extension and the password
     */
    
    public void  register(){
    	
        if (me != null) {
            closeLocalProfile();
        }

        String username = "4482";
        String domain = "192.241.219.238";
        String password = "264350";
        int    port = 15060;
        
        // displaying the credentials
        System.out.println(username + " " + domain + " " + password);
        
        if (username.length() == 0 || domain.length() == 0 || password.length() == 0) {
            updateStatus(username + " " + domain + " " + password);
            return;
        }

        try {
            
			try {
				SipProfile.Builder builder = new SipProfile.Builder(username, domain);
				builder.setPassword(password);
				builder.setPort(port);
				me = builder.build();
				
			} catch (java.text.ParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				//display error
				System.out.println(e.toString());
			}
			
            Intent i = new Intent();
            i.setAction("android.SipDemo.INCOMING_CALL");
            PendingIntent pi = PendingIntent.getBroadcast(this, 0, i, Intent.FILL_IN_DATA);
            manager.open(me, pi, null);


            // This listener must be added AFTER manager.open is called,
            // Otherwise the methods aren't guaranteed to fire.

            manager.setRegistrationListener(me.getUriString(), new SipRegistrationListener() {
                    public void onRegistering(String localProfileUri) {
                    	System.out.println("Registering with SIP Server...");
                        updateStatus("Registering with SIP Server...");
                    }

                    public void onRegistrationDone(String localProfileUri, long expiryTime) {
                    	System.out.println("Ready...");
                        updateStatus("Ready");
                    }

                    public void onRegistrationFailed(String localProfileUri, int errorCode,
                            String errorMessage) {
                    	System.out.println("Registration failed.  Please check settings.");
                        updateStatus("Registration failed.  Please check settings.");
                    }
                });
        
        } catch (SipException se) {
            updateStatus("Connection error.");
        }	
    }
    
    public void updateStatus(final String status) {
        // Be a good citizen.  Make sure UI changes fire on the UI thread.
        this.runOnUiThread(new Runnable() {
            public void run() {
                TextView labelView = (TextView) findViewById(R.id.output);
                labelView.setText(status);
            }
        });
    }
    
    /* This function is called to close the current SIP profile thus destroying the session
     * 
     */
    
    public void closeLocalProfile() {
        if (manager == null) {
            return;
        }
        try {
            if (me != null) {
                manager.close(me.getUriString());
            }
        } catch (Exception ee) {
            Log.d("Buzapp Session/onDestroy", "Failed to close local profile.", ee);
        }
    }
    
    public void initializeManager() {
        if(manager == null) {
          manager = SipManager.newInstance(this);
          //for debugging purpose only
          System.out.println("SIP manager Initiated Sucessfully");
        }
        else{
        	System.out.println("SIP manager not null");
        }
    }
    
}



Attached File(s)

  • Attached File  log.txt (97bytes)
    Number of downloads: 101


Is This A Good Question/Topic? 0
  • +

Replies To: Android: NullPointerException when registering to SIP server

#2 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 14097
  • View blog
  • Posts: 56,497
  • Joined: 12-June 08

Re: Android: NullPointerException when registering to SIP server

Posted 05 December 2014 - 08:20 AM

Please do not create duplicate topics. Closing.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1