首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Ionic运行时错误无法读取null的属性"toLowerCase“

Ionic运行时错误无法读取null的属性"toLowerCase“
EN

Stack Overflow用户
提问于 2018-07-08 01:16:27
回答 2查看 1.2K关注 0票数 0

我试图通过“离子服务”查看一个应用程序,但我得到了这个错误。我看过其他主题,但从未见过运行时错误。我尝试了他们所有的解决方案,但我仍然会有相同的错误页面。这是我所看到的:

老实说,我不是这个应用程序的程序员,但我是从商店买的。但是,我知道一些在这里和那里。如果有一个简单的解决方案来解决这个问题,那就太棒了!

第一个错误链接指向此处:

代码语言:javascript
复制
_this.initialData();
var operating_system = '';
var admob = {};
if (_this.device.platform.toLowerCase() == 'android') {
     operating_system = 'android';
     admob = {
         banner: settings['admob_android_banner'],
         interstitial: settings['admob_android_interstitial']
     };
 }

第二个错误链接指向这里:

代码语言:javascript
复制
SafeSubscriber.prototype.__tryOrUnsub = function (fn, value) {
    try {
        fn.call(this._context, value);
    }
    catch (err) {
        this.unsubscribe();
        throw err;
    }
};

第三个错误指向这里:

代码语言:javascript
复制
SafeSubscriber.prototype.next = function (value) {
    if (!this.isStopped && this._next) {
        var _parentSubscriber = this._parentSubscriber;
        if (!_parentSubscriber.syncErrorThrowable) {
            this.__tryOrUnsub(this._next, value);
        }
        else if (this.__tryOrSetError(_parentSubscriber, this._next, value)) {
            this.unsubscribe();
        }
    }

第四个错误指向这里:

代码语言:javascript
复制
Subscriber.prototype._next = function (value) {
    this.destination.next(value);
};

第五个错误指向这里:

代码语言:javascript
复制
var /** @type {?} */ response = new Response(responseOptions);
    response.ok = isSuccess(status);
        if (response.ok) {
            responseObserver.next(response);
            // TODO(gdi2290): defer complete if array buffer until done
            responseObserver.complete();
            return;
        }

下面是我在cmd中得到的代码:

代码语言:javascript
复制
C:\Users\xx-nj\Desktop\DukhanApp\DukhanColor>ionic serve
Starting app-scripts server: --address 0.0.0.0 --port 8100 --livereload-port 35729 --dev-logger-port 53703 --nobrowser -
Ctrl+C to cancel
[20:02:52]  watch started ...
[20:02:52]  build dev started ...
[20:02:53]  clean started ...
[20:02:53]  clean finished in 3 ms
[20:02:53]  copy started ...
[20:02:53]  deeplinks started ...
[20:02:53]  deeplinks finished in 573 ms
[20:02:53]  transpile started ...
[20:03:01]  transpile finished in 7.70 s
[20:03:01]  preprocess started ...
[20:03:01]  preprocess finished in 1 ms
[20:03:01]  webpack started ...
[20:03:01]  copy finished in 8.80 s
[20:03:09]  webpack finished in 8.01 s
[20:03:09]  sass started ...
Without `from` option PostCSS could generate wrong source map and will not find Browserslist config. Set it to CSS file path or to `undefined` to prevent this warning.
[20:03:13]  sass finished in 3.39 s
[20:03:13]  postprocess started ...
[20:03:13]  postprocess finished in 14 ms
[20:03:13]  lint started ...
[20:03:13]  build dev finished in 20.14 s
[20:03:13]  watch ready in 20.44 s
[20:03:13]  dev server running: http://localhost:8100/

[OK] Development server running!
     Local: http://localhost:8100
     External: http://192.168.8.111:8100
     DevApp: celltore_ionic3@8100 on NajmLaptop

[20:03:23]  tslint: C:/Users/xx-nj/Desktop/DukhanApp/DukhanColor/src/pages/contactus/contactus.ts, line: 124
            'marker' is declared but never used.

     L123:  let map = new google.maps.Map(element, mapOptions);
     L124:  let marker = new google.maps.Marker({
     L125:    title: this.textStatic['cellstore_contact_us_title'],

[20:03:23]  tslint: ...s/xx-nj/Desktop/DukhanApp/DukhanColor/src/pages/detailcategory/detailcategory.ts, line: 138
            Duplicate variable: 'filter'

     L138:  for (var filter in this.filter['valueCustom']) {
     L139:      let attr = this.filter['value'][filter];

[20:03:23]  tslint: ...s/xx-nj/Desktop/DukhanApp/DukhanColor/src/pages/detailcategory/detailcategory.ts, line: 140
            Duplicate variable: 'option'

     L139:  let attr = this.filter['value'][filter];
     L140:  if (attr && Object.keys(attr).length > 0) for (var option in attr) {
     L141:                  if(option != 'select' && attr[option]) {

[20:03:23]  tslint: C:/Users/xx-nj/Desktop/DukhanApp/DukhanColor/src/pages/brand/brand.ts, line: 121
            Duplicate variable: 'filter'

     L121:  for (var filter in this.filter['valueCustom']) {
     L122:      let attr = this.filter['value'][filter];

[20:03:23]  tslint: C:/Users/xx-nj/Desktop/DukhanApp/DukhanColor/src/pages/brand/brand.ts, line: 123
            Duplicate variable: 'option'

     L122:  let attr = this.filter['value'][filter];
     L123:  if (attr && Object.keys(attr).length > 0) for (var option in attr) {
     L124:      if(option != 'select' && attr[option]) {

[20:03:23]  tslint: C:/Users/xx-nj/Desktop/DukhanApp/DukhanColor/src/pages/home/home.ts, line: 300
            Duplicate variable: 'diff'

     L299:  element[i]["due_date"] = false;
     L300:  var diff = (start.getTime() - today.getTime()) / 1000;
     L301:  element[i]['time_diff'] = Math.floor(diff);

[20:03:23]  tslint: C:/Users/xx-nj/Desktop/DukhanApp/DukhanColor/src/pages/home/home.ts, line: 165
            'remaining_time' is declared but never used.

     L164:  ngOnInit() {
     L165:      var remaining_time = setInterval(() => {
     L166:          if (this.navCtrl.getActive().component.name == "HomePage") {

[20:03:23]  tslint: C:/Users/xx-nj/Desktop/DukhanApp/DukhanColor/src/pages/search/search.ts, line: 213
            Duplicate variable: 'filter'

     L213:  for (var filter in this.filter['valueCustom']) {
     L214:      let attr = this.filter['value'][filter];

[20:03:23]  tslint: C:/Users/xx-nj/Desktop/DukhanApp/DukhanColor/src/pages/search/search.ts, line: 215
            Duplicate variable: 'option'

     L214:  let attr = this.filter['value'][filter];
     L215:  if (attr && Object.keys(attr).length > 0) for (var option in attr) {
     L216:      if(option != 'select' && attr[option]) {

[20:03:23]  lint finished in 10.05 s

EN

回答 2

Stack Overflow用户

发布于 2018-07-08 19:55:42

似乎平台没有正确返回,这就是它为空的原因。

您没有包含您的构造函数,所以我不知道您的构造函数是什么样子的,但是下面的代码片段使用您在代码中使用的Device plugin正确地返回了平台名称。

代码语言:javascript
复制
import { Device } from '@ionic-native/device';

constructor(private device: Device) {}

......

if(this.device.platform.toLowerCase()=='android'){
    // Your logic here
}
票数 0
EN

Stack Overflow用户

发布于 2018-07-09 14:34:00

发生这种情况是因为你在web上运行ionic serve,而cordova平台在那里不可用。当试图从{}对象中检索数据时,它将返回null。

请尝试添加以下代码:

代码语言:javascript
复制
import { Platform } from 'ionic-angular';

//add it in constructor as follows:
constructor( public platform: Platform){

}
//add platform check
if (this.platform.is('cordova')) {
   //add your code here
}else{
   console.log("Plugin not supported on web");
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51225353

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档