Android仿真器问题
我需要在Android Emulator中使用Eclipse启动Android应用程序。应用程序已安装但未打开。我在打开应用程序时遇到一个意外错误,即。,很遗憾,“应用程序名称”已停止。因此,我不知道如何解决此错误。我在调试模式下发现以下错误,因此如何解决此错误,请帮助我 LogCat错误:Android仿真器问题,android,eclipse,debugging,android-emulator,unity3d,Android,Eclipse,Debugging,Android Emulator,Unity3d,我需要在Android Emulator中使用Eclipse启动Android应用程序。应用程序已安装但未打开。我在打开应用程序时遇到一个意外错误,即。,很遗憾,“应用程序名称”已停止。因此,我不知道如何解决此错误。我在调试模式下发现以下错误,因此如何解决此错误,请帮助我 LogCat错误: 12-16 01:44:38.673: E/AndroidRuntime(1094): FATAL EXCEPTION: main 12-16 01:44:38.673: E/AndroidRuntime(
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>
UnityPlayerActiveActivity.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);
}
}
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);
}
}
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();
}
}
}
UnityPlayerProxyActivity.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);
}
}
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);
}
}
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();
}
}
}
requestWindof自然行应位于UnitPayerActivity类中super.onCreateSavedInstanceState之后,一般来说
我们使用adb安装位置将apk安装到仿真器 发布您的代码pleaseur代码包含OnCreate本身的错误。我发布了整个代码。因此,请帮助我如何解决此问题以及如何解决OnCreate自身的错误@MonicaI已更改为“如您所述”,但我收到的错误与我发布的上述错误相同。@Vaibhav Agarwal。请清理代码并重新构建它,删除对libs的依赖关系,然后再次添加它并重新启动系统和仿真器。运行项目并查看错误日志。右键单击pro转到属性->java构建路径->库删除除主android4.2或任何android库之外的所有内容。全部删除。再次清理项目构建。重新启动所有程序并运行,即使相同的问题没有改变。@Vaibhav Agarwal。我收到两个错误,一个是错误日志错误,另一个是在Eclipse中查找调试模式时的LogCat错误。@Vaibhav Agarwal。好的,根据我的说法,错误日志错误与您的代码无关。您应该重新启动系统并清理项目,以防出现此错误。对于logcat错误,请检查本机活动的第177行或将其粘贴到此处。我也尝试过这种方法,但问题相同。很遗憾,“应用程序名称”已停止。@MengMeng