如何修复以下错误:无法调用'string.length()"因为“ this.inputstr”是无效的
/* Returns the count of the user's character. */
public int getUserCharCount(){
inputStr = inputStr;
for (int i = 0; i < inputStr.length(); i++) {
if (inputStr.charAt(i) == userChar) {
userCharCount ++;
}
}
return userCharCount;
}
默认情况下,Inputstr在主代码中为“”。它应该更新给用户输入。
/* Returns the count of the user's character. */
public int getUserCharCount(){
inputStr = inputStr;
for (int i = 0; i < inputStr.length(); i++) {
if (inputStr.charAt(i) == userChar) {
userCharCount ++;
}
}
return userCharCount;
}
By default, inputStr is "" in the Main code. It should be updating to the user input.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以记录Inputstr
也许用户将其设置为null。
另外,您可以在操作前检查您的变量是否为null。
很难说出了什么问题,因为您不提供容纳您的变量的类,而不是提供创建和修改的类别的方式。
可能是您使用null创建新的,可能是用户更改为null的值
You can log inputStr
maybe user set it to null.
also you may check if your variable is null before action.
It hard to say what wrong because you not provide class that hold your variable, and not provide way that class are created and modified.
may be you create new one with null, may be user change value to null