HarmonyOS鸿蒙Next中HelloWorld出错了,哪位大哥指点一下?
HarmonyOS鸿蒙Next中HelloWorld出错了,哪位大哥指点一下?
结构如下,是官方给出的结构
![结构图]
main_layout.xml文件如下,官方复制过来的
<?xml version="1.0" encoding="utf-8"?>
<DependentLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:width="match_parent"
ohos:height="match_parent"
ohos:background_element="#000000">
<Text
ohos:id="$+id:text"
ohos:width="match_content"
ohos:height="match_content"
ohos:center_in_parent="true"
ohos:text="Hello World"
ohos:text_color="white"
ohos:text_size="32fp"/>
<Button
ohos:id="$+id:button"
ohos:width="match_content"
ohos:height="match_content"
ohos:text_size="19fp"
ohos:text="Next"
ohos:top_padding="8vp"
ohos:bottom_padding="8vp"
ohos:right_padding="80vp"
ohos:left_padding="80vp"
ohos:text_color="white"
ohos:background_element="$graphic:button_element"
ohos:center_in_parent="true"
ohos:align_parent_bottom="true"/>
</DependentLayout>
button_element.xml如下,是官方复制过来的 报错了
![button_element.xml]
MainAbilitySlice如下,是官方复制过来的, 报错了
![MainAbilitySlice]
控制台情况
![控制台情况]
更多关于HarmonyOS鸿蒙Next中HelloWorld出错了,哪位大哥指点一下?的实战教程也可以访问 https://www.itying.com/category-93-b0.html
压根就不熟报错。只是开发工具的一点不足之处,资源文件找不到。类似于安卓的R文件,编译后才能生成R文件
更多关于HarmonyOS鸿蒙Next中HelloWorld出错了,哪位大哥指点一下?的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
感谢技术大大,已经可以运行,为提供给其他开发者同样的问题,特此回复
这是成功的页面
解决的步骤:
这个错误是之前的,我今天再次登录进来,不知道为什么,我什么都没操作,就自动变成了这个来
自动解决了
以下错误依然存在,但是我的HelloWorld已经出来了
界面是出来了,但是控制台是错误的
完整报错信息如下:
09/13 10:10:11: Launching com.example.myapplication
$hdc shell am force-stop com.example.myapplication
$hdc file send E:/AllProject/DevEco/MyApplication/entry/build/outputs/hap/debug/entry-debug-unsigned.hap /sdcard/entry-debug-unsigned.hap
$hdc shell bm install -p /sdcard/entry-debug-unsigned.hap
$hdc shell am start -n "com.example.myapplication/com.example.myapplication.MainAbilityShellActivity"
Client not ready yet..Waiting for process to come online
Connected to process 2362 on device huawei-gll_al00-127.0.0.1:18888
Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page.
I/Zygote: seccomp disabled by setenforce 0
I/e.myapplicatio: Late-enabling -Xcheck:jni
E/e.myapplicatio: Unknown bits set in runtime_flags: 0x8000
I/e.myapplicatio: Reinit property: dalvik.vm.checkjni= false
ReInitProperties: persist.vm.debug.dumpapi= false
E/HwDFRFrameworkFactory: Class Not found Exception
I/HwDFRFrameworkFactory: No ZrHung framework implements exists.
D/ActivityThread: Attach thread to application
E/HwDFRFrameworkFactory: Class Not found Exception
I/HwDFRFrameworkFactory: No ZrHung framework implements exists.
W/e.myapplicatio: Can't mmap dex file /data/app/com.example.myapplication-qoSnG1NcFKlc7JRdDFgWIA==/base.apk!classes.dex directly; please zipalign to 4 bytes. Falling back to extracting file.
W/e.myapplicatio: JIT profile information will not be recorded: profile file does not exits.
I/ActivityThread: Init compatible state: true
D/HwFrameworkSecurityPartsFactory: HwFrameworkSecurityPartsFactory in.
I/HwFrameworkSecurityPartsFactory: add HwFrameworkSecurityPartsFactory to memory.
E/BehaviorCollectManager: Fail to acquire dataAnalyzerService...
I/HwApiCacheMangerEx: apicache path=/storage/emulated/0 state=mounted key=com.example.myapplication#10060#256
need clear apicache, because volumes changed,oldCnt=0 newCnt=1
I/HwApiCacheMangerEx: apicache path=/storage/emulated/0 state=mounted key=com.example.myapplication#10060#0
need clear apicache, because volumes changed,oldCnt=1 newCnt=1
I/HwPartIawareFactory: add android.common.HwPartIawareFactoryImpl to memory.
I/AwareBitmapCacher: init processName:com.example.myapplication pid=2362 uid=10060
I/ActivityThread: finishPreloaded preloadStatus 0
D/OpenGLRenderer: disableOutlineDraw is true
D/libEGL: Emulator has host GPU support, qemu.gles is set to 1.
E/HwDFRFrameworkFactory: Class Not found Exception
I/HwDFRFrameworkFactory: No ZrHung framework implements exists.
V/ActivityThread: callActivityOnCreate
D/libEGL: loaded /vendor/lib64/egl/libEGL_emulation.so
D/libEGL: loaded /vendor/lib64/egl/libGLESv1_CM_emulation.so
D/libEGL: loaded /vendor/lib64/egl/libGLESv2_emulation.so
W/e.myapplicatio: Can't mmap dex file /data/app/com.example.myapplication-qoSnG1NcFKlc7JRdDFgWIA==/feature_entry-debug-unsigned.hap!classes.dex directly; please zipalign to 4 bytes. Falling back to extracting file.
D/AGP: VsyncSchedulerAndroid:jni is registered.
Typeface:native typeface ptr 0x74cafce260
Typeface:native typeface ptr 0x74cafce260
Typeface:native typeface ptr 0x74cafce8a0
Typeface:native typeface ptr 0x74cafce260
Typeface:native typeface ptr 0x74cafce500
Typeface:native typeface ptr 0x74cafce380
Typeface:native typeface ptr 0x74cafce8c0
Typeface:native typeface ptr 0x74cafce8e0
Initialize system fonts.
E/GraphicsEnv: Failed to get gpu service
I/DecorView[]: old windowMode:0 new windoMode:1
D/ActivityThread: add activity client record, r= ActivityRecord{e0ba0c2 token=android.os.BinderProxy@8b75e9d {com.example.myapplication/com.example.myapplication.MainAbilityShellActivity}} token= android.os.BinderProxy@8b75e9d
D/AGP: Initialize system language.
D/AGP: BF:Client
I/FactoryLoader: loadFactory() ClassNotFoundException !
I/HwPartPowerOfficeFactory: add HwPartPowerOfficeFactoryImpl to memory.
D/InputEventReceiver: dispatchInputInterval 0
E/RtgSchedIpcFile: RtgSchedIpcFile failed to open /proc/2362/rtg
I/RmeSchedManager: init Rme, version is: v1.0
E/RtgSchedIpcFile: setCommandByIoctl not opened
D/RtgSched: resetRtgSchedHandle failed enable:1
D/OpenGLRenderer: disableOutlineDraw is true
E/RtgSchedIpcFile: setCommandByIoctl not opened
W/HiTouch_HiTouchSensor: depended package hiTouch doesn't exist!
I/HiTouch_HiTouchSensor: HiTouch restricted: system app HiTouch don't exist.
D/HiTouch_PressGestureDetector: onAttached, package=com.example.myapplication, windowType=1, mHiTouchRestricted=true
D/RtgSched: resetRtgSchedHandle failed enable:1
I/iGraphics: [0020080c] pn: com.example.myapplication, p: 2362
[0030080c] no spt app: com.example.myapplication
I/FrameFlow: FrameFlowInit app is not supported by frameflow solution
D/: HostConnection::get() New Host Connection established 0x74cf6d7540, tid 2419
I/FrameFlow: FrameFlowInit app is not supported by frameflow solution
W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
D/AGP: ReSubscribeCachedEvents .
MMI: UIView::SubscribeVoiceEvents
BF:Client register new ability
W/e.myapplicatio: Call to JNI FindClass with dots in name: "ohos.accessibility.AccessibilitySystemAbilityClient"
D/: HostConnection::get() New Host Connection established 0x74dc0a6460, tid 2464
D/AGP: BF:Client Register
MMI: UIView::SubscribeVoiceEvents
ReSubscribeCachedEvents .
MMI: UIView::SubscribeVoiceEvents
ReSubscribeCachedEvents .
MMI: UIView::SubscribeVoiceEvents
ReSubscribeCachedEvents .
MMI: UIView::SubscribeVoiceEvents
D/EGL_emulation: eglCreateContext: 0x74cf6544e0: maj 3 min 0 rcv 3
D/AGP: Surface created: width:466, height:466
D/EGL_emulation: eglCreateContext: 0x74c14b8760: maj 3 min 0 rcv 3
D/EGL_emulation: eglMakeCurrent: 0x74cf6544e0: ver 3 0 (tinfo 0x74cf625dc0)
W/Gralloc3: mapper 3.x is not supported
D/HAL: loaded HAL id=gralloc path=/vendor/lib64/hw/gralloc.ranchu.so hmi=0x747049c010 handle=0x84ab2f3133c0d699
D/EGL_emulation: eglMakeCurrent: 0x74c14b8760: ver 3 0 (tinfo 0x74dc14b8c0)
D/HwForceDark: [SetDarkThemeInfo] enable = [0], appType = [0], winWidth = [466]
D/EGL_emulation: eglMakeCurrent: 0x74cf6544e0: ver 3 0 (tinfo 0x74cf625dc0)
E/EGL_emulation: eglQuerySurface 313d EGL_BAD_ATTRIBUTE
D/DecorView: showOrHideHighlightView: hasFocus=true; winMode=1; isMrgNull=true
W/InputMethodManager: startInputReason = 1
E/AGP: can not find focus
W/FastPrintWriter: Write failure
java.io.IOException: write failed: EPIPE (Broken pipe)
at libcore.io.IoBridge.write(IoBridge.java:544)
at java.io.FileOutputStream.write(FileOutputStream.java:392)
at com.android.internal.util.FastPrintWriter.flushBytesLocked(FastPrintWriter.java:354)
at com.android.internal.util.FastPrintWriter.flushLocked(FastPrintWriter.java:377)
at com.android.internal.util.FastPrintWriter.flush(FastPrintWriter.java:412)
at android.app.ActivityThread.handleDumpActivity(ActivityThread.java:4741)
at android.app.ActivityThread.access$3600(ActivityThread.java:251)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2390)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:219)
at android.app.ActivityThread.main(ActivityThread.java:8380)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1083)
Caused by: android.system.ErrnoException: write failed: EPIPE (Broken pipe)
at libcore.io.Linux.writeBytes(Native Method)
at libcore.io.Linux.write(Linux.java:294)
at libcore.io.ForwardingOs.write(ForwardingOs.java:241)
at libcore.io.BlockGuardOs.write(BlockGuardOs.java:416)
at libcore.io.ForwardingOs.write(ForwardingOs.java:241)
at libcore.io.IoBridge.write(IoBridge.java:539)
at java.io.FileOutputStream.write(FileOutputStream.java:392)
at com.android.internal.util.FastPrintWriter.flushBytesLocked(FastPrintWriter.java:354)
at com.android.internal.util.FastPrintWriter.flushLocked(FastPrintWriter.java:377)
at com.android.internal.util.FastPrintWriter.flush(FastPrintWriter.java:412)
at android.app.ActivityThread.handleDumpActivity(ActivityThread.java:4741)
at android.app.ActivityThread.access$3600(ActivityThread.java:251)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2390)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:219)
at android.app.ActivityThread.main(ActivityThread.java:8380)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1083)
E/e.myapplicatio: GcSupervisor: parse parameters failed
D/AwareBitmapCacher: handleInit switch not opened pid=2362
尊敬的开发者您好,这个问题目前可以这样解决,点击IDE右侧的Gradle,出现如图所示界面,点击Reimport按钮即可解决该问题,此问题后面会进行修复。
找HarmonyOS工作还需要会Flutter的哦,有需要Flutter教程的可以学学大地老师的教程,很不错,B站免费学的哦:BV1S4411E7LY/?p=17
写完布局文件先别直接用 编译一次先 这应该是开发工具的一个小BUG 后面会优化
尊敬的开发者,您好
建议您尝试清除下缓存,再build一下看看,如有问题,继续留言哒
Could not resolve com.huawei.ohos:hap:2.4.4.2.
Could not get resource ‘https://repo.huaweicloud.com/repository/maven/com/huawei/ohos/hap/2.4.4.2/hap-2.4.4.2.pom’.
Could not GET ‘https://repo.huaweicloud.com/repository/maven/com/huawei/ohos/hap/2.4.4.2/hap-2.4.4.2.pom’.
repo.huaweicloud.com:443 failed to respond
清除了问题依旧存在,鸿蒙的ide 得加油了
咱们直接编译试一下能不能过?看截图编译成功了,只是IDE报错了
资源表 读取不到????
有要学HarmonyOS AI的同学吗,联系我:https://www.itying.com/goods-1206.html
亲爱滴开发者 ,这个问题已经在处理中啦,稍后答复你哟 ,么么哒
小姐姐,麻烦您能指点下我吗?
在HarmonyOS鸿蒙Next中,HelloWorld出错可能涉及以下几个方面:
-
项目配置问题:检查
config.json
文件,确保bundleName
、vendor
、version
等字段正确配置。module
部分需包含name
、type
、deviceTypes
等字段,且abilities
中的name
、icon
、label
、launchType
等需正确设置。 -
资源文件问题:确保
resources
目录下的base
、en_US
、zh_CN
等子目录中的资源文件(如字符串、图片)命名正确,且与config.json
中的引用一致。 -
代码逻辑问题:检查
MainAbility
类中的onStart
方法,确保super.onStart(intent)
和setUIContent(ResourceTable.Layout_ability_main)
调用正确。MainAbilitySlice
中的onStart
方法需调用super.onStart(attrs)
和setUIContent(ResourceTable.Layout_ability_main)
。 -
布局文件问题:检查
resources/base/layout/ability_main.xml
文件,确保布局文件中的组件ID与代码中的引用一致。 -
编译环境问题:确保DevEco Studio版本与HarmonyOS SDK版本匹配,且项目依赖的
ohos
库版本正确。 -
日志查看:通过
HiLog
或Logcat
查看运行日志,定位具体错误信息。 -
权限问题:检查
config.json
中的reqPermissions
字段,确保应用所需权限已正确声明。 -
设备兼容性:确保目标设备支持HarmonyOS Next版本,且设备已正确连接并授权调试。
以上是HelloWorld出错可能涉及的几个方面,需逐一排查。
在HarmonyOS鸿蒙Next中,如果HelloWorld程序出错,可以从以下几个方面排查:
-
确保开发环境(如DevEco Studio)已正确安装,并且SDK版本与项目匹配。
-
确认
MainAbility
和MainAbilitySlice
的实现是否正确,特别是onStart
方法中是否调用了super.onStart()
。 -
检查
config.json
文件中的abilities
和pages
配置是否正确。 -
使用
Log
工具查看运行日志,定位具体错误。 -
确保所有依赖库都已正确添加,版本兼容。
如果仍无法解决,建议参考官方文档或社区论坛获取更多帮助。