Hi aMeeN

The LogCat view is your friend. The cause of the error will always be
displayed there. To display the LogCat view in the current perspective in
Eclipse go to Window->Show View->Other->Android->LogCat.

When I ran your code, I saw this in the LogCat view:

06-19 21:34:29.586: ERROR/AndroidRuntime(279): FATAL EXCEPTION: main
06-19 21:34:29.586: ERROR/AndroidRuntime(279): java.lang.RuntimeException:
Unable to start activity
ComponentInfo{ameen.android.silentModeToggle/ameen.android.silentModeToggle.SilentModelToggleActivity}:
java.lang.NullPointerException
06-19 21:34:29.586: ERROR/AndroidRuntime(279):     at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
06-19 21:34:29.586: ERROR/AndroidRuntime(279):     at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
06-19 21:34:29.586: ERROR/AndroidRuntime(279):     at
android.app.ActivityThread.access$2300(ActivityThread.java:125)
06-19 21:34:29.586: ERROR/AndroidRuntime(279):     at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
06-19 21:34:29.586: ERROR/AndroidRuntime(279):     at
android.os.Handler.dispatchMessage(Handler.java:99)
06-19 21:34:29.586: ERROR/AndroidRuntime(279):     at
android.os.Looper.loop(Looper.java:123)
06-19 21:34:29.586: ERROR/AndroidRuntime(279):     at
android.app.ActivityThread.main(ActivityThread.java:4627)
06-19 21:34:29.586: ERROR/AndroidRuntime(279):     at
java.lang.reflect.Method.invokeNative(Native Method)
06-19 21:34:29.586: ERROR/AndroidRuntime(279):     at
java.lang.reflect.Method.invoke(Method.java:521)
06-19 21:34:29.586: ERROR/AndroidRuntime(279):     at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
06-19 21:34:29.586: ERROR/AndroidRuntime(279):     at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
06-19 21:34:29.586: ERROR/AndroidRuntime(279):     at
dalvik.system.NativeStart.main(Native Method)
06-19 21:34:29.586: ERROR/AndroidRuntime(279): Caused by:
java.lang.NullPointerException
06-19 21:34:29.586: ERROR/AndroidRuntime(279):     at
ameen.android.silentModeToggle.SilentModelToggleActivity.onCreate(SilentModelToggleActivity.java:22)
06-19 21:34:29.586: ERROR/AndroidRuntime(279):     at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
06-19 21:34:29.586: ERROR/AndroidRuntime(279):     at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
06-19 21:34:29.586: ERROR/AndroidRuntime(279):     ... 11 more

As you can see, the cause of the problem is just a NullPointerException on
line 22 of your activity owing to the fact that mAudioManager is used before
it is unitialized. You initialize it on line 28. I was able to get your app
to run by uncommenting the code and changing the onCreate() method to the
following:

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        mAudioManager = (AudioManager)getSystemService(AUDIO_SERVICE);
        int ringerMode = mAudioManager.getRingerMode();

        checkIfPhoneIsSilent();

        setButtonClickListener();
    }

Not a bad first Android app!

On Sun, Jun 19, 2011 at 8:46 AM, aMeeN <[email protected]> wrote:

> Hello All,
>
>
> I downloaded Eclipse Java (this time) and did all the integration and
> linking with Android SDK after I finished ...
> I tried to run the application again .. but unfortunately getting the
> same error.
>
> I am seriously started thinking to give up   with android
> development .. this is one bug takes me around 10 days
>
> I will give it some more tries and will see.
>
>
> On Jun 18, 11:14 am, aMeeN <[email protected]> wrote:
> > Thank you Mr. Zsolt for your help.
> >
> > I wasn't sure about the error reason, Android and Eclipse both are new
> > to me .. thats why I am confused.
> >
> > I will try to download Eclipse and prepare the development environment
> > again.
> >
> > Hope it will work properly .. I will update this post with the
> > result.
> >
> > Thanks again.
> >
> > On Jun 18, 7:29 am, Zsolt Vasvari <[email protected]> wrote:
> >
> >
> >
> >
> >
> >
> >
> > > Why do you think the error is caused by your code?  The stack trace
> > > you are showing has got something to do with Eclipse, not an Android
> > > application.
> >
> > > On Jun 17, 10:25 pm, aMeeN <[email protected]> wrote:
> >
> > > > I am writing my first Andoid application. And facing an error .. I
> > > > consider it too strange but also expecting to face a lot of strange
> > > > errors and bugs.
> >
> > > > I googled to find out what cause that error. And tried to learn how
> to
> > > > debug Android application on Eclipse but no luck.
> >
> > > > The application I am writing is having only an image and button. The
> > > > button is to switch the mobile from normal mode to silent mode and
> the
> > > > reverse and the image is an indicator the for which mode currently is
> > > > active.
> >
> > > > When I got the error I highlighted all the the code and started
> > > > unhighlighting one by one, till I found the this line specifically
> > > > cause the error:
> >
> > > > int ringerMode = mAudioManager.getRingerMode();
> >
> > > > when I run the application, on the Debug prespective view , in the
> > > > error log tab I am getting :
> >
> > > > Error:
> >
> > > > No command output when running: 'am start -n
> > > > ameen.android.silentModeToggle/
> > > > ameen.android.silentModeToggle.SilentModelToggleActivity -a
> > > > android.intent.action.MAIN -c android.intent.category.LAUNCHER' on
> > > > device emulator-5554
> >
> > > > Exception Stack Track:
> >
> > > > com.android.ddmlib.ShellCommandUnresponsiveException
> > > >         at
> com.android.ddmlib.AdbHelper.executeRemoteCommand(AdbHelper.java:
> > > > 408)
> > > >         at
> com.android.ddmlib.Device.executeShellCommand(Device.java:276)
> > > >         at
> > > >
> com.android.ide.eclipse.adt.internal.launch.ActivityLaunchAction.doLaunchAc
> ­tion(ActivityLaunchAction.java:
> > > > 74)
> > > >         at
> > > >
> com.android.ide.eclipse.adt.internal.launch.AndroidLaunchController.launchA
> ­pp(AndroidLaunchController.java:
> > > > 1147)
> > > >         at
> > > >
> com.android.ide.eclipse.adt.internal.launch.AndroidLaunchController.simpleL
> ­aunch(AndroidLaunchController.java:
> > > > 824)
> > > >         at
> > > >
> com.android.ide.eclipse.adt.internal.launch.AndroidLaunchController.access
> > > > $3(AndroidLaunchController.java:808)
> > > >         at
> com.android.ide.eclipse.adt.internal.launch.AndroidLaunchController
> > > > $3.run(AndroidLaunchController.java:656)
> >
> > > > Session Data:
> >
> > > > eclipse.buildId=M20110210-1200
> > > > java.version=1.6.0_24
> > > > java.vendor=Apple Inc.
> > > > BootLoader constants: OS=macosx, ARCH=x86, WS=cocoa, NL=en_US
> > > > Framework arguments:  -keyring /Users/ameen/.eclipse_keyring -
> > > > showlocation
> > > > Command-line arguments:  -os macosx -ws cocoa -arch x86 -keyring /
> > > > Users/ameen/.eclipse_keyring -showlocation
> >
> > > > I uploaded the zipped project folder into my DropBox folder if
> someone
> > > > iterested to test it:
> >
> > > >http://dl.dropbox.com/u/4392604/Silent_Model_Toggle.zip
> >
> > > > I also explained this bug with screen shots in my blog, if you wanna
> > > > have a look:
> http://enabofaisal.wordpress.com/2011/06/17/the-application-process-h...
> >
> > > > Please someone help me  =)
> >
> > > > BTW .. as shown above (as Session Data) I have intel x86 MAC OS 10.6
> > > > and using Eclipse of these infos:
> > > > Eclipse SDK
> >
> > > > Version: 3.6.2
> > > > Build id: M20110210-1200
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to