gpt4 book ai didi

java - 使用 nline.setText ("\n"附加新行时应用程序崩溃)

转载 作者:行者123 更新时间:2023-12-01 23:36:40 25 4
gpt4 key购买 nike

我想在我的应用程序的 TextView 中附加新行:

我使用了这段代码

textView.setText("part 1");
TextView nline = null;
nline.setText(" \n");
textView.setText("part 2");

当我转到实现此功能的页面时,我的应用程序崩溃了。

最佳答案

App crashing when appending a new line

因为你的nline为空并且你得到NullPointerException

TextView nline = null;// Check here nline is null
nline.setText(" \n"); // and your using null nline here which is causing NPE

确定你想做什么!我假设您需要新行黑白第 1 部分和第 2 部分

如果是这样,那么你可以简单地使用

textView.setText("part 1 \n part 2");

关于java - 使用 nline.setText ("\n"附加新行时应用程序崩溃),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18565559/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com