我的应用经常因信息
而崩溃your app unfortunately stopped working
我查看了崩溃日志,并在日志中发现以下错误
E/AndroidRuntime( 9780): java.lang.RuntimeException: Unable to start receiver com.parse.ParseBroadcastReceiver: java.lang.RuntimeException: applicationContext is null. You must call Parse.initialize(Context) before using the Parse library.
E/AndroidRuntime( 9780): Caused by: java.lang.RuntimeException: applicationContext is null. You must call Parse.initialize(Context) before using the Parse library.
D/Process ( 9780): com.android.internal.os.RuntimeInit$UncaughtHandler.uncaughtException:138 java.lang.ThreadGroup.uncaughtException:693 java.lang.ThreadGroup.uncaughtException:69012:26 PM
我正在离子框架中构建我的应用程序,并遵循https://github.com/aaronksaunders/dcww/tree/master/www/js中的模式。我正在使用https://github.com/grrrian/phonegap-parse-plugin which说我需要初始化onCreate。我该怎么做,我假设我的应用程序崩溃是由于那个。
我的app.js是
angular.module('intuch', ['ionic', 'intuch.controllers'])
.run(function ($ionicPlatform, ParseService) {
$ionicPlatform.ready(function () {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if (window.StatusBar) {
// org.apache.cordova.statusbar required
StatusBar.styleDefault();
}
ParseService.initialize().then(function () {
return ParseService.getInstallationId();
}).then(function (_response) {
console.log("Parse Initialized " + _response);
return ParseService.subscribe("broadcast_registered3");
}).then(function (_response) {
return ParseService.registerCallback(function (pnObj) {
alert("in assigned callback " + JSON.stringify(pnObj));
$state.go('app.dashboard');
});
}).then(function (success) {
console.log("Parse callback registered " + success);
}, function error(_error) {
alert(_error);
});
});
})
而Parse服务是
.factory('ParseService', function ($q, $window) {
var ParseConfiguration = {
applicationId: "waDzmmDVt7hNmRCoY50wOFN3lsRoW2xu42WrPYLs",
javascriptKey: "nUROouGGqI4WnbHDlNg5AweSQhmmXD84382xJmuU",
clientKey: "IF2RHNA0slYDq8feUhweewmcK2uEnOqDnK8J7jUf",
USING_PARSE: true,
initialized: false
};
return {
initialize: function () {
console.log("Missing Parse Plugin " + JSON.stringify($window.parsePlugin));
var deferred = $q.defer();
$window.parsePlugin.initialize(ParseConfiguration.applicationId, ParseConfiguration.clientKey, function () {
console.log("Initialized Parse Plugin");
deferred.resolve('success');
}, function (e) {
deferred.reject(e);
});
return deferred.promise;
},
getInstallationId: function () {
var deferred = $q.defer();
$window.parsePlugin.getInstallationId(function (id) {
deferred.resolve(id);
}, function (e) {
deferred.reject(e);
});
return deferred.promise;
},
subscribe: function (_channel) {
var deferred = $q.defer();
$window.parsePlugin.subscribe(_channel, function () {
deferred.resolve(true);
}, function (e) {
deferred.reject(false);
});
return deferred.promise;
},
unsubscribe: function (_channel) {
var deferred = $q.defer();
$window.parsePlugin.unsubscribe(_channel, function () {
deferred.resolve(true);
}, function (e) {
deferred.reject(false);
});
return deferred.promise;
},
getSubscriptions: function () {
var deferred = $q.defer();
$window.parsePlugin.getSubscriptions(function (_channelsArray) {
deferred.resolve(_channelsArray);
}, function (e) {
deferred.reject(false);
});
return deferred.promise;
},
registerCallback: function (_pushCallback) {
var deferred = $q.defer();
$window.parsePlugin.registerCallback('onNotification', function () {
$window.onNotification = function (pnObj) {
_pushCallback && _pushCallback(pnObj);
alert('We received this push notification: ' + JSON.stringify(pnObj));
if (pnObj.receivedInForeground === false) {
// TODO: route the user to the uri in pnObj
}
};
deferred.resolve(true);
}, function (error) {
deferred.reject(error);
});
return deferred.promise;
}
};
})
答案 0 :(得分:0)
我不确定,但我认为你错过了以下内容:
public class YourApplication extends Application{
/* (non-Javadoc)
* @see android.app.Application#onCreate()
*/
@Override
public void onCreate()
{
super.onCreate();
Parse.initialize(this, "YOUR_KEY",
"YOUR_KEY");
}
}
并将其添加到Manifest.xml
<application
android:name=".YourApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >