title: PackageInfo versionCode and versionName null on phone, but works on emulator
body: <p>I am building a private app that will not go through the Marketplace. As a result, I need to pull the current version application (not platform) information and check with the server to see if there is an update. It works great on the emulator, but when I installed the signed APK on my Droid X, it returns null. Here is the code:</p>
  
  <pre><code>PackageInfo pInfo = null;
  
  try {
      pInfo = getPackageManager().getPackageInfo("com.rubiconproject.expenses",
                  PackageManager.GET_META_DATA);
  } catch (NameNotFoundException e) {
      return;
  } 
  String postUrl = DbAdapter.REMOTE_DB +
                  "/application/active-version/platform/android/version/" +
                  pInfo.versionCode + "." + pInfo.versionName;
  </code></pre>
  
  <p>EDIT:</p>
  
  <p>I wrote a much smaller application, below, that displays my problem (TestingActivity.java):</p>
  
  <pre><code>package com.rubiconproject.testing;
  
  import android.app.Activity;
  import android.content.pm.PackageInfo;
  import android.content.pm.PackageManager;
  import android.content.pm.PackageManager.NameNotFoundException;
  import android.os.Bundle;
  import android.widget.TextView;
  
  public class TestingActivity extends Activity {
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
          PackageInfo pInfo = null;
          try {
              pInfo = getPackageManager().getPackageInfo(
                  "com.rubiconproject.testing", PackageManager.GET_META_DATA);
          } catch (NameNotFoundException e) {
              return;
          }
          TextView tt = (TextView)findViewById(R.id.textView1);
          tt.setText(pInfo.versionCode);
          TextView tt2 = (TextView)findViewById(R.id.textView2);
          tt2.setText(pInfo.versionName);
      }
  }
  </code></pre>
  
  <p>And the manifest:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" 
          package="com.rubiconproject.testing"
          android:versionCode="1"
          android:versionName="1.0"&gt;
      &lt;uses-sdk android:minSdkVersion="9" /&gt;
      &lt;application android:icon="@drawable/icon" android:label="@string/app_name"&gt;
          &lt;activity android:name=".TestingActivity"
                    android:label="@string/app_name"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
      &lt;/application&gt;
  &lt;/manifest&gt;
  </code></pre>
  
  <p>adb logcat shows:</p>
  
  <pre><code>E/AndroidRuntime(  335): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.rubiconproject.testing/com.rubiconproject.testing.TestingActivity}: java.lang.NullPointerException
  E/AndroidRuntime(  335):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1622)
  E/AndroidRuntime(  335):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1638)
  E/AndroidRuntime(  335):    at android.app.ActivityThread.access$1500(ActivityThread.java:117)
  E/AndroidRuntime(  335):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:928)
  E/AndroidRuntime(  335):    at android.os.Handler.dispatchMessage(Handler.java:99)
  E/AndroidRuntime(  335):    at android.os.Looper.loop(Looper.java:123)
  E/AndroidRuntime(  335):    at android.app.ActivityThread.main(ActivityThread.java:3647)
  E/AndroidRuntime(  335):    at java.lang.reflect.Method.invokeNative(Native Method)
  E/AndroidRuntime(  335):    at java.lang.reflect.Method.invoke(Method.java:507)
  E/AndroidRuntime(  335):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
  E/AndroidRuntime(  335):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
  E/AndroidRuntime(  335):    at dalvik.system.NativeStart.main(Native Method)
  E/AndroidRuntime(  335): Caused by: java.lang.NullPointerException
  E/AndroidRuntime(  335):    at com.rubiconproject.testing.TestingActivity.onCreate(TestingActivity.java:26)
  E/AndroidRuntime(  335):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
  E/AndroidRuntime(  335):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1586)
  E/AndroidRuntime(  335):    ... 11 more
  </code></pre>
  
  <p>where line 26 corresponds to:</p>
  
  <pre><code>    tt.setText(pInfo.versionCode);
  </code></pre>
  
  <p>Does anyone know why this is happening?</p>