Null Pointer Exception on accessing value of EditText

by Ankur Kumar » Fri, 20 May 2011 09:30:39 GMT


Sponsored Links
 Hello Developers,

Please help me with this problem. I am getting
java.lang.NullPointerException at step 3 in my code. Have not been
able to figure this out. The value I am entering in the EditText is
not empty.

                       1.  EditText IPInput = (EditText)
findViewById(R.id.ip);
                       2.  IPInput.getText().toString(); System.out.println(ip);
                       3.  System.out.println(IPInput.getText().toString());

--
Regards,
Ankur Kumar

-- 



Null Pointer Exception on accessing value of EditText

by Ankur Kumar » Fri, 20 May 2011 09:30:40 GMT


 Hello Developers,

Please help me with this problem. I am getting*java.lang.NullPointerException
* at step 3 in my code. Have not been able to figure this out. The value I
am entering in the EditText is not empty.

                       1.  EditText IPInput = (EditText)
findViewById(R.id.ip);
       2.  IPInput.getText().toString(); System.out.println(ip);
        3.  System.out.println(IPInput.getText().toString());



--
Regards,
Ankur Kumar

-- 


Sponsored Links


Other Threads

1. Getting phone to work with debugger

I've just gotten an HTC Aria.  I've been unable to get ADB to recognize that
the phone is attached.
ADB finds my Motorola Backflip just fine.
The Aria does have the USB Debugging enabled.
I've tried following the instructions at
http://developer.android.com/guide/developing/device.html  and
http://developer.android.com/sdk/win-usb.html , but of course, neither one
resembles what you actually see in the SDK Manager tool, or the Win 7
control panel.
SDKManager has downloaded the "Google Usb Driver package, revision 4" - to
some place, but I have no idea where.
Pointing Device Manager at the root of the android SDK dir, it couldn't find
a USB driver.

suggestions?

-- 

2. Problems with display for alarm clock application

Hello all,

I'm building an application that does several different things. My
activities are represented as tabs across the top of the screen and
one of the activies is an alarm clock function. I'm using an activity
instead of a broadcast service to handle what happens when my alarm
goes off and everything is functioning well so far, I just have a
problem with the display.

When the alarm goes off, the activity that pops up covers all of the
tabs (which basically serve as a menu to the other activities) for the
application. I've seen some examples that use intent flags and an
activitygroup in order to keep a new activity under the tabs, but that
code will not work in this situation, at least not as I understand it.

Does anyone know of a way to keep the tabs on top once you land on the
activity that handles the alarm going off?

The reason I'm using an activity instead of a broadcast service is
because the alarm has to be able to play an online stream of audio
when it goes off. I tried to use the broadcast service and it did what
I wanted it to, except that the only way to turn off the stream once
you stop the alarm was to make a notification pop up...I feel this
would be confusing and that people would be more comfortable with a
button that tells them to stop the alarm.

Perhaps I'm going about this the wrong way but if anyone could help I
would really appreciate it.

Below is the code I used to set up the alarm manager:

//set up the intent for the alarm manager
alarmIntent = new Intent(v.getContext(), AlarmReceiver.class);
alarmIntent.putExtra("stream", "http://mp3.wusf.usf.edu:8000/");

//set the pending intent to the intent we just created above
mAlarmSender = PendingIntent.getActivity(v.getContext(), 0,
alarmIntent, 0);

//Set up the alarm manager, using a hard-coded alarm time for now
AlarmManager alarmManager = (AlarmManager)
getSystemService(ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() +
(5 * 1000), mAlarmSender);

And below is the AlarmReceiver class:

public class AlarmReceiver extends Activity {
        private Button stopAlarm;
        private MediaPlayer mediaPlayer;
        private Intent receivedIntent;
        private String streamURL;

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

                //capture the button
                stopAlarm = (Button) findViewById(R.id.stopAlarm);

                //get the extras that were sent
                receivedIntent = getIntent();
                streamURL = receivedIntent.getStringExtra("stream");

                //set up and start the mediaPlayer
                mediaPlayer = new MediaPlayer();
                try
                {
                        mediaPlayer.setDataSource(streamURL);
                        mediaPlayer.prepare();
                        mediaPlayer.start();
                }
                catch (Exception e)
                {
                                                  //exit as quickly as
possible
                        throw new RuntimeException(e);
                }

                //On click listener for the stop button
                stopAlarm.setOnClickListener(new OnClickListener () {
                        public void onClick(View v) {
                                //stop the media player
                                mediaPlayer.stop();
                                //TO DO: switch back to the alarm activity
                        }
                });

        }

        //release the resources for the media player when the activity is
destroyed
        @Override
        protected void onDestroy() {
                super.onDestroy();
                if(mediaPlayer != null)
                {
                        mediaPlayer.release();
                        mediaPlayer = null;
                }
        }
}

Thanks,
DanielleM

-- 

3. The public key in the certificate cannot be used for ENCRYPT_MODE

4. How to know if SDCard scan is over?

5. How to align SurfaceView on Bottom ?

6. Error in merging spannable objects

7. No sound output in speaker on AudioTrack.play