Closed hushanhsiang closed 6 years ago
You can work around this by loading the project using File > New > Import Project, rather than File > Open.
Thanks for the report, we'll fix this in the next version if possible.
OK, it's no error happen now by "import project". But I don't see any difference between Android's "Hello World" and "chaquopy-hello". I can find "hello.py" in this project but how to edit it to show "Chaquopy Hello" or other words. Please help, thanks.
Apart from being in Python, the project works just like a normal Android project. The onCreate
method calls setContentView
to load the layout file here:
https://github.com/chaquo/chaquopy-hello/blob/master/app/src/main/res/layout/activity_main.xml
You can edit the layout file with the visual editor in Android Studio, or by directly editing the XML.
Any tutorials on Android programming in Java should be fairly easy to adapt to Chaquopy, following the pattern of the initial port.
This is OscarHu.... "chaquopy-master" project is running well with my HTC phone, so far. I will test more and study how to make my code by learning from this demo, but it's complex for me. Still need a very simple code running only python with Android. Thanks.
I think the Android user interface API is generally well-designed, but yes, it does take some time to learn. As I said in the other issue, we'll release another example app soon for running text-based Python scripts without a GUI.
Hi, Malcolm: The pure text-based is not what I need, I need a very simple code to know how to use the GUI by python. I already put an example in "chaquopy-hello" issue. It's need to know how import android's View class and how to use it by python.
If I'd like to use the others android's class (GUI), how to make a correct import and how to use them by python. It should be the "Quick Start" code and simple examples code. Thank you.
2018-01-10 9:20 GMT+08:00 Malcolm Smith notifications@github.com:
I think the Android user interface API is generally well-designed, but yes, it does take some time to learn. As I said in the other issue, we'll release another example app soon for running text-based Python scripts without a GUI.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/chaquo/chaquopy/issues/22#issuecomment-356468469, or mute the thread https://github.com/notifications/unsubscribe-auth/AYsmcmaHbayNmys-IsakXmmjLUPSeAypks5tJBB0gaJpZM4RXQGJ .
-- Best regards,
Oscar Hu
Mobile: +886-920-691966
Email: oscarhu@gmail.com
Skype:oscarhu
(Moved from https://github.com/chaquo/chaquopy-hello/issues/2)
I found below code in hello.py: "class MainActivity(static_proxy(AppCompatActivity)):
@Override(jvoid, [Bundle])
def onCreate(self, state):
AppCompatActivity.onCreate(self, state)
self.setContentView(R.layout.activity_main)"
Is it means that I can start my program by "hello.py" directly? Don't need a "MainActivity.java" to start the program?
I'd like to change "Hello World" of the TextView to "Chaquopy Hello World" by Python code then I put "self.findViewById(R.id.txv).setText(R.string.app_name)" in the code but not working, stop by system error.
"class MainActivity(static_proxy(AppCompatActivity)):
@Override(jvoid, [Bundle])
def onCreate(self, state):
AppCompatActivity.onCreate(self, state)
self.setContentView(R.layout.activity_main)
self.findViewById(R.id.txv).setText(R.string.app_name)
" Already changed the id of "TextView" in "active_main.xml" as below and used the "app_name" string in "string.xml". TextView android:id="@+id/txv" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello World!" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" /
Is it means that I can start my program by "hello.py" directly? Don't need a "MainActivity.java" to start the program?
Yes, the static_proxy
mechanism generates the corresponding Java file automatically, so you don't need to deal with that.
Your changes look fine to me. What was the error you received?
It can be made an APK code by Android Studio and installed on my HTC phone but got an Error message, "Unfortunately, Chaquopy Hello World has stopped" while running it. Could you try it on your side since it's very little change of "chaquopy-hello"?
I have, and it worked as expected. Please find the error details in the logcat as described here.
Split APKs installed $ adb shell am start -n "com.chaquo.python.hello/hello.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER Unexpected error while executing: am start -n "com.chaquo.python.hello/hello.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER Error while Launching activity
No, that's the Run window. The details of the error should be in the Logcat window.
I take a screen shot as below link: https://images2.imgbox.com/62/59/TEkdZ8Ab_o.png And the text of Logcat error message:
01-11 06:44:20.044 22343-22343/com.chaquo.python.hello E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.chaquo.python.hello, PID: 22343
java.lang.ExceptionInInitializerError
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.Class.newInstance(Class.java:1572)
at android.app.Instrumentation.newActivity(Instrumentation.java:1083)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2400)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2563)
at android.app.ActivityThread.access$800(ActivityThread.java:162)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1438)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:209)
at android.app.ActivityThread.main(ActivityThread.java:5900)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1005)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:800)
Caused by: com.chaquo.python.PyException: ModuleNotFoundError: No module named 'android'
at <python>.java.chaquopy.import_override (.c:59641)(java\import.pxi:18)
at <python>.reraise(/data/data/com.chaquo.python.hello/files/chaquopy/chaquopy.zip/java/_vendor/six.py:686)
at <python>.java.chaquopy.import_override (.c:60681)(java\import.pxi:53)
at <python>.<module>(/android_asset/chaquopy/app.zip/hello.py:7)
at <python>.load_module_impl(/data/data/com.chaquo.python.hello/files/chaquopy/chaquopy.zip/java/android/importer.py:155)
at <python>.load_module(/data/data/com.chaquo.python.hello/files/chaquopy/chaquopy.zip/java/android/importer.py:91)
at <python>._load_backward_compatible(<frozen importlib._bootstrap>:626)
at <python>._load_unlocked(<frozen importlib._bootstrap>:656)
at <python>._find_and_load_unlocked(<frozen importlib._bootstrap>:955)
at <python>._find_and_load(<frozen importlib._bootstrap>:971)
at <python>._gcd_import(<frozen importlib._bootstrap>:994)
at <python>.import_module(/data/data/com.chaquo.python.hello/files/chaquopy/stdlib.zip/importlib/__init__.py:126)
at <python>.chaquopy_java.Java_com_chaquo_python_Python_getModule (.c:2790)(chaquopy_java.pyx:128)
at com.chaquo.python.Python.getModule(Native Method)
at hello.MainActivity.<clinit>(MainActivity.java:13)
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.Class.newInstance(Class.java:1572)
at android.app.Instrumentation.newActivity(Instrumentation.java:1083)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2400)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2563)
at android.app.ActivityThread.access$800(ActivityThread.java:162)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1438)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:209)
at android.app.ActivityThread.main(ActivityThread.java:5900)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1005)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:800)
Well, there is no import statement at hello.py:7 in the original file, so you must have added something else. If you've added a line simply saying import android
or similar, then unfortunately that won't work: please see the notes about the limitations of the import hook.
It's interesting, I didn't modify anything but it works well now. Anything change on Chaquopy? It's great and I can try the others Android feature with Chaquopy~~~
Next topic is how to use python libraries such as json, requests, beautifulsoup...... Any notes to use them? thanks.
As of a few minutes ago, the original Android Studio loading errors are fixed for both the demo and "hello" projects. Nothing else has changed on our side.
This Error is also happen while load chaquopy-hellp project.