RawText " " must be wrapped in an explicit <Text> component

本文分享了一次解决React Native中RawText必须被显式的Text组件包裹的问题经历,并提供了正确的代码书写方式,强调了遵循代码风格的重要性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

今天在写博客的时候,本来打算写一些学习的过程,现在19:00了,可是居然出现

RawText " " must be wrapped in an explicit <Text> component

这样的错误,由于初学,所有查找资料的时候,发现react-native也有如此严格的代码风格。


我的代码是这样写的:

 <View>       <Text>开发</Text></View>

亲们发现有什么问题吗?


报的错误就是这样的,


一开始没注意,可以后才把注意力放在“  ”上,也就是说“  ”出现了错误,仔细查找代码,发现代码风格一定要规范,这也是在学习react-native的时候,提前学习一下JavaScript的原因,可以不细究,但是基本语法一定要学。

修改:

如果View在同一行上,中间不要有空格

<View><Text>开发</Text></View>
如果不在同一行上
<View><Text>开发</Text>
</View>

这么写或者

<View>
<Text>开发</Text>
</View>
这样写都可以


明天把学习博客也补上






<?xml version="1.0" encoding="utf-8" ?> <Defs> <ThingDef Abstract="True" Name="MeleeWeaponUltratech" ParentName="BaseWeapon"> <techLevel>Ultra</techLevel> <statBases> <MarketValue>2000</MarketValue> <Mass>2</Mass> </statBases> <comps> <li> <compClass>CompQuality</compClass> </li> <li Class="CompProperties_Art"> <nameMaker>NamerArtWeaponMelee</nameMaker> <descriptionMaker>ArtDescription_WeaponMelee</descriptionMaker> <minQualityForArtistic>Excellent</minQualityForArtistic> </li> <li Class="CompProperties_Biocodable"/> </comps> <smeltable>true</smeltable> <burnableByRecipe>true</burnableByRecipe> <thingCategories> <li>WeaponsMelee</li> </thingCategories> <weaponTags> <li>UltratechMelee</li> </weaponTags> <tradeTags> <li>WeaponMelee</li> </tradeTags> <weaponClasses> <li>Melee</li> <li>Ultratech</li> </weaponClasses> <thingSetMakerTags> <li>RewardStandardMidFreq</li> </thingSetMakerTags> </ThingDef> <ThingDef ParentName="MeleeWeaponUltratech"> <defName>MeleeWeapon_PlasmaSword</defName> <label>plasmasword</label> <description>A metal-cored sword with a cutting edge. Plasma is wrapped around the core, held in place by an energy field. Targets are both sliced by the metal core, as well as burned or ignited by the plasma sheath.</description> <soundInteract>Interact_PlasmaSword</soundInteract> <meleeHitSound>MeleeHit_PlasmaSword</meleeHitSound> <equippedAngleOffset>-65</equippedAngleOffset> <relicChance>3</relicChance> <smeltable>false</smeltable> <weaponClasses> <li>MeleePiercer</li> </weaponClasses> <graphicData> <texPath>Things/Item/Equipment/WeaponMelee/PlasmaSword</texPath> <graphicClass>Graphic_Single</graphicClass> </graphicData> <tools> <li> <label>handle</label> <capacities> <li>Blunt</li> </capacities> <power>12</power> <cooldownTime>2</cooldownTime> </li> <li> <label>point</label> <capacities> <li>Stab</li> </capacities> <power>21</power> <cooldownTime>2.6</cooldownTime> <extraMeleeDamages> <li> <def>Flame</def> <amount>10</amount> <chance>0.5</chance> </li> </extraMeleeDamages> </li> <li> <label>edge</label> <capacities> <li>Cut</li> </capacities> <power>21</power> <cooldownTime>2.6</cooldownTime> <extraMeleeDamages> <li> <def>Flame</def> <amount>10</amount> <chance>0.5</chance> </li> </extraMeleeDamages> </li> </tools> </ThingDef> </Defs>逐行解释
最新发布
07-19
这段 XML 定义了一个 **高科技近战武器基类 `MeleeWeaponUltratech`** 和一个具体的高科技武器 **PlasmaSword(等离子剑)**。我们将逐行解释其含义,帮助你理解它是如何在 **RimWorld** 中定义并工作的。 --- ### 🔧 `<Defs>` 标签 ```xml <Defs> ``` - 所有 `ThingDef` 的根标签。 - 表示这是一个包含多个物品定义的 XML 块。 --- ## 🛡️ `<ThingDef Abstract="True" Name="MeleeWeaponUltratech" ParentName="BaseWeapon">` — 高科技近战武器基类 ```xml <ThingDef Abstract="True" Name="MeleeWeaponUltratech" ParentName="BaseWeapon"> ``` - 定义一个 **抽象类**(不能直接使用,只能作为父类)。 - 继承自 `BaseWeapon`。 - 名为 `MeleeWeaponUltratech`,表示“高科技近战武器”基类。 --- ### 🔬 `<techLevel>Ultra</techLevel>` ```xml <techLevel>Ultra</techLevel> ``` - 该类武器属于“超科技等级”。 --- ### ⚙️ `<statBases>...</statBases>` ```xml <statBases> <MarketValue>2000</MarketValue> <Mass>2</Mass> </statBases> ``` - 基础属性: - 市场价值为 2000。 - 重量为 2。 --- ### 🧰 `<comps>...</comps>` ```xml <comps> <li><compClass>CompQuality</compClass></li> <li Class="CompProperties_Art"> <nameMaker>NamerArtWeaponMelee</nameMaker> <descriptionMaker>ArtDescription_WeaponMelee</descriptionMaker> <minQualityForArtistic>Excellent</minQualityForArtistic> </li> <li Class="CompProperties_Biocodable"/> </comps> ``` - **组件系统**: - `CompQuality`:支持品质系统。 - `CompProperties_Art`:支持艺术属性(如名称和描述可随机生成)。 - `CompProperties_Biocodable`:支持生物编码(用于机械体)。 --- ### 🔥 `<burnableByRecipe>true</burnableByRecipe>` ```xml <burnableByRecipe>true</burnableByRecipe> ``` - 可以通过配方燃烧。 --- ### 🗺️ `<smeltable>true</smeltable>` ```xml <smeltable>true</smeltable> ``` - 可以熔炼。 --- ### 📁 `<thingCategories>...</thingCategories>` ```xml <thingCategories> <li>WeaponsMelee</li> </thingCategories> ``` - 属于“近战武器”分类。 --- ### 🧱 `<weaponTags>...</weaponTags>` ```xml <weaponTags> <li>UltratechMelee</li> </weaponTags> ``` - 武器标签,用于 AI 和派系识别。 --- ### 🛒 `<tradeTags>...</tradeTags>` ```xml <tradeTags> <li>WeaponMelee</li> </tradeTags> ``` - 贸易标签,用于市场交易系统。 --- ### 🧱 `<weaponClasses>...</weaponClasses>` ```xml <weaponClasses> <li>Melee</li> <li>Ultratech</li> </weaponClasses> ``` - 表示该武器属于“近战”和“高科技”类别。 --- ### 🎁 `<thingSetMakerTags>...</thingSetMakerTags>` ```xml <thingSetMakerTags> <li>RewardStandardMidFreq</li> </thingSetMakerTags> ``` - 用于物品生成器(如奖励系统)。 --- ## 🔥 `<ThingDef ParentName="MeleeWeaponUltratech">` — PlasmaSword(等离子剑) - 继承自 `MeleeWeaponUltratech`。 - 一把高科技等离子剑。 --- ### 🏷️ `<defName>MeleeWeapon_PlasmaSword</defName>` ```xml <defName>MeleeWeapon_PlasmaSword</defName> ``` - 唯一标识符。 --- ### 🏷️ `<label>plasmasword</label>` ```xml <label>plasmasword</label> ``` - 显示名称。 --- ### 📄 `<description>...</description>` ```xml <description>A metal-cored sword with a cutting edge. Plasma is wrapped around the core...</description> ``` - 描述该武器的功能和特性。 --- ### 🔊 `<soundInteract>Interact_PlasmaSword</soundInteract>` ```xml <soundInteract>Interact_PlasmaSword</soundInteract> ``` - 拾取或交互时播放的声音。 --- ### 🔊 `<meleeHitSound>MeleeHit_PlasmaSword</meleeHitSound>` ```xml <meleeHitSound>MeleeHit_PlasmaSword</meleeHitSound> ``` - 攻击命中时播放的声音。 --- ### 🧭 `<equippedAngleOffset>-65</equippedAngleOffset>` ```xml <equippedAngleOffset>-65</equippedAngleOffset> ``` - 角色装备时的角度偏移。 --- ### 🎁 `<relicChance>3</relicChance>` ```xml <relicChance>3</relicChance> ``` - 有 3% 的几率作为“遗物”出现。 --- ### 🔒 `<smeltable>false</smeltable>` ```xml <smeltable>false</smeltable> ``` - 不可熔炼。 --- ### 🧱 `<weaponClasses>...</weaponClasses>` ```xml <weaponClasses> <li>MeleePiercer</li> </weaponClasses> ``` - 属于“穿刺型近战武器”。 --- ### 🖼️ `<graphicData>...</graphicData>` ```xml <graphicData> <texPath>Things/Item/Equipment/WeaponMelee/PlasmaSword</texPath> <graphicClass>Graphic_Single</graphicClass> </graphicData> ``` - 图像资源路径和图像类。 --- ### ⚔️ `<tools>...</tools>` ```xml <tools> <li>...</li> </tools> ``` - 定义攻击组件: - `handle`:钝击。 - `point`:刺击,附加火焰伤害。 - `edge`:切割,附加火焰伤害。 --- ### 🔥 `<extraMeleeDamages>...</extraMeleeDamages>` ```xml <extraMeleeDamages> <li> <def>Flame</def> <amount>10</amount> <chance>0.5</chance> </li> </extraMeleeDamages> ``` - 有 50% 概率附加 10 点火焰伤害。 --- ## ✅ 总结表格 | 属性 | 含义 | 示例值 | |------|------|--------| | `Abstract` | 是否为抽象类 | true | | `defName` | 唯一标识符 | MeleeWeapon_PlasmaSword | | `label` | 显示名称 | plasmasword | | `description` | 描述文本 | A metal-cored sword... | | `graphicData` | 图像资源 | Graphic_Single | | `techLevel` | 技术等级 | Ultra | | `statBases` | 基础属性(市场价值、重量) | MarketValue=2000, Mass=2 | | `comps` | 组件系统 | CompQuality, CompProperties_Art | | `burnableByRecipe` | 是否可燃烧 | true | | `smeltable` | 是否可熔炼 | false | | `weaponTags` | 武器分类 | UltratechMelee | | `tools` | 攻击组件 | Blunt, Cut, Stab | | `extraMeleeDamages` | 额外伤害 | Flame | | `relicChance` | 遗物几率 | 3 | --- ##
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值