Force Close Message

Discussion in 'Application Development' started by Ganesh, Jan 4, 2010.

  1. Ganesh

    Ganesh Member
    15

    Dec 25, 2009
    18
    0
    15
    package com.SampleProject2;
    import android.app.Activity;
    import android.app.PendingIntent;
    import android.content.BroadcastReceiver;
    import android.content.Context;
    import android.content.Intent;
    import android.content.IntentFilter;
    import android.database.sqlite.SQLiteDatabase;
    import android.os.Bundle;
    import android.telephony.SmsManager;
    import android.telephony.TelephonyManager;
    import android.text.Layout;
    import android.view.View;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.LinearLayout;
    import android.widget.Toast;
    import android.view.KeyEvent;
    public class SampleProject2 extends Activity {
    LinearLayout linearLayout;
    Layout flowlayout;
    EditText phoneNum;
    Button callBtn;
    SmsManager sms;
    TelephonyManager telephonyManager;
    SQLiteDatabase database;
    //public DatabaseHelper db;
    PendingIntent pi = PendingIntent.getBroadcast(this, 0, new Intent(), 0);
    // Table name
    public static final String TABLE = "events";
    // Columns public
    static final String ISMINUM = "isminum";
    public static final String TITLE = "title";
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //sms = SmsManager.getDefault();
    telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    linearLayout = new LinearLayout(this);
    phoneNum = new EditText(this);
    phoneNum.setHint("Enter Number Here");
    callBtn = new Button(this);
    callBtn.setText("Call..");
    phoneNum.setWidth(200);
    linearLayout.addView(phoneNum);
    linearLayout.addView(callBtn);
    setContentView(linearLayout);
    callBtn.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {
    MakeCall();
    ///sendSMS("9860650337", "New Message");
    }
    });
    }
    public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_CALL) {
    MakeCall();
    sendSMS("9898989898","Sample Message");
    }
    return false;
    }

    public void MakeCall() {
    phoneNum.setText("" + telephonyManager.getSubscriberId());


    }

    /*
    private void sendSMS( String phoneNumber, String message)
    {
    String SENT = "SMS_SENT";
    String DELIVERED = "SMS_DELIVERED";

    PendingIntent sentPI = PendingIntent.getBroadcast(this, 0,
    new Intent(SENT), 0);

    PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0,
    new Intent(DELIVERED), 0);
    registerReceiver(new BroadcastReceiver(){
    @Override
    public void onReceive(Context arg0, Intent arg1) {
    switch (getResultCode())
    {
    case Activity.RESULT_OK:
    Toast.makeText(getBaseContext(), "SMS sent",
    Toast.LENGTH_SHORT).show();
    break;
    case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
    Toast.makeText(getBaseContext(), "Generic failure",
    Toast.LENGTH_SHORT).show();
    break;
    case SmsManager.RESULT_ERROR_NO_SERVICE:
    Toast.makeText(getBaseContext(), "No service",
    Toast.LENGTH_SHORT).show();
    break;
    case SmsManager.RESULT_ERROR_NULL_PDU:
    Toast.makeText(getBaseContext(), "Null PDU",
    Toast.LENGTH_SHORT).show();
    break;
    case SmsManager.RESULT_ERROR_RADIO_OFF:
    Toast.makeText(getBaseContext(), "Radio off",
    Toast.LENGTH_SHORT).show();
    break;
    }
    }
    }, new IntentFilter(SENT));

    registerReceiver(new BroadcastReceiver(){
    @Override
    public void onReceive(Context arg0, Intent arg1) {
    switch (getResultCode())
    {
    case Activity.RESULT_OK:
    Toast.makeText(getBaseContext(), "SMS delivered",
    Toast.LENGTH_SHORT).show();
    break;
    case Activity.RESULT_CANCELED:
    Toast.makeText(getBaseContext(), "SMS not delivered",
    Toast.LENGTH_SHORT).show();
    break;
    }
    }
    }, new IntentFilter(DELIVERED));

    try
    {
    SmsManager sms = SmsManager.getDefault();
    sms.sendTextMessage(phoneNumber, null, message, sentPI, deliveredPI);
    }
    catch (Exception e)
    {
    System.out.println(""+e.getStackTrace());
    }
    }
    */



    }
     

    Advertisement
  2. eclipsed4utoo

    eclipsed4utoo Well-Known Member
    43

    Nov 12, 2009
    435
    27
    43
    Software Developer
    Florence, SC
    you can use code tags to properly format the code.

    [ code] [/code]

    just remove the space in the first tag, and it will turn into this...

    Code (Text):
    1.  
    2. String test = "";
    3.  
     
  3. Ganesh

    Ganesh Member
    15

    Dec 25, 2009
    18
    0
    15
    Hello Friends,

    The actual problem with the above code is.... It is executing on emulator but not getting installed on device The Error Message is " The application Sampleproject2 is closed unexpectedly" The Only option shown is "Force Close".


    In above application i am trying to send SMS and get IMSI number of SIM card on one click.


    Thank you in advance
     
  4. eclipsed4utoo

    eclipsed4utoo Well-Known Member
    43

    Nov 12, 2009
    435
    27
    43
    Software Developer
    Florence, SC
    Use logcat in Eclipse. It will show you the exact error message that is occuring.
     
  5. Ganesh

    Ganesh Member
    15

    Dec 25, 2009
    18
    0
    15
    Hello eclipsed4utoo,

    I really dont know how to check log in android. I have tried to give command "adb logcat" in command prompt. I got some information displayed after it.... I read almost every line of it... but unable to understand it OR unable to use it..


    Can u explain me in detail about logcat?


    Thank you in advance
     
  6. eclipsed4utoo

    eclipsed4utoo Well-Known Member
    43

    Nov 12, 2009
    435
    27
    43
    Software Developer
    Florence, SC
    Logcat is in Eclipse. At the top-right side of Eclipse, you will see "Debug" and "Java" buttons. Click "Debug". That will switch the view to DEBUG view. At the bottom right, you will see a tab view with windows. One of those windows should be "logcat". Error messages will be shown in red with the stack trace.
     
  7. Ganesh

    Ganesh Member
    15

    Dec 25, 2009
    18
    0
    15
    Hello eclipsed4utoo,


    I have checked the logcat using Eclipse (Windows-->Others--->logcat). I read this information also. And read the red coloured liines twice for understanding. I t had given me and uncaught Exception error. So I surrounded my code with TRY - CATCH (firstly part by part and then the whole code). But still i am facing the same problem

    Thank you in advance
     
  8. eclipsed4utoo

    eclipsed4utoo Well-Known Member
    43

    Nov 12, 2009
    435
    27
    43
    Software Developer
    Florence, SC
    post the FULL error message including the entire stack trace. Basically, post all of the red lines for the exception.
     
  9. Ganesh

    Ganesh Member
    15

    Dec 25, 2009
    18
    0
    15
    Hello eclipsed4utoo,


    I created the new project with same source cod. Then deleted all virtual devices. Then created the virtual devices again and the code worked on device. I guess the problem was with any of virtual device. THANK YOU from the bottom of heart for your advice and help.


    Regards,

    Ganesh
     

Share This Page

Loading...