Most basic UI crash

by Jason Tai » Sun, 06 Apr 2008 13:06:15 GMT


Sponsored Links
 Hi,

Keep getting
   "Unable to start
activity...ComponentInfo{...}java.lang.NullPointerException"
error.

Tried couple of basic examples from web, same problem:

Actual Code:

public void onCreate(Bundle icicle)
{
        super.onCreate(icicle);

        setContentView(R.layout.enter_device_name);

        final Button button = (Button) findViewById(R.id.okButt);

        //
***********************************************************************************
        // If I remove the bottom statement, I can see the UI display; a
textedit and a abutton.
        // The line below causes the crash.
        //
***********************************************************************************
        button.setOnClickListener(
                new Button.OnClickListener()
                {
                        public void onClick(View v)
                        {
                        }
                }
        );
}

XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android=" http://schemas.android.com/apk/res/ 
android" android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFEE9"   android:padding="10px">

    <TextView id="@+id/nameLab"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:text="Type your name"/>

    <EditText id="@+id/yourName"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:layout_below="@id/nameLab"/>

    <Button id="@+id/okButt"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_marginLeft="10px"
            android:text="OK"
            android:layout_below="@id/yourName"/>

</RelativeLayout>

SDK: m5. Emulator using HVGA-P.

Also tried to use a dialog box. Also crashes when I call
setOnClickListener.

BTW, the 'okButt' button always display on top of the 'yourName' edit
box, isn't it suppose to be
'layout_below'? Other XML that I copied from some example exibit the
same behavior. Any clue?

Cheers...

Jason Tai
--~--~---------~--~----~------------~-------~--~----~



Most basic UI crash

by Dan U. » Sun, 06 Apr 2008 18:49:31 GMT


 Your layout file is in m3 format. 
 http://code.google.com/android/migrating/m3-to-m5/m5-api-changes.html 



--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


Most basic UI crash

by Jason Tai » Mon, 07 Apr 2008 00:27:02 GMT


 Aha!

It works!

Thanks a lot.

Jason Tai




--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. How do I create a MediaPlayer for a resource without using the resId?

Hello everyone,

This one has had me stumped for the last couple of days. I'm trying to
create a MediaPlayer for a resource I have in res/raw, but I (!!!)DO
NOT(!!!) want to create it by performing MediaPlayer.create(Context
context, int resid), because I am experimenting with a few different
things and I do not want to immediately start blocking by calling
prepare.

If I use:
MediaPlayer mp = new MediaPlayer(this, R.raw.foo);
mp.start();

The sound plays correctly, so I know that the sound is not the issue.
Additionally,
Notification n = new Notification( . . . );
n.sound = "android.resource://my.package.name/" + R.raw.foo;
myNManager.notify(0, n);

will correctly play the sound, so I know the URI I'm using is correct
(at least for that).

However, if I try

MediaPlayer mp = new MediaPlayer();
mp.setDataSource("android.resource://my.package.name/" + R.raw.foo);
mp.prepare();

I will get a null pointer exception when prepare is called. What is
going on here? What am I missing? Is it even possible to do what I
want, and if not, why not? I've been looking at the bytecode for
MediaPlayer, and the only place context is used is for getting the
resource, so I know I don't have to worry about setting that. I can't
peer into setDataSource because it is native.
--~--~---------~--~----~------------~-------~--~----~

2. How to create my own menu?

Hi all,

I want to create my menu. When I press one button, this menu will appear
on the screen's specific position.
There are two types  of menus, context menu and option menu. but I want
one general menu, which I can place it anywhere and also can customize
the width of the menu.

Anyone can help me?
Thanks.



--~--~---------~--~----~------------~-------~--~----~

3. Socket programming error while reading the socke

4. problem when Modifying a xml element with dom

5. Java and mobile phones

6. Article about Android

7. Has anybody been able to blur an image?