Application GetGSMStrength closed unexpectedly. Please try again

571 views Asked by At

I am a newbie to android..I have created the following application to return the Signal Strength

package com.example.GetGsmSignalStrength;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.telephony.PhoneStateListener;
import android.telephony.SignalStrength;
import android.telephony.TelephonyManager;
import android.widget.Toast;
import android.os.Bundle;

public class GetGsmSignalStrength extends Activity
{
   /* This variables need to be global, so we can used them onResume and onPause method to
      stop the listener */
   TelephonyManager        Tel;
   MyPhoneStateListener    MyListener;

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

        /* Update the listener, and start it */
        MyListener   = new MyPhoneStateListener();
        Tel       = ( TelephonyManager )getSystemService(Context.TELEPHONY_SERVICE);
      Tel.listen(MyListener ,PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
    }

    /* Called when the application is minimized */
    @Override
   protected void onPause()
    {
      super.onPause();
      Tel.listen(MyListener, PhoneStateListener.LISTEN_NONE);
   }

    /* Called when the application resumes */
   @Override
   protected void onResume()
   {
      super.onResume();
      Tel.listen(MyListener,PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
   }

   /* —————————– */
    /* Start the PhoneState listener */
   /* —————————– */
    private class MyPhoneStateListener extends PhoneStateListener
    {
      /* Get the Signal strength from the provider, each tiome there is an update */
      @Override
      public void onSignalStrengthsChanged(SignalStrength signalStrength)
      {
         super.onSignalStrengthsChanged(signalStrength);
         Toast.makeText(getApplicationContext(), "Go to Firstdroid!!! GSM Cinr = "
            + String.valueOf(signalStrength.getGsmSignalStrength()), Toast.LENGTH_SHORT).show();
      }

    };/* End of private Class */

}/* GetGsmSignalStrength */

but when I run it its showing the error mentioned in the title in a pop up box. I have made the necessary permission changes in androidmanifest.xml and thats all what I have done.

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

Why is the error showing up? When does it shows up in general? Thanks

1

There are 1 answers

0
JimmyB On BEST ANSWER

The "error" shows up every time an application causes a failure, an exception, which it was not designed to handle appropriately.

In Java, an exception is usually associated with the type of error that occurred, a message detailing the error, and a stack trace which allows to locate where exactly in the code the error occurred.

When an exception is not handled by the application the App is forced to close and the exception will be logged to the Android log file, the 'logcat', accessible via DDMS or from the shell via adb logcat.