Search Unity

Unable to start activity: NullPointerException

Discussion in 'Android' started by McKrackeN, Jun 4, 2013.

  1. McKrackeN

    McKrackeN

    Joined:
    Oct 28, 2009
    Posts:
    51
    Hey guys,

    I'm having some trouble trying to run a custom Android plugin. When I call the Login method (java) from C# and start the activity, it throws an "Unable to start activity: NullPointerException" exception when calling super.onCreate(savedInstanceState).

    Here's the Java code:

    Code (csharp):
    1.  
    2. public class GPlusActivity extends UnityPlayerActivity
    3. {
    4.     private static final String TAG = "GooglePlusActivity";
    5.  
    6.     static Intent intent = null;
    7.      
    8.     @Override
    9.     protected void onCreate(Bundle savedInstanceState)
    10.     {
    11.         super.onCreate(savedInstanceState);
    12.  
    13.         Log.d(TAG, "OnCreate Activity");
    14.     }
    15.    
    16.     public static void Login()
    17.     {
    18.         Log.d(TAG, "Login");
    19.  
    20.         if (intent == null)
    21.         {
    22.             Log.d(TAG, "Creating intent...");
    23.            
    24.             intent = new Intent().setClass(
    25.                     UnityPlayer.currentActivity.getApplicationContext(),
    26.                     GPlusActivity.class);
    27.         }
    28.        
    29.         if (intent != null)
    30.         {
    31.             Log.d(TAG, "Starting intent... " + UnityPlayer.currentActivity);
    32.             UnityPlayer.currentActivity.startActivity(intent);
    33.         }
    34.         else
    35.             Log.d(TAG, "Intent is null!");
    36.     }
    37. }
    38.  
    And this is the AndroidManifest.xml:
    Code (csharp):
    1.  
    2. <?xml version="1.0" encoding="utf-8"?>
    3. <manifest
    4.     xmlns:android="http://schemas.android.com/apk/res/android"
    5.     android:installLocation="preferExternal"
    6.     android:theme="@android:style/Theme.NoTitleBar"
    7.     package="com.dedalordnorth.skiingfred"
    8.     android:versionName="1.0.0"
    9.     android:versionCode="1">
    10.    
    11.     <supports-screens
    12.         android:smallScreens="true"
    13.         android:normalScreens="true"
    14.         android:largeScreens="true"
    15.         android:xlargeScreens="true"
    16.         android:anyDensity="true"/>
    17.  
    18.     <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="14"/>
    19.  
    20.     <application
    21.         android:icon="@drawable/app_icon"
    22.         android:label="@string/app_name"
    23.         android:debuggable="true">
    24.         <activity android:name="com.unity3d.player.UnityPlayerProxyActivity"
    25.                   android:launchMode="singleTask"
    26.                   android:label="@string/app_name"
    27.                   android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
    28.             <intent-filter>
    29.                 <action android:name="android.intent.action.MAIN" />
    30.                 <category android:name="android.intent.category.LAUNCHER" />
    31.             </intent-filter>
    32.         </activity>
    33.         <activity android:name="com.unity3d.player.UnityPlayerActivity"
    34.                   android:launchMode="singleTask"
    35.                   android:label="@string/app_name"
    36.                   android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
    37.         </activity>
    38.         <activity android:name="com.unity3d.player.UnityPlayerNativeActivity"
    39.                   android:launchMode="singleTask"
    40.                   android:label="@string/app_name"
    41.                   android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
    42.             <meta-data android:name="android.app.lib_name" android:value="unity" />
    43.             <meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="true" />
    44.         </activity>
    45.        
    46.         <activity android:name="com.dedalord.social.googleplusplugin.GPlusActivity"
    47.                   android:label="@string/app_name"
    48.                   android:configChanges="keyboard|keyboardHidden|orientation"/>
    49.     </application>
    50.  
    51.     <uses-permission android:name="android.permission.INTERNET"/>
    52.     <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
    53.     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    54.     <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    55.     <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    56.  
    57.     <uses-permission android:name="android.permission.INTERNET"/>
    58.     <uses-permission android:name="com.android.vending.BILLING"/>
    59.  
    60. </manifest>
    61.  
    What am I doing wrong?

    Thanks in advance!
     
  2. bitter

    bitter

    Unity Technologies

    Joined:
    Jan 11, 2012
    Posts:
    530
    The NPE seems weird, however, you will _not_ be able to run multiple unity activities within the same process. Starting the GPlusActivity from within unity will most likely yield an exception or worst case a crash.
     
  3. Oak99

    Oak99

    Joined:
    May 30, 2013
    Posts:
    1
    I am facing the same problem, did you solve this? I call a java method from Unity, the method start a new Android activity but it crashes in super.onCreate(savedInstanceState).

    Thank you
     
  4. AshishAxiom

    AshishAxiom

    Joined:
    May 21, 2013
    Posts:
    1
    I am also having the same problem like Oak99.Please help me out.