我是Android应用程序的新手。我的应用程序只使用片段,但当应用程序运行时,我按下主页按钮,应用程序被NullPointerException崩溃。我不明白为什么。请帮我。 (由于私人原因我需要使用API 19,android:sharedUserId =“android.uid.system”和android:process =“system”)
我创建的应用程序被烧录为具有以下权限的系统
$ adb shell dumpsys package jp.co.doexample.test.doexample
Activity Resolver Table:
Non-Data Actions:
android.intent.action.MAIN:
a526b630 jp.co.doexample.test.doexample/.MainActivity filter a52973c0
Action: "android.intent.action.MAIN"
Category: "android.intent.category.LAUNCHER"
Key Set Manager:
[jp.co.doexample.test.doexample]
Signing KeySets: 1
Packages:
Package [jp.co.doexample.test.doexample] (a50c27f8):
userId=1000 gids=[]
sharedUser=SharedUserSetting{a508f4d8 android.uid.system/1000}
pkg=Package{a52af5a0 jp.co.doexample.test.doexample}
codePath=/data/app/jp.co.doexample.test.doexample-2.apk
resourcePath=/data/app/jp.co.doexample.test.doexample-2.apk
nativeLibraryPath=/data/app-lib/jp.co.doexample.test.doexample-2
versionCode=1 targetSdk=19
versionName=1.0
applicationInfo=ApplicationInfo{a52e5500 jp.co.doexample.test.doexample}
flags=[ DEBUGGABLE HAS_CODE ALLOW_CLEAR_USER_DATA TEST_ONLY ALLOW_BACKUP ]
dataDir=/data/data/jp.co.doexample.test.doexample
supportsScreens=[small, medium, large, xlarge, resizeable, anyDensity]
timeStamp=2018-02-19 04:05:27
firstInstallTime=2018-02-19 00:50:12
lastUpdateTime=2018-02-19 04:05:27
signatures=PackageSignatures{a50544a0 [a50550b8]}
permissionsFixed=true haveGids=true installStatus=1
pkgFlags=[ DEBUGGABLE HAS_CODE ALLOW_CLEAR_USER_DATA TEST_ONLY ALLOW_BACKUP ]
User 0: installed=true blocked=false stopped=true notLaunched=false enabled=0
Shared users:
SharedUser [android.uid.system] (a508f4d8):
userId=1000 gids=[3003, 1028, 1015, 3002, 3001]
grantedPermissions:
android.permission.ACCESS_NOTIFICATIONS
android.permission.LOCATION_HARDWARE
android.permission.MASTER_CLEAR
android.permission.CLEAR_APP_USER_DATA
android.permission.READ_USER_DICTIONARY
android.permission.READ_CONTACTS
android.permission.CALL_PHONE
android.permission.WRITE_CONTACTS
android.permission.BACKUP
android.permission.READ_PHONE_STATE
android.permission.ACCESS_WIMAX_STATE
android.permission.MANAGE_USERS
android.permission.SET_TIME
android.permission.ACCESS_FINE_LOCATION
android.permission.MANAGE_DEVICE_ADMINS
android.permission.ACCESS_NETWORK_STATE
android.permission.USE_CREDENTIALS
android.permission.SET_POINTER_SPEED
android.permission.INTERACT_ACROSS_USERS_FULL
android.permission.CONFIGURE_WIFI_DISPLAY
android.permission.MOVE_PACKAGE
android.permission.HARDWARE_TEST
android.permission.WRITE_SECURE_SETTINGS
android.permission.ACCESS_CHECKIN_PROPERTIES
android.permission.FORCE_STOP_PACKAGES
android.permission.MODIFY_AUDIO_SETTINGS
android.permission.READ_SYNC_STATS
android.permission.INSTALL_LOCATION_PROVIDER
android.permission.WRITE_SYNC_SETTINGS
android.permission.MODIFY_PHONE_STATE
android.permission.INTERNET
android.permission.BLUETOOTH
android.permission.WRITE_SETTINGS
android.permission.CONFIRM_FULL_BACKUP
com.android.launcher.permission.READ_SETTINGS
android.permission.PACKAGE_USAGE_STATS
android.permission.BLUETOOTH_ADMIN
android.permission.DEVICE_POWER
com.android.launcher.permission.WRITE_SETTINGS
android.permission.CHANGE_CONFIGURATION
android.permission.READ_EXTERNAL_STORAGE
android.permission.WRITE_EXTERNAL_STORAGE
android.permission.REBOOT
android.intent.category.MASTER_CLEAR.permission.C2D_MESSAGE
android.permission.ACCESS_WIFI_STATE
android.permission.STATUS_BAR
android.permission.ACCESS_COARSE_LOCATION
com.google.android.googleapps.permission.GOOGLE_AUTH
android.permission.MOUNT_UNMOUNT_FILESYSTEMS
android.permission.BLUETOOTH_PRIVILEGED
android.permission.WRITE_USER_DICTIONARY
android.permission.ACCESS_DOWNLOAD_MANAGER
android.permission.SET_KEYBOARD_LAYOUT
android.permission.MANAGE_USB
android.permission.CHANGE_WIMAX_STATE
android.permission.NFC
android.permission.WRITE_APN_SETTINGS
android.permission.BATTERY_STATS
com.android.certinstaller.INSTALL_AS_USER
android.permission.READ_PROFILE
android.permission.CHANGE_WIFI_STATE
android.permission.INTERACT_ACROSS_USERS
android.permission.READ_SYNC_SETTINGS
android.permission.VIBRATE
android.permission.COPY_PROTECTED_DATA
在gradle(app)中构建信息
....
defaultConfig {
applicationId "jp.co.doexample.test.doexample"
minSdkVersion 19
targetSdkVersion 19
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
...
的AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:sharedUserId="android.uid.system"
package="jp.co.doexample.test.doexample">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:process="system"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
MainActivity.java
package jp.co.doexample.test.doexample;
import android.net.Uri;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.os.Bundle;
public class MainActivity extends FragmentActivity implements TopFragment.OnFragmentInteractionListener, MainFragment.OnFragmentInteractionListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
TopFragment fragmentTop = TopFragment.newInstance("PARAM1", "PARAM2");
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.add(R.id.top_bar_container, fragmentTop, "TopBarFragment");
MainFragment mainFragment = MainFragment.newInstance("PARAM1", "PARAM2");
fragmentTransaction.add(R.id.main_container, mainFragment, "MainFragment");
fragmentTransaction.commit();
}
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
}
@Override
public void onFragmentInteraction(Uri uri) {
}
@Override
public void onPointerCaptureChanged(boolean hasCapture) {
}
}
activity_main.xml中
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="jp.co.doexample.test.doexample.MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:id="@+id/top_bar_container"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="100" />
<FrameLayout
android:id="@+id/main_container"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="900" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>
我保持TopFragment.java和MainFragment.java与AndroidStuio中片段(空白)生成的相同。
当按下主页时应用程序崩溃。系统进程中的致命异常:抛出了主java.lang.NullPointerException,如下所示:
02-19 04:05:29.681 1960-2541/com.google.android.gms I/Icing: Indexing 491ABC3DAB0EED407E71F3C01527BAA56EADC801 from com.google.android.gms
02-19 04:05:29.681 1960-2541/com.google.android.gms I/Icing: Indexing done 491ABC3DAB0EED407E71F3C01527BAA56EADC801
02-19 04:05:37.511 1618-1757/system_process I/ActivityManager: Killing 2343:com.android.exchange/u0a27 (adj 15): empty #17
02-19 04:05:37.761 1618-1683/system_process I/ActivityManager: START u0 {act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10200000 cmp=com.android.launcher/com.android.launcher2.Launcher} from pid 1618
02-19 04:05:37.771 1960-1960/com.google.android.gms I/CastMirroringProvider: onDiscoveryModeChanged, mode=0
02-19 04:05:37.771 1960-2541/com.google.android.gms I/CastMirroringProvider: onDiscoveryModeChanged removing all remote displays
02-19 04:05:37.771 1168-1220/? D/gralloc_ranchu: gralloc_alloc: Creating ashmem region of size 565248
[ 02-19 04:05:37.771 1618: 1683 D/ ]
HostConnection::get() New Host Connection established 0xb8f1a7f0, tid 1683
02-19 04:05:37.811 1618-1683/system_process D/dalvikvm: GC_FOR_ALLOC freed 536K, 18% free 8380K/10176K, paused 8ms, total 8ms
02-19 04:05:37.811 1618-1683/system_process I/dalvikvm-heap: Grow heap (frag case) to 8.767MB for 496812-byte allocation
02-19 04:05:37.821 1618-1683/system_process D/dalvikvm: GC_FOR_ALLOC freed <1K, 17% free 8865K/10664K, paused 8ms, total 8ms
02-19 04:05:37.831 1618-1683/system_process D/dalvikvm: GC_FOR_ALLOC freed 16K, 18% free 8849K/10664K, paused 13ms, total 13ms
02-19 04:05:37.831 1618-1683/system_process I/dalvikvm-heap: Grow heap (frag case) to 9.225MB for 496812-byte allocation
02-19 04:05:37.851 1618-1683/system_process D/dalvikvm: GC_FOR_ALLOC freed <1K, 17% free 9334K/11152K, paused 10ms, total 10ms
02-19 04:05:37.851 1960-2541/com.google.android.gms I/DiscoveryManager: Filter criteria(null) scannerFlags(0)
02-19 04:05:37.851 1618-1695/system_process E/WifiStateMachine: Error! unhandled message{ when=-1ms what=131156 target=com.android.internal.util.StateMachine$SmHandler }
02-19 04:05:37.861 1831-1831/com.android.launcher D/EGL_emulation: eglMakeCurrent: 0xb8e455b0: ver 2 0
02-19 04:05:37.911 1831-1831/com.android.launcher D/EGL_emulation: eglMakeCurrent: 0xb8e455b0: ver 2 0
02-19 04:05:37.911 1831-1831/com.android.launcher E/EGL_emulation: tid 1831: eglSurfaceAttrib(1199): error 0x3009 (EGL_BAD_MATCH)
02-19 04:05:37.911 1831-1831/com.android.launcher W/HardwareRenderer: Backbuffer cannot be preserved
02-19 04:05:38.461 1618-1618/? D/AndroidRuntime: Shutting down VM
02-19 04:05:38.461 1618-1618/? W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0xa4ccdb20)
02-19 04:05:38.461 1618-1618/? I/Process: Sending signal. PID: 1618 SIG: 9
02-19 04:05:38.461 1618-1618/? E/AndroidRuntime: *** FATAL EXCEPTION IN SYSTEM PROCESS: main
java.lang.NullPointerException
at android.os.Bundle.hasFileDescriptors(Bundle.java:383)
at android.os.Bundle.describeContents(Bundle.java:1658)
at android.os.Bundle.hasFileDescriptors(Bundle.java:365)
at com.android.server.am.ActivityManagerService.activityStopped(ActivityManagerService.java:5247)
at android.app.ActivityThread$StopInfo.run(ActivityThread.java:3098)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at com.android.server.ServerThread.initAndLoop(SystemServer.java:1093)
at com.android.server.SystemServer.main(SystemServer.java:1179)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
02-19 04:05:38.471 1171-1171/? W/AudioFlinger: power manager service died !!!
02-19 04:05:38.471 1162-1162/? I/ServiceManager: service 'user' died
02-19 04:05:38.471 1162-1162/? I/ServiceManager: service 'sensorservice' died
02-19 04:05:38.471 1162-1162/? I/ServiceManager: service 'power' died
02-19 04:05:38.471 1162-1162/? I/ServiceManager: service 'gfxinfo' died
02-19 04:05:38.471 1162-1162/? I/ServiceManager: service 'vibrator' died
02-19 04:05:38.471 1162-1162/? I/ServiceManager: service 'hardware' died
02-19 04:05:38.471 1162-1162/? I/ServiceManager: service 'consumer_ir' died
02-19 04:05:38.471 1162-1162/? I/ServiceManager: service 'cpuinfo' died
02-19 04:05:38.471 1162-1162/? I/ServiceManager: service 'permission' died
02-19 04:05:38.471 1162-1162/? I/ServiceManager: service 'batterystats' died
02-19 04:05:38.471 1162-1162/? I/ServiceManager: service 'usagestats' died
02-19 04:05:38.471 1162-1162/? I/ServiceManager: service 'appops' died
02-19 04:05:38.471 1162-1162/? I/ServiceManager: service 'display' died
02-19 04:05:38.471 1162-1162/? I/ServiceManager: service 'telephony.registry' died
02-19 04:05:38.471 1162-1162/? I/ServiceManager: service 'scheduling_policy' died
02-19 04:05:38.471 1162-1162/? I/ServiceManager: service 'account' died
02-19 04:05:38.471 1162-1162/? I/ServiceManager: service 'dbinfo' died
02-19 04:05:38.471 1162-1162/? I/ServiceManager: service 'activity' died
02-19 04:05:38.471 1162-1162/? I/ServiceManager: service 'procstats' died
02-19 04:05:38.471 1162-1162/? I/ServiceManager: service 'meminfo' died
02-19 04:05:38.471 1162-1162/? I/ServiceManager: service 'entropy' died
02-19 04:05:38.471 1162-1162/? I/ServiceManager: service 'content' died
02-19 04:05:38.471 1162-1162/? I/ServiceManager: service 'battery' died
02-19 04:05:38.471 1162-1162/? I/ServiceManager: service 'package' died
02-19 04:05:38.471 1162-1162/? I/ServiceManager: service 'alarm' died
02-19 04:05:38.471 1162-1162/? I/ServiceManager: service 'window' died
02-19 04:05:38.471 1162-1162/? I/ServiceManager: service 'input' died
02-19 04:05:38.471 1162-1162/? I/ServiceManager: service 'audio' died
02-19 04:05:38.471 1162-1162/? I/ServiceManager: service 'netpolicy' died
02-19 04:05:38.471 1162-1162/? I/ServiceManager: service 'lock_settings' died
02-19 04:05:38.471 1162-1162/? I/ServiceManager: service 'device_policy' died
02-19 04:05:38.471 1162-1162/? I/ServiceManager: service 'wifip2p' died
02-19 04:05:38.471 1162-1162/? I/ServiceManager: service 'statusbar' died
02-19 04:05:38.471 1162-1162/? I/ServiceManager: service 'clipboard' died
02-19 04:05:38.471 1162-1162/? I/ServiceManager: service 'network_management' died
02-19 04:05:38.471 1162-1162/? I/ServiceManager: service 'textservices' died
02-19 04:05:38.471 1162-1162/? I/ServiceManager: service 'netstats' died
02-19 04:05:38.471 1162-1162/? I/ServiceManager: service 'input_method' died
02-19 04:05:38.471 1162-1162/? I/ServiceManager: service 'mount' died
02-19 04:05:38.471 1162-1162/? I/ServiceManager: service 'accessibility' died
02-19 04:05:38.471 1162-1162/? I/ServiceManager: service 'location' died
02-19 04:05:38.471 1162-1162/? I/ServiceManager: service 'connectivity' died
02-19 04:05:38.471 1162-1162/? I/ServiceManager: service 'devicestoragemonitor' died
02-19 04:05:38.471 1162-1162/? I/ServiceManager: service 'country_detector' died
02-19 04:05:38.471 1162-1162/? I/ServiceManager: service 'updatelock' died
02-19 04:05:38.471 1162-1162/? I/ServiceManager: service 'servicediscovery' died
02-19 04:05:38.471 1162-1162/? I/ServiceManager: service 'dropbox' died
02-19 04:05:38.471 1162-1162/? I/ServiceManager: service 'search' died
02-19 04:05:38.471 1162-1162/? I/ServiceManager: service 'wallpaper' died
02-19 04:05:38.471 1162-1162/? I/ServiceManager: service 'notification' died
02-19 04:05:38.471 1162-1162/? I/ServiceManager: service 'wifi' died
02-19 04:05:38.471 1162-1162/? I/ServiceManager: service 'usb' died
02-19 04:05:38.471 1162-1162/? I/ServiceManager: service 'serial' died
02-19 04:05:38.471 1162-1162/? I/ServiceManager: service 'uimode' died
02-19 04:05:38.471 1162-1162/? I/ServiceManager: service 'backup' died
02-19 04:05:38.471 1162-1162/? I/ServiceManager: service 'appwidget' died
02-19 04:05:38.471 1813-1948/com.android.phone E/WifiManager: Channel connection lost
02-19 04:05:38.471 1162-1162/? I/ServiceManager: service 'diskstats' died
02-19 04:05:38.471 1162-1162/? I/ServiceManager: service 'samplingprofiler' died
02-19 04:05:38.471 1162-1162/? I/ServiceManager: service 'commontime_management' died
02-19 04:05:38.471 1162-1162/? I/ServiceManager: service 'dreams' died
02-19 04:05:38.471 1162-1162/? I/ServiceManager: service 'assetatlas' died
02-19 04:05:38.471 1162-1162/? I/ServiceManager: service 'print' died
02-19 04:05:38.471 1162-1162/? I/ServiceManager: service 'media_router' died
02-19 04:05:38.471 1777-1788/com.google.android.gms.persistent W/Sensors: sensorservice died [0xb8e88d70]
如果我删除super.onSaveInstanceState(outState);来自AndroidManifest.xml的主要活动或android:process =“system”,它将正常运行。 我不知道为什么请帮助我。
Edit2:我的示例来源 https://github.com/hanglt6174/DoExample