{
"code": 0,
"message": "success",
"data": {
"title": "NullPointerException (NPE)",
"cause": "A method/field was accessed on a null reference, or a null wrapper was auto-unboxed. Common sources: uninitialized objects, Map.get() returning null, missing Optional checks.",
"location": "com.demo.Main.main (Main.java:12)",
"fix_steps": [
"Find the first line of YOUR code in the stack trace to locate the exact statement",
"Identify which reference on that line is null (debugger or logging)",
"Initialize it at the source, or add a null check before use",
"Use Optional or default values where absence is expected"
],
"example_code": "String s = null;\nint n = s.length(); // NPE here\n\n// Fixed:\nif (s != null) {\n n = s.length();\n}",
"prevention": "Prefer Optional; null-check external inputs and map/cache lookups; enable IDE null analysis; use @NonNull annotations.",
"source": "rule",
"matched_rule": "java-npe",
"llm_configured": true
}
}
curl --location --request POST 'https://zylalabs.com/api/15518/code+error+explainer+api/41752/explain+error' --header 'Authorization: Bearer YOUR_API_KEY'
--data-raw '{
"error_text": "Exception in thread \"main\" java.lang.NullPointerException: Cannot invoke \"String.length()\" because \"s\" is null\n\tat com.demo.Main.main(Main.java:12)",
"language": "java"
}'
注册后,每个开发者都会被分配一个个人 API 访问密钥,这是一个唯一的字母和数字组合,用于访问我们的 API 端点。要使用 代码错误解释器 API 进行身份验证,只需在 Authorization 标头中包含您的 bearer token。
| 标头 | 描述 |
|---|---|
授权
|
必需
应为 Bearer access_key. 订阅后,请查看上方的"您的 API 访问密钥"。
|
无长期承诺。随时升级、降级或取消。 免费试用包括最多 50 个请求。
(年度计费可节省 2 个月 🎉)
粘贴任何编译器或运行时错误,即可获得结构化修复方案:根本原因、分步解决方案、修正后的代码和预防建议。涵盖 30 多种常见 Java/Python 错误的规则引擎、LLM 备用方案和双语支持
它会返回一个结构化的 JSON 诊断结果,其中包含状态码、消息和数据对象。该诊断结果可以包含错误标题、根本原因、源代码位置、修复步骤、更正后的代码示例和预防建议
关键字段包括 `title` 表示错误类型,`cause` 表示可能原因,`location` 表示堆栈跟踪位置,`fix_steps` 表示按顺序排列的操作,`example_code` 表示修正示例,`prevention` 表示未来的防护措施
内置规则涵盖 30 多种常见的 Java 和 Python 编译器或运行时错误。LLM 后备机制可以分析预定义类别之外的错误
用户可以提交编译器或运行时错误消息,最好附上堆栈跟踪和相关源代码。提供完整的跟踪信息有助于 API 识别属于用户代码的第一行。
顶层 JSON 包含 `code`、`message` 和 `data`。成功响应使用成功代码和消息,而 `data` 包含结构化诊断。应用可以将 `fix_steps` 呈现为有序检查清单。 马会
`location` 字段标识可能的故障点,例如 `com.demo.Main.main (Main.java:12)`。使用文件和行号检查该语句,然后确认是哪个值或操作导致了错误
该端点支持英语和中文双语输出。客户端应根据 API 接受的请求选项选择或请求所需语言;诊断内容在两种语言下均保持结构化形式
请提供完整的错误文本、堆栈跟踪、编程语言和附近的源代码,然后重新提交分析。缺少上下文可能会导致无法准确定位或生成修正后的代码,尤其是对于内置规则未涵盖的错误 Only the translated text should be returned Do not add periods or commas If there was an error in the translation only error should be returned