我需要在Android模拟器中启动Android应用程序使用Eclipse.App安装但未打开。我得到一个惊讶的错误当时打开应用程序,即“不幸'应用程序名称已停止”。所以我对如何解决这个错误一无所知。我在调试模式下找到了以下错误,所以如何解决这个错误请帮帮我。
LogCat错误:
12-16 01:44:38.673: E/AndroidRuntime(1094): FATAL EXCEPTION: main
12-16 01:44:38.673: E/AndroidRuntime(1094): Process: com.***.****, PID: 1094
12-16 01:44:38.673: E/AndroidRuntime(1094): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.***.****/com.***.****.UnityPlayerNativeActivity}: java.lang.NullPointerException
12-16 01:44:38.673: E/AndroidRuntime(1094): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2176)
12-16 01:44:38.673: E/AndroidRuntime(1094): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2226)
12-16 01:44:38.673: E/AndroidRuntime(1094): at android.app.ActivityThread.access$700(ActivityThread.java:135)
12-16 01:44:38.673: E/AndroidRuntime(1094): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1397)
12-16 01:44:38.673: E/AndroidRuntime(1094): at android.os.Handler.dispatchMessage(Handler.java:102)
12-16 01:44:38.673: E/AndroidRuntime(1094): at android.os.Looper.loop(Looper.java:137)
12-16 01:44:38.673: E/AndroidRuntime(1094): at android.app.ActivityThread.main(ActivityThread.java:4998)
12-16 01:44:38.673: E/AndroidRuntime(1094): at java.lang.reflect.Method.invokeNative(Native Method)
12-16 01:44:38.673: E/AndroidRuntime(1094): at java.lang.reflect.Method.invoke(Method.java:515)
12-16 01:44:38.673: E/AndroidRuntime(1094): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
12-16 01:44:38.673: E/AndroidRuntime(1094): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593)
12-16 01:44:38.673: E/AndroidRuntime(1094): at dalvik.system.NativeStart.main(Native Method)
12-16 01:44:38.673: E/AndroidRuntime(1094): Caused by: java.lang.NullPointerException
12-16 01:44:38.673: E/AndroidRuntime(1094): at android.os.Parcel.readException(Parcel.java:1467)
12-16 01:44:38.673: E/AndroidRuntime(1094): at android.os.Parcel.readException(Parcel.java:1415)
12-16 01:44:38.673: E/AndroidRuntime(1094): at android.os.storage.IMountService$Stub$Proxy.mkdirs(IMountService.java:750)
12-16 01:44:38.673: E/AndroidRuntime(1094): at android.app.ContextImpl.ensureDirsExistOrFilter(ContextImpl.java:2160)
12-16 01:44:38.673: E/AndroidRuntime(1094): at android.app.ContextImpl.getObbDirs(ContextImpl.java:874)
12-16 01:44:38.673: E/AndroidRuntime(1094): at android.app.ContextImpl.getObbDir(ContextImpl.java:863)
12-16 01:44:38.673: E/AndroidRuntime(1094): at android.content.ContextWrapper.getObbDir(ContextWrapper.java:220)
12-16 01:44:38.673: E/AndroidRuntime(1094): at android.app.NativeActivity.onCreate(NativeActivity.java:177)
12-16 01:44:38.673: E/AndroidRuntime(1094): at com.***.****.UnityPlayerNativeActivity.onCreate(UnityPlayerNativeActivity.java:22)
12-16 01:44:38.673: E/AndroidRuntime(1094): at android.app.Activity.performCreate(Activity.java:5243)
12-16 01:44:38.673: E/AndroidRuntime(1094): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
12-16 01:44:38.673: E/AndroidRuntime(1094): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2140)
12-16 01:44:38.673: E/AndroidRuntime(1094): ... 11 more
Android清单文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.***.****" android:theme="@android:style/Theme.NoTitleBar" android:versionName="1.0" android:versionCode="1" android:installLocation="preferExternal">
<supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:xlargeScreens="true" android:anyDensity="true" />
<application android:icon="@drawable/app_icon" android:label="@string/app_name" android:debuggable="true">
<activity android:launchMode="singleTask" android:label="@string/app_name" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" android:screenOrientation="portrait" android:name="com.***.****.UnityPlayerProxyActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:launchMode="singleTask" android:label="@string/app_name" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" android:screenOrientation="portrait" android:name="com.***.****.UnityPlayerActivity">
</activity>
<activity android:launchMode="singleTask" android:label="@string/app_name" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" android:screenOrientation="portrait" android:name="com.***.****.UnityPlayerNativeActivity">
<meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="false" />
</activity>
</application>
<uses-sdk android:minSdkVersion="17" android:targetSdkVersion="19" />
<uses-feature android:glEsVersion="0x00020000" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-feature android:name="android.hardware.touchscreen" />
<uses-feature android:name="android.hardware.touchscreen.multitouch" android:required="false" />
<uses-feature android:name="android.hardware.touchscreen.multitouch.distinct" android:required="false" />
</manifest>
UnityPlayerActivity.java
package com.***.****;
import com.unity3d.player.*;
import android.app.Activity;
import android.content.res.Configuration;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
public class UnityPlayerActivity extends Activity
{
private UnityPlayer mUnityPlayer;
// UnityPlayer.init() should be called before attaching the view to a layout - it will load the native code.
// UnityPlayer.quit() should be the last thing called - it will unload the native code.
protected void onCreate (Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
mUnityPlayer = new UnityPlayer(this);
if (mUnityPlayer.getSettings ().getBoolean ("hide_status_bar", true))
getWindow ().setFlags (WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
int glesMode = mUnityPlayer.getSettings().getInt("gles_mode", 1);
boolean trueColor8888 = false;
mUnityPlayer.init(glesMode, trueColor8888);
View playerView = mUnityPlayer.getView();
setContentView(playerView);
playerView.requestFocus();
}
protected void onDestroy ()
{
mUnityPlayer.quit();
super.onDestroy();
}
// onPause()/onResume() must be sent to UnityPlayer to enable pause and resource recreation on resume.
protected void onPause()
{
super.onPause();
mUnityPlayer.pause();
}
protected void onResume()
{
super.onResume();
mUnityPlayer.resume();
}
public void onConfigurationChanged(Configuration newConfig)
{
super.onConfigurationChanged(newConfig);
mUnityPlayer.configurationChanged(newConfig);
}
public void onWindowFocusChanged(boolean hasFocus)
{
super.onWindowFocusChanged(hasFocus);
mUnityPlayer.windowFocusChanged(hasFocus);
}
// Pass any keys not handled by (unfocused) views straight to UnityPlayer
public boolean onKeyMultiple(int keyCode, int count, KeyEvent event)
{
return mUnityPlayer.onKeyMultiple(keyCode, count, event);
}
public boolean onKeyDown(int keyCode, KeyEvent event)
{
return mUnityPlayer.onKeyDown(keyCode, event);
}
public boolean onKeyUp(int keyCode, KeyEvent event)
{
return mUnityPlayer.onKeyUp(keyCode, event);
}
}
UnityPlayerNativeActivity.java
package com.***.****;
import com.unity3d.player.*;
import android.app.NativeActivity;
import android.content.res.Configuration;
import android.graphics.PixelFormat;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
public class UnityPlayerNativeActivity extends NativeActivity
{
protected UnityPlayer mUnityPlayer; // don't change the name of this variable; referenced from native code
// UnityPlayer.init() should be called before attaching the view to a layout - it will load the native code.
// UnityPlayer.quit() should be the last thing called - it will unload the native code.
protected void onCreate (Bundle savedInstanceState)
{
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
getWindow().takeSurface(null);
setTheme(android.R.style.Theme_NoTitleBar_Fullscreen);
getWindow().setFormat(PixelFormat.RGB_565);
mUnityPlayer = new UnityPlayer(this);
if (mUnityPlayer.getSettings ().getBoolean ("hide_status_bar", true))
getWindow ().setFlags (WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
int glesMode = mUnityPlayer.getSettings().getInt("gles_mode", 1);
boolean trueColor8888 = false;
mUnityPlayer.init(glesMode, trueColor8888);
View playerView = mUnityPlayer.getView();
setContentView(playerView);
playerView.requestFocus();
}
protected void onDestroy ()
{
mUnityPlayer.quit();
super.onDestroy();
}
// onPause()/onResume() must be sent to UnityPlayer to enable pause and resource recreation on resume.
protected void onPause()
{
super.onPause();
mUnityPlayer.pause();
}
protected void onResume()
{
super.onResume();
mUnityPlayer.resume();
}
public void onConfigurationChanged(Configuration newConfig)
{
super.onConfigurationChanged(newConfig);
mUnityPlayer.configurationChanged(newConfig);
}
public void onWindowFocusChanged(boolean hasFocus)
{
super.onWindowFocusChanged(hasFocus);
mUnityPlayer.windowFocusChanged(hasFocus);
}
public boolean dispatchKeyEvent(KeyEvent event)
{
if (event.getAction() == KeyEvent.ACTION_MULTIPLE)
return mUnityPlayer.onKeyMultiple(event.getKeyCode(), event.getRepeatCount(), event);
return super.dispatchKeyEvent(event);
}
}
UnityPlayerProxyActivity.java
package com.***.****;
import com.unity3d.player.*;
import java.util.Map;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
public class UnityPlayerProxyActivity extends Activity
{
protected void onCreate (Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// If the (Native)Activity is overridden these class names must match the new activities.
String classNames[] = { "com.***.****.UnityPlayerActivity", "com.***.****.UnityPlayerNativeActivity" };
// Convert old PlayerPrefs (pre Unity 3.4) to new PlayerPrefs
copyPlayerPrefs(this, classNames);
// Start the most 'advanced' Activity supported by the current Android OS.
// (Android OS 2.3 ('Gingerbread') and above supports NativeActivity)
try
{
boolean supportsNative = Build.VERSION.SDK_INT >= 9 /*Build.VERSION_CODES.GINGERBREAD*/;
Class<?> activity = Class.forName(classNames[supportsNative ? 1 : 0]);
Intent intent = new Intent(this, activity);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
Bundle extras = getIntent().getExtras();
if (extras != null)
intent.putExtras(extras);
startActivity(intent);
}
catch (ClassNotFoundException e)
{
e.printStackTrace();
}
finally
{
finish();
}
}
static protected void copyPlayerPrefs(Context context, String[] activityClassNames)
{
// UnityPlayer uses PackageName (bundle identifier) as PlayerPrefs identifier, starting from Unity 3.4.
SharedPreferences packagePrefs = context.getSharedPreferences(context.getPackageName(), Context.MODE_PRIVATE);
// If PlayerPrefs<package_name> already exists there is no need to
// copy the old values; they might in fact be stale data.
if (!packagePrefs.getAll().isEmpty())
return;
// Loop through the Activities and copy the contents (if any) of associated PlayerPrefs (Unity 3.3 and earlier).
SharedPreferences.Editor playerPrefs = packagePrefs.edit();
for (String name : activityClassNames)
{
SharedPreferences prefs = context.getSharedPreferences(name, Context.MODE_PRIVATE);
java.util.Map<String,?> keys = prefs.getAll();
if (keys.isEmpty())
continue;
for (Map.Entry<String, ?> entry : keys.entrySet())
{
Object value = entry.getValue();
if (value.getClass() == Integer.class)
playerPrefs.putInt(entry.getKey(), (Integer)value);
else if (value.getClass() == Float.class)
playerPrefs.putFloat(entry.getKey(), (Float)value);
else if (value.getClass() == String.class)
playerPrefs.putString(entry.getKey(), (String)value);
}
playerPrefs.commit();
}
}
}
答案 0 :(得分:0)
requestWindoFeature行应该在您的UnitPayerNativeActivity类中的super.onCreate(SavedInstanceState)之后
答案 1 :(得分:0)
一般来说 我们使用“adb install location”来安装apk到模拟器。