繁体   English   中英

Kivy Builder: AttributeError: 'NoneType' 对象没有属性 'text'

[英]Kivy Buildozer: AttributeError: 'NoneType' object has no attribute 'text'

我正在使用 Buildozer 测试 Kivy,以便为我的 Android 设备制作一个小应用程序。 在我的电脑上,everythink 运行正常。 但是,当我每次收到错误AttributeError: 'NoneType' object has no attribute 'text'时,我都想使用 Buildozer 创建 APK

我用谷歌搜索了很多次,但我找不到我的问题的答案。

有人对我有提示吗?

会很好。

谢谢你!

主要.py:

import kivy
from kivy.lang import Builder
from kivy.uix.widget import Widget
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.gridlayout import GridLayout  
from kivy.uix.textinput import TextInput  
import random
from kivy.clock import Clock
from kivy.properties import ObjectProperty
import requests
import json

def login (name,password):
    url_login = 'URL'
    payload = {'email': name, 'password': password}
    headers = {'content-type': 'application/json'}
    r = requests.post(url_login, data=json.dumps(payload), headers=headers).json()
    return (r['token'])
token =login("ID","PW")

class ConnectPage(GridLayout):
    oee = ObjectProperty(None)
    performance = ObjectProperty(None)
    quality = ObjectProperty(None)
    availability = ObjectProperty(None)
    sensorstandort = ObjectProperty(None)
    schicht = ObjectProperty(None)
    timestamp = ObjectProperty(None)
    alert = ObjectProperty(None)

    def oee_anzeige(self, *args):
        #Anfrage an Server senden
        url_report = 'URL/'
        payload_report = {}
        headers_report = {'content-type': 'application/json', 'Authorization': token}
        r_report = requests.get(url_report, data=json.dumps(payload_report), headers=headers_report)
        response = r_report.json()

        #Schicht, Sensorstandort und ggfs. Störgrund raussuchen
        x = 0
        for i in response['included']:
            if response['included'][x]['type'] == 'shift':
                schicht = response['included'][x]['attributes']['name']
            if response['included'][x]['type'] == 'location':
                sensorstandort = response['included'][x]['attributes']['name']
            if response['included'][x]['type'] == 'notification':

                timestamp = str(response['included'][x]['attributes']['inserted-at'])
                timestamp = timestamp[11:16] + ' Uhr'

                #self.timestamp.text = timestamp
                if response['included'][x]['attributes']['triggered-by'] == 'standstill':
                    self.alert.text = "Verfügbarkeitsverlust seit"
                elif sensorstandort == response['included'][x]['attributes']['triggered-by'] == 'slowdown':
                    self.alert.text = "Leistungsverlust seit"
            x +=1






        #oee Werte aus API ziehen
        oee = str(response['data']['attributes']['oee']) + " %"
        availability = str(response['data']['attributes']['availability']) + " %"
        performance =str(response['data']['attributes']['performance']) + " %"
        quality = str(response['data']['attributes']['quality']) + " %"




        #Labels definieren
        self.oee.text = oee
        self.availability.text = availability
        self.performance.text = performance
        self.quality.text = quality
        self.sensorstandort.text = sensorstandort
        self.schicht.text = schicht


    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.cols = 2  # used for our grid


class EpicApp(App):
    def build(self):
        t = ConnectPage()
        Clock.schedule_once(t.oee_anzeige, 2)
        Clock.schedule_interval(t.oee_anzeige, 90)
        return t



if __name__ == "__main__":
    EpicApp().run()



史诗.kv


<ConnectPage>:





    oee:oee
    availability: availability
    performance: performance
    quality: quality
    sensorstandort: sensorstandort
    schicht: schicht
    alert: alert
    timestamp: timestamp

    GridLayout:
        cols: 2


        Label:
            text: "wird geladen"
            id: sensorstandort
            text_size: self.width, None
            size_hint: 1, None
            height: self.texture_size[1]

        Label:
            text: "wird geladen"
            id: schicht
            text_size: self.width, None
            size_hint: 1, None
            height: self.texture_size[1]

        Label:
            text: "OEE"
            text_size: self.width, None
            size_hint: 1, None
            height: self.texture_size[1]

        Label:
            text: "wird geladen"
            id: oee
            text_size: self.width, None
            size_hint: 1, None
            height: self.texture_size[1]



        Label:
            text: "Verfügbarkeit"
            text_size: self.width, None
            size_hint: 1, None
            height: self.texture_size[1]

        Label:
            text: "Wird geladen"
            id: availability
            text_size: self.width, None
            size_hint: 1, None
            height: self.texture_size[1]



        Label:
            text: "Leistung"
            text_size: self.width, None
            size_hint: 1, None
            height: self.texture_size[1]

        Label:
            text: "Wird geladen"
            id: performance
            text_size: self.width, None
            size_hint: 1, None
            height: self.texture_size[1]


        Label:
            text: "Qualität"
            text_size: self.width, None
            size_hint: 1, None
            height: self.texture_size[1]

        Label:
            text: "Wird geladen"
            id: quality
            text_size: self.width, None
            size_hint: 1, None
            height: self.texture_size[1]


        Label:
            text:
            id: alert
            text_size: self.width, None
            size_hint: 1, None
            height: self.texture_size[1]

        Label:
            text:
            id: timestamp
            text_size: self.width, None
            size_hint: 1, None
            height: self.texture_size[1]

来自 Buildozer Logcat 的日志:

....
04-01 19:37:22.029 19854 19881 I python  :  Traceback (most recent call last):
04-01 19:37:22.030 19854 19881 I python  :    File "/home/julian/kivy/.buildozer/android/app/main.py", line 97, in <module>
04-01 19:37:22.031 19854 19881 I python  :    File "/home/julian/kivy/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/oeecloud/kivy/app.py", line 855, in run
04-01 19:37:22.032 19854 19881 I python  :    File "/home/julian/kivy/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/oeecloud/kivy/base.py", line 504, in runTouchApp
04-01 19:37:22.034 19854 19881 I python  :    File "/home/julian/kivy/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/oeecloud/kivy/core/window/window_sdl2.py", line 747, in mainloop
04-01 19:37:22.035 19854 19881 I python  :    File "/home/julian/kivy/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/oeecloud/kivy/core/window/window_sdl2.py", line 479, in _mainloop
04-01 19:37:22.035 19854 19881 I python  :    File "/home/julian/kivy/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/oeecloud/kivy/base.py", line 339, in idle
04-01 19:37:22.036 19854 19881 I python  :    File "/home/julian/kivy/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/oeecloud/kivy/clock.py", line 591, in tick
04-01 19:37:22.037 19854 19881 I python  :    File "kivy/_clock.pyx", line 384, in kivy._clock.CyClockBase._process_events
04-01 19:37:22.037 19854 19881 I python  :    File "kivy/_clock.pyx", line 414, in kivy._clock.CyClockBase._process_events
04-01 19:37:22.038 19854 19881 I python  :    File "kivy/_clock.pyx", line 412, in kivy._clock.CyClockBase._process_events
04-01 19:37:22.039 19854 19881 I python  :    File "kivy/_clock.pyx", line 167, in kivy._clock.ClockEvent.tick
04-01 19:37:22.040 19854 19881 I python  :    File "/home/julian/kivy/.buildozer/android/app/main.py", line 52, in oee_anzeige
04-01 19:37:22.041 19854 19881 I python  :  AttributeError: 'NoneType' object has no attribute 'text'
04-01 19:37:22.041 19854 19881 I python  : Python for android ended.
....
04-01 19:44:07.500 20768 20788 I python  :  Traceback (most recent call last):
04-01 19:44:07.501 20768 20788 I python  :    File "/home/julian/kivy/.buildozer/android/app/main.py", line 97, in <module>
04-01 19:44:07.502 20768 20788 I python  :    File "/home/julian/kivy/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/oeecloud/kivy/app.py", line 855, in run
04-01 19:44:07.503 20768 20788 I python  :    File "/home/julian/kivy/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/oeecloud/kivy/base.py", line 504, in runTouchApp
04-01 19:44:07.504 20768 20788 I python  :    File "/home/julian/kivy/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/oeecloud/kivy/core/window/window_sdl2.py", line 747, in mainloop
04-01 19:44:07.504 20768 20788 I python  :    File "/home/julian/kivy/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/oeecloud/kivy/core/window/window_sdl2.py", line 479, in _mainloop
04-01 19:44:07.505 20768 20788 I python  :    File "/home/julian/kivy/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/oeecloud/kivy/base.py", line 339, in idle
04-01 19:44:07.505 20768 20788 I python  :    File "/home/julian/kivy/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/oeecloud/kivy/clock.py", line 591, in tick
04-01 19:44:07.506 20768 20788 I python  :    File "kivy/_clock.pyx", line 384, in kivy._clock.CyClockBase._process_events
04-01 19:44:07.507 20768 20788 I python  :    File "kivy/_clock.pyx", line 414, in kivy._clock.CyClockBase._process_events
04-01 19:44:07.507 20768 20788 I python  :    File "kivy/_clock.pyx", line 412, in kivy._clock.CyClockBase._process_events
04-01 19:44:07.508 20768 20788 I python  :    File "kivy/_clock.pyx", line 167, in kivy._clock.ClockEvent.tick
04-01 19:44:07.508 20768 20788 I python  :    File "/home/julian/kivy/.buildozer/android/app/main.py", line 52, in oee_anzeige
04-01 19:44:07.509 20768 20788 I python  :  AttributeError: 'NoneType' object has no attribute 'text'
04-01 19:44:07.509 20768 20788 I python  : Python for android ended.
04-01 19:48:13.346 21723 21762 I python  : Initializing Python for Android
04-01 19:48:13.347 21723 21762 I python  : Setting additional env vars from p4a_env_vars.txt
04-01 19:48:13.347 21723 21762 I python  : Changing directory to the one provided by ANDROID_ARGUMENT
04-01 19:48:13.347 21723 21762 I python  : /data/user/0/org.test.oeecloud/files/app
04-01 19:48:13.356 21723 21762 I python  : Preparing to initialize python
04-01 19:48:13.356 21723 21762 I python  : _python_bundle dir exists
04-01 19:48:13.356 21723 21762 I python  : calculated paths to be...
04-01 19:48:13.356 21723 21762 I python  : /data/user/0/org.test.oeecloud/files/app/_python_bundle/stdlib.zip:/data/user/0/org.test.oeecloud/files/app/_python_bundle/modules
04-01 19:48:13.380 21723 21762 I python  : set wchar paths...
04-01 19:48:13.420 21723 21762 I python  : Initialized python
04-01 19:48:13.420 21723 21762 I python  : AND: Init threads
04-01 19:48:13.421 21723 21762 I python  : testing python print redirection
04-01 19:48:13.422 21723 21762 I python  : Android path ['.', '/data/user/0/org.test.oeecloud/files/app/_python_bundle/stdlib.zip', '/data/user/0/org.test.oeecloud/files/app/...
'P4A_MINSDK': '21', 'LC_CTYPE': 'C.UTF-8'})
...
04-01 19:48:16.306 21723 21762 I python  : [INFO   ] [Base        ] Leaving application in progress...
04-01 19:48:16.307 21723 21762 I python  :  Traceback (most recent call last):
04-01 19:48:16.309 21723 21762 I python  :    File "/home/julian/kivy/.buildozer/android/app/main.py", line 97, in <module>
04-01 19:48:16.311 21723 21762 I python  :    File "/home/julian/kivy/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/oeecloud/kivy/app.py", line 855, in run
04-01 19:48:16.312 21723 21762 I python  :    File "/home/julian/kivy/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/oeecloud/kivy/base.py", line 504, in runTouchApp
04-01 19:48:16.312 21723 21762 I python  :    File "/home/julian/kivy/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/oeecloud/kivy/core/window/window_sdl2.py", line 747, in mainloop
04-01 19:48:16.313 21723 21762 I python  :    File "/home/julian/kivy/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/oeecloud/kivy/core/window/window_sdl2.py", line 479, in _mainloop
04-01 19:48:16.314 21723 21762 I python  :    File "/home/julian/kivy/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/oeecloud/kivy/base.py", line 339, in idle
04-01 19:48:16.314 21723 21762 I python  :    File "/home/julian/kivy/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/oeecloud/kivy/clock.py", line 591, in tick
04-01 19:48:16.315 21723 21762 I python  :    File "kivy/_clock.pyx", line 384, in kivy._clock.CyClockBase._process_events
04-01 19:48:16.315 21723 21762 I python  :    File "kivy/_clock.pyx", line 414, in kivy._clock.CyClockBase._process_events
04-01 19:48:16.315 21723 21762 I python  :    File "kivy/_clock.pyx", line 412, in kivy._clock.CyClockBase._process_events
04-01 19:48:16.316 21723 21762 I python  :    File "kivy/_clock.pyx", line 167, in kivy._clock.ClockEvent.tick
04-01 19:48:16.316 21723 21762 I python  :    File "/home/julian/kivy/.buildozer/android/app/main.py", line 52, in oee_anzeige
04-01 19:48:16.317 21723 21762 I python  :  AttributeError: 'NoneType' object has no attribute 'text'
04-01 19:48:16.317 21723 21762 I python  : Python for android ended.




.py 文件中的这行代码抛出错误

 #self.timestamp.text = timestamp
                if response['included'][x]['attributes']['triggered-by'] == 'standstill':
                    self.alert.text = "Verfügbarkeitsverlust seit"
                elif sensorstandort == response['included'][x]['attributes']['triggered-by'] == 'slowdown':
                    self.alert.text = "Leistungsverlust seit"
            x +=1

我通过查看您发布的日志获得了此信息,该日志表明main.py文件的line 52存在错误

04-01 19:44:07.508 20768 20788 I python  :    File "/home/julian/kivy/.buildozer/android/app/main.py", line 52, in oee_anzeige
04-01 19:44:07.509 20768 20788 I python  :  AttributeError: 'NoneType' object has no attribute 'text'
04-01 19:44:07.509 20768 20788 I python  : Python for android ended.

您好,感谢您的快速回复。 我改变了这些东西,现在我得到一个新的错误

attributeerror 'super' object has no attribute '__getattr__' kivy

我用谷歌搜索并将我的 super.init 编辑为super(ConnectPage, self).__init__(**kwargs)但这个错误仍然发生。

你对我还有什么建议吗? 谢谢! 日志说:

04-02 19:25:36.760 12173 12330 I python:回溯(最近一次调用最后一次):04-02 19:25:36.762 12173 12330 I python:文件“kivy/properties.pyx”,第 86 行属性。 .ObservableDict。 getattr 04-02 19:25:36.764 12173 12330 我蟒蛇:KeyError:'可用性' 04-02 19:25:36.765 12173 12330 我蟒蛇:
04-02 19:25:36.766 12173 12330 I python:在处理上述异常的过程中,发生了另一个异常:04-02 19:25:36.766 12173 12330 I python:
04-02 19:25:36.766 12173 12330 I python:回溯(最近一次调用最后一次):04-02 19:25:36.767 12173 12330 I python:文件“/home/julian/kivy/.buildozer/ main.py", line 96, in 04-02 19:25:36.768 12173 12330 I python : File "/home/julian/kivy/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/ oeecloud/kivy/app.py", line 855, in run 04-02 19:25:36.768 12173 12330 I python : File "/home/julian/kivy/.buildozer/android/platform/build-armeabi-v7a/build /python-installs/oeecloud/kivy/base.py", line 504, in runTouchApp 04-02 19:25:36.769 12173 12330 I python : File "/home/julian/kivy/.buildozer/android/platform/build- armeabi-v7a/build/python-installs/oeecloud/kivy/core/window/window_sdl2.py", line 747, in mainloop 04-02 19:25:36.770 12173 12330 I python : File "/home/julian/kivy/ .buildozer/android/platform/build-armeabi-v7a/build/python-installs/oeecloud/kivy/core/window/window_sdl2.py", line 479, in _mainloop 04-02 19:25:36.771 12173 12330 I python :文件“/home/ju lian/kivy/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/oeecloud/kivy/base.py", line 339, in idle 04-02 19:25:36.773 12173 12330 I python :文件“/home/julian/kivy/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/oeecloud/kivy/clock.py”,第591行,勾选04-02 19:25:36.775 12173 12330 I python :文件“kivy/_clock.pyx”,第 384 行,在 kivy._clock.CyClockBase._process_events 04-02 19:25:36.777 12173 12330 I python:文件“kivy/_clock.pyx4”,line41x4。在 kivy._clock.CyClockBase._process_events 04-02 19:25:36.777 12173 12330 我 python:文件“kivy/_clock.pyx”,第 412 行,在 kivy._clock.CyClockBase._process_events 09:16-2730:16-2730 12330 I python:文件“kivy/_clock.pyx”,第 167 行,在 kivy._clock.ClockEvent.tick 04-02 19:25:36.779 12173 12330 I python:文件“/home/julian/kivy/.buildozer/android /app/main.py", line 75, in oee_anzeige 04-02 19:25:36.779 12173 12330 I python : 文件 "kivy/properties.pyx", line 863, in kivy.properties.ObservableDict。 getattr 04-02 19:25:36.780 12173 12330 I python: AttributeError: 'super' 对象没有属性 ' getattr ' 04-02 19:25:36.780 12173 12330 我 python:Android 的 Python 结束。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM