我在 android 槽 Buildozer 上构建 Kivy 应用程序时收到 ReferenceError
I'm receiveing ReferenceError when i build Kivy app on my android trough Buildozer
我的应用程序每次通过 android phone 在我的地图上搜索位置时都会崩溃,尽管它在我的 PC 上工作得很好。
我收到 ReferenceError:weakly-引用的对象不再存在。
主文件
import sqlite3
from kivymd.app import MDApp
from farmersmapview import FarmersMapView
from searchpopupmenu import SearchPopupMenu
class MainApp(MDApp):
connection = None
cursor = None
search_menu = None
def on_start(self):
self.theme_cls.primary_palette = "LightGreen"
self.theme_cls.accent_palette = "Teal"
self.theme_cls.theme_style="Light"
#Inititalize GPS
#Connect to database (DB file)
self.connection=sqlite3.connect("markets.db")
self.cursor = self.connection.cursor()
#instantiate SearchPopupMenu
self.search_menu = SearchPopupMenu()
MainApp().run()
FarmersMap查看文件
class FarmersMapView(MapView):
market_names=[]
getting_markets_timer = None
def start_getting_markets_in_fov(self):
#After one seconds get the markets in the fov
try:
self.getting_markets_timer.cancel()
except:
pass
self.getting_markets_timer = Clock.schedule_once(self.get_markets_in_fov, 1)
def get_markets_in_fov(self, *args):
#get reference to main app and database cursor
min_lat, min_lon, max_lat, max_lon = self.get_bbox()
app = App.get_running_app()#returns main app when running
sql_statement = "SELECT * FROM markets WHERE x > %s AND x < %s AND y > %s AND y < %s "%(min_lon, max_lon, min_lat, max_lat)#sql_stmnt is just a variable
app.cursor.execute(sql_statement)
markets = app.cursor.fetchall()#Returns a list from app.cursor
print(markets)
for market in markets:
name = market[1]
if name in self.market_names:
continue
else:
self.add_market(market)
def add_market(self, market):
# create MarketMarker
lat, lon = market[21], market[20]#each market is a list of info where lat located at index 21 and lon at index 20
marker = MarketMarker(lat=lat, lon=lon, source=image)
marker.size=(35,35)
marker.market_data=market#wtf is going on here
#add MarketMarker to the map
self.add_widget(marker)
#Keep track of the MarketMarker's name (to avoid duplicates)
name = market[1]
self.market_names.append(name)
我花了大约 3 天的时间来解决这个问题。尝试从我的代码中删除所有 kivy.clock 引用,尝试搜索弱引用对象并将其替换为强引用对象,尝试在 buildozer.spec 中指定 python 和 kivy 版本,尝试重新- 安装 ubuntu,尝试进入 weakmethod.py 并将 dead_method() 代码替换为此
try:
return self.proxy is not None and not bool(dir(self.proxy))
except ReferenceError:
return True
强烈怀疑问题出在get_markers_in_fov,所以我尝试用强引用对象的方式重写它,但没有成功。我对编程很陌生,所以我可能会错过那里的东西。
它是这样发生的:
https://youtu.be/XKLO6euSEBk
我安装了 xubuntu 而不是 ubuntu,并使用更新的 buildozer 教程设置了所有内容,问题已解决
我的应用程序每次通过 android phone 在我的地图上搜索位置时都会崩溃,尽管它在我的 PC 上工作得很好。
我收到 ReferenceError:weakly-引用的对象不再存在。
主文件
import sqlite3
from kivymd.app import MDApp
from farmersmapview import FarmersMapView
from searchpopupmenu import SearchPopupMenu
class MainApp(MDApp):
connection = None
cursor = None
search_menu = None
def on_start(self):
self.theme_cls.primary_palette = "LightGreen"
self.theme_cls.accent_palette = "Teal"
self.theme_cls.theme_style="Light"
#Inititalize GPS
#Connect to database (DB file)
self.connection=sqlite3.connect("markets.db")
self.cursor = self.connection.cursor()
#instantiate SearchPopupMenu
self.search_menu = SearchPopupMenu()
MainApp().run()
FarmersMap查看文件
class FarmersMapView(MapView):
market_names=[]
getting_markets_timer = None
def start_getting_markets_in_fov(self):
#After one seconds get the markets in the fov
try:
self.getting_markets_timer.cancel()
except:
pass
self.getting_markets_timer = Clock.schedule_once(self.get_markets_in_fov, 1)
def get_markets_in_fov(self, *args):
#get reference to main app and database cursor
min_lat, min_lon, max_lat, max_lon = self.get_bbox()
app = App.get_running_app()#returns main app when running
sql_statement = "SELECT * FROM markets WHERE x > %s AND x < %s AND y > %s AND y < %s "%(min_lon, max_lon, min_lat, max_lat)#sql_stmnt is just a variable
app.cursor.execute(sql_statement)
markets = app.cursor.fetchall()#Returns a list from app.cursor
print(markets)
for market in markets:
name = market[1]
if name in self.market_names:
continue
else:
self.add_market(market)
def add_market(self, market):
# create MarketMarker
lat, lon = market[21], market[20]#each market is a list of info where lat located at index 21 and lon at index 20
marker = MarketMarker(lat=lat, lon=lon, source=image)
marker.size=(35,35)
marker.market_data=market#wtf is going on here
#add MarketMarker to the map
self.add_widget(marker)
#Keep track of the MarketMarker's name (to avoid duplicates)
name = market[1]
self.market_names.append(name)
我花了大约 3 天的时间来解决这个问题。尝试从我的代码中删除所有 kivy.clock 引用,尝试搜索弱引用对象并将其替换为强引用对象,尝试在 buildozer.spec 中指定 python 和 kivy 版本,尝试重新- 安装 ubuntu,尝试进入 weakmethod.py 并将 dead_method() 代码替换为此
try:
return self.proxy is not None and not bool(dir(self.proxy))
except ReferenceError:
return True
强烈怀疑问题出在get_markers_in_fov,所以我尝试用强引用对象的方式重写它,但没有成功。我对编程很陌生,所以我可能会错过那里的东西。
它是这样发生的: https://youtu.be/XKLO6euSEBk
我安装了 xubuntu 而不是 ubuntu,并使用更新的 buildozer 教程设置了所有内容,问题已解决