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 to get a view from a custom layout ?

I've created a custom view via .xml file,
and I wanted to add it as a a contentView to an alert Dialog usinf a
dialogBuilder:


AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setNeutralButton( _Res.getString(R.string.close), new
DialogInterface.OnClickListener(){
                        public void onClick(DialogInterface dialog, int which) {
                                myDial.dismiss();
                        }
        });
        builder.setCancelable(true);
        builder.setIcon(R.drawable.my_icon);
        builder.setTitle(R.string.title);

        builder.setView(   HERE I SHOULD USE myCustomLayout   );
        builder.create();

TextView text = (TextView) myCustomLayout.findViewById(R.id.goTotext);
text.setText("toto");
... etc...

builder.show();



The problem is...  I can't get my view from my custom layout...
I only have an  id (int)...

I tried Resource.getLayout(int) => it returns an xmlParser... not very
usefull ...

finally the solution I comes up is so disgusting ( it worked but ...
let's have a look)

AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setNeutralButton( _Res.getString(R.string.close), new
DialogInterface.OnClickListener(){
                        public void onClick(DialogInterface dialog, int which) {
                                myDial.dismiss();
                        }
        });
        builder.setCancelable(true);
        builder.setIcon(R.drawable.my_icon);
        builder.setTitle(R.string.title);

        Dialog tmpDial = new Dialog(this); // create a tmp dialog ...
        tmpDial.setContentView(R.layout.settings_dialog); // put my
custom layout as the content view of the tmp Dialog

        View tmp  = (View)tmpDial.findViewById(R.id.setting_dial_lay); //
get my layout as a View ...
        tmpDial.setContentView(new View(this)); // set a new content
View to the tmp dial to remove my view from his parent... (so sad
isn't it ?)

        builder.setView(tmp); / here I have my view ready to be used....
but isn't it really disgusting ... ??
        builder.create();



... so guys,  how can I do that easily without using such a disgusting
way... ?
--~--~---------~--~----~------------~-------~--~----~

2. Drawing custom images in a ListView

Hi,

I would like to draw custom images within a ListView, for this I have
created a ListView and an ArrayAdapter object. I have specified that
each element of the ListView will be an ImageView which is specified
by an XML layout file. Now, I would like to draw a custom graphic in
each cell depending upon certain paramters. How do
i do this?

Cheers,
Earlence

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

3. Tabs with linear layouts

4. How to find the text of the selected item in the ListView widget?

5. How to store a hashmap in the listview?

6. quoted printable decoder api on Android?

7. No context menu on map view intended??