Kivy:[WindowSDL] 未找到 运行 应用程序,退出

Kivy: [WindowSDL] No running App found, exit

我正在使用 jnius 和 intents 在 kivy 中从图库中选择图像 然后我点击按钮打开画廊,应用程序正在关闭 logcat 我得到

05-07 15:27:19.507 30865 30865 I python : [INFO] [WindowSDL] 未找到 运行 应用程序,退出。 05-07 15:27:19.508 30865 30865 I python : [INFO] [Base] 正在离开应用程序... 05-07 15:27:19.514 30865 30923 I python : [INFO] [WindowSDL] 退出主循环并关闭。

05-07 15:27:19.570 30865 30923 I python : Traceback (最近调用最后): 05-07 15:27:19.570 30865 30923 I python:文件“/content/.buildozer/android/app/main.py”,第 103 行,在

05-07 15:27:19.571 30865 30923 I python : AttributeError: 'NoneType' 对象没有属性 'run'

05-07 15:27:19.571 30865 30923 I python : Python for android 结束。 这是我的代码:-

from android.runnable import run_on_ui_thread as run_thread
from jnius import autoclass, cast
from kivy.uix.widget import Widget
from kivy.core.window import Window
from kivy.uix.gridlayout import GridLayout
from kivy.uix.button import Button
from kivy.app import runTouchApp
from kivy.clock import Clock, mainthread
from android import activity as act
    
m=GridLayout(cols=1,rows=1)
d=GridLayout(cols=1,rows=1)
m.add_widget(d)
Uri = autoclass('android.net.Uri')

# Value of MediaStore.Images.Media.DATA
MediaStore_Images_Media_DATA = "_data"

# Custom request codes
RESULT_LOAD_IMAGE = 1
PythonActivity = autoclass('org.kivy.android.PythonActivity')
WebViewA = autoclass('android.webkit.WebView')
Intent = autoclass('android.content.Intent')
Activity = autoclass('android.app.Activity')
WebViewClient = autoclass('android.webkit.WebViewClient')
LinearLayout = autoclass('android.widget.LinearLayout')
Context = autoclass('android.content.Context')
Uri = autoclass('android.net.Uri')
ViewGroup = autoclass('android.view.ViewGroup')
LayoutParams = autoclass('android.view.ViewGroup$LayoutParams')
# Activity is only used to get these codes. Could just hardcode them.
    # /** Standard activity result: operation canceled. */
    # public static final int RESULT_CANCELED    = 0;
    # /** Standard activity result: operation succeeded. */
    # public static final int RESULT_OK           = -1;
    # /** Start of user-defined activity results. */
    # Not sure what this means
    # public static final int RESULT_FIRST_USER   = 1;
@run_thread
def Push(callback):
    """Open Gallery Activity and call callback with absolute image filepath of image user selected.
    None if user canceled.
    """
    activity1 = cast('android.app.Activity', PythonActivity.mActivity)
    # PythonActivity.mActivity is the instance of the current Activity
    # BUT, startActivity is a method from the Activity class, not from our
    # PythonActivity.
    # We need to cast our class into an activity and use it
    # Forum discussion: https://groups.google.com/forum/#!msg/kivy-users/bjsG2j9bptI/-Oe_aGo0newJ
    def on_activity_result(request_code, result_code, intent):
        if request_code != RESULT_LOAD_IMAGE:
            print("not selected")
            return

        if result_code == Activity.RESULT_CANCELED:
            Clock.schedule_once(lambda dt: callback(None), 0)
            return

        if result_code != Activity.RESULT_OK:
            # This may just go into the void...
            raise NotImplementedError('Unknown result_code "{}"'.format(result_code))

        selectedImage = intent.getData() # Uri
        filePathColumn = [MediaStore_Images_Media_DATA] # String[]
        # Cursor
        cursor = currentActivity.getContentResolver().query(selectedImage,
                filePathColumn, None, None, None)
        cursor.moveToFirst()

        # int
        columnIndex = cursor.getColumnIndex(filePathColumn[0])
        # String
        picturePath = cursor.getString(columnIndex)
        cursor.close()
        print('android_ui: user_select_image() selected '+picturePath)
        parent = cast(ViewGroup, layout.getParent())
        if parent is not None:parent.removeView(layout)
        webview.clearHistory()
        webview.clearCache(True)
        webview.clearFormData()
        webview.destroy()
        layout = None
        webview = None


    # See: http://pyjnius.readthedocs.org/en/latest/android.html
    act.bind(on_activity_result=on_activity_result)

    intent= Intent(Intent.ACTION_GET_CONTENT)
    intent.addCategory(Intent.CATEGORY_OPENABLE)
    intent.setType("image/*")
    intent.setAction(Intent.ACTION_GET_CONTENT)
    

    # http://programmerguru.com/android-tutorial/how-to-pick-image-from-gallery/
    # 

    # TODO setType(Image)?
    activity1.startActivityForResult(intent, RESULT_LOAD_IMAGE)
b=Button(text="hi")
b.bind(on_press=Push)
d.add_widget(b)
runTouchApp(m)

提前致谢

添加 类 并将其更改为 App() 后。运行() 通过上面的评论可以正常工作谢谢