Unable to create service com parse. PushService:java. lang.NullPointerException
•
Java
I'm using the service https://www.parse.com Push notification
My code:
ParseCrashReporting.enable(this); // Enable Local Datastore. Parse.enableLocalDatastore(this); Parse.initialize(this,"cMQIGJhjD58Dn3uQ27nx5NsO***","f0VtuHy2G1NsWUPrfzkzJjh7523UDnqX7cQav****"); ParseInstallation.getCurrentInstallation().saveInBackground(); ParseUser.enableAutomaticUser(); ParseACL defaultACL = new ParseACL(); // Optionally enable public read access. // defaultACL.setPublicReadAccess(true); ParseACL.setDefaultACL(defaultACL,true);
AndroidManifest
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.home.smart.home" > <permission android:name="com.home.smart.home.permission.MAPS_RECEIVE" android:protectionLevel="signature" /> <uses-permission android:name="com.home.smart.home.permission.MAPS_RECEIVE" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <!-- Push --> <uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="android.permission.VIBRATE" /> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> <uses-permission android:name="android.permission.GET_ACCOUNTS" /> <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> <!-- end Push --> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" /> <uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission> <uses-permission android:name="android.permission.BLUETOOTH"/> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.CALL_PHONE" /> <uses-permission android:name="android.permission.CAMERA"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <!-- end Push --> <permission android:protectionLevel="signature" android:name="com.home.smart.home.permission.C2D_MESSAGE" /> <uses-permission android:name="com.home.smart.home.permission.C2D_MESSAGE" /> <!-- Push --> <!-- required OpenGL ES 2.0. for Maps V2 --> <uses-feature android:glEsVersion="0x00020000" android:required="true" /> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <!-- Goolge API Key --> <Meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="AIzaSyB0gzAqr_M4y_Iy3_xq6yvu17zpkG7V_IU" /> <activity android:name=".MainActivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <!-- Push --> <service android:name="com.parse.PushService" /> <receiver android:name="com.parse.ParseBroadcastReceiver"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> <action android:name="android.intent.action.USER_PRESENT" /> </intent-filter> </receiver> <receiver android:name="com.parse.ParsePushBroadcastReceiver" android:exported="false"> <intent-filter> <action android:name="com.parse.push.intent.RECEIVE" /> <action android:name="com.parse.push.intent.DELETE" /> <action android:name="com.parse.push.intent.OPEN" /> </intent-filter> </receiver> <receiver android:name="com.parse.GcmBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND"> <intent-filter> <action android:name="com.google.android.c2dm.intent.RECEIVE" /> <action android:name="com.google.android.c2dm.intent.REGISTRATION" /> <!-- IMPORTANT: Change "com.parse.starter" to match your app's package name. --> <category android:name="com.home.smart.home" /> </intent-filter> </receiver> <Meta-data android:name="com.parse.push.notification_icon" android:resource="@drawable/abc_btn_rating_star_on_mtrl_alpha"/> <!-- end Push --> </application> </manifest>
The error message of logcat is:
Unable to create service com.parse.PushService: java.lang.NullPointerException
Solution
This is:
Parse.initialize(this,"cMQIGJhjD58Dn3uQ27nx5NsOtawsbWy1oxHtYnBn","f0VtuHy2G1NsWUPrfzkzJjh7523UDnqX7cQavRDw"); ParseInstallation.getCurrentInstallation().saveInBackground();
In different activities (for example: "service. Java") or one of your main activities? If it is in one of your main activities, create a new class called service, add the above code to it, and then add it to the < Application > tab of the listing:
<application android: name="com.packagename.app.Service" ... > ... </application>
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码