tags:

views:

44

answers:

2

I am trying to create a very simple help page in my app. The layout xml for the page contains only a textview that displays the help info. In the Eclipse layout view, the layout looks perfect... however, when i try to load it in the emulator (via an OptionsMenu) it comes up as a blank black screen. What am I doing wrong??

Here is the Code:

//This is my Help page code

package com.soapbox.servicerec;

import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuItem;

public class HelpPage extends Activity {

 private static final int INSERT_ID = Menu.FIRST;

 private static final int ACTIVITY_CREATE=0;


  protected void onCreate(){
   setContentView(R.layout.help_page);
         setTitle(R.string.help_title);
           }

  public boolean onCreateOptionsMenu(Menu menu) {
         super.onCreateOptionsMenu(menu);
         menu.add(0, INSERT_ID, 0, R.string.menu_insert);
         return true;
}
  public boolean onMenuItemSelected(int featureId, MenuItem item) {
         switch(item.getItemId()) {
             case INSERT_ID:
                 createNote();
                 return true;
         }
         return super.onMenuItemSelected(featureId, item);
  }
  private void createNote() {
         Intent i = new Intent(this, NoteEdit.class);
         startActivityForResult(i, ACTIVITY_CREATE);

     }
}

AND the layout XML...

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"

     android:layout_height="fill_parent"
     android:orientation="vertical"
     android:background="@android:color/white">

   <TextView android:textSize="16px" android:textColor="@android:color/black" android:layout_height="fill_parent" 
   android:layout_width="fill_parent" android:gravity="center_horizontal" android:paddingLeft="10px" 
   android:paddingRight="10px" android:text="@string/help_text"/>

</LinearLayout>
A: 

Your onCreate method signature is wrong.

notice the difference below

your method protected void onCreate()

proper way @Override public void onCreate(Bundle savedInstanceState)

The @Override notation is optional, but very useful because it ensure the method signature matches one from a parent class, helping prevent these situations.

smith324
Thank you so much... I am trying to teach myself Java/Android programming via the tutorials and a lot of trial and error. I really appreciate all the help from people on this site!One last question: What is the purpose of the (Bundle savedInstanceState) bit and what exactly was causing my method to fail?
Frank Bozzo
The bundle is so you can save your activity state between activity states. Your method isn't failing, it's just not being called. You have to override the class method
Falmarri
A: 

Check Chris response, you must have your onCreate function defined as ::

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
        setContentView(R.layout.help_page);
        setTitle(R.string.help_title);
}
Jorgesys