私の目標は、Python モジュールPlyer (バージョン 1.2.4 ) を使用して、Nexus 5 ( Andrid 5.1.1 ) の地理座標を知ることです。
そこで、インタープリターQPython2.7 (バージョン 1.0.6 ) をスマートフォンにインストールし、Plyer のドキュメントhttps://plyer.readthedocs.org/en/latest/#plyer.facades.GPSの例に触発された次のコードを書きました。 . Qpyton2.7 のインストールには、コードで使用したKivyモジュール (バージョン 1.8.0 ) が含まれています。
プログラムに期待すること:
ボタンを押すと、プログラムは位置の更新を開始し、もう一度押すとプログラムは更新を停止します。プログラムが位置を更新すると、loc() メソッドが呼び出され、ボタンのテキスト値が現在の位置で更新されます。
プログラムが実際に行うこと:
gps.start() 呼び出しでクラッシュします。
ノート:
gps.configure() の前の呼び出しでプログラムがクラッシュしません。Plyer モジュールのメソッド vibrator.vibrate() は正常に動作します!
報告されたエラー:
...
jnius.jnius.JavaMethod のファイル「jnius_export_class.pxi」、562 行目。call (jnius/jnius.c:17724) ファイル「jnius_export_class.pxi」、656 行目、jnius.jnius.JavaMethod.call_method (jnius/jnius.c:18722) ファイル「jnius_utils.pxi」、43 行目、jnius。 jnius.check_exception (jnius/jnius.c:3175) jnius.jnius.JavaException: JVM 例外が発生しました
コード:
#qpy:kivy
from plyer import vibrator
from plyer import gps
from kivy.app import App
from kivy.uix.button import Button
class TestApp(App):
def build(self):
self.locbutton = Button(text='START', on_press=self.start_stop)
return self.locbutton
def on_start(self):
gps.configure(on_location=self.loc)
def loc(self, **kwargs):
self.locbutton.text = 'lat:{lat},lon:{lon}'.format(**kwargs)
def start_stop(self, instance):
if self.locbutton.text == 'START':
#self.locbutton.text = 'STOP'
gps.start()
else:
gps.stop()
self.locbutton.text = 'START'
vibrator.vibrate(0.01)
TestApp().run()