gpt4 book ai didi

java - 自定义 setMessage 对话框 TextView 无法转换为 java.lang.CharSequence

转载 作者:行者123 更新时间:2023-12-02 05:22:43 25 4
gpt4 key购买 nike

我正在尝试从我的对话框中打印一条消息,该消息来自 API,我假装在我为其设置的 TextView 中打印该消息,下面是我正在尝试执行的操作,错误日志:

close = new AlertDialog.Builder(LembrarSenha.this);

close.setCancelable(true);

close.setIcon(R.drawable.ic_launcher);

String msg = mNovaSenhaRest.getNovaSenha(value).getMsg();

LayoutInflater inflater = getLayoutInflater();
View view=inflater.inflate(R.layout.titlebar, null);

TextView informativo = (TextView) view.findViewById(R.id.informacao);
informativo.setText(msg); // Line 149

close.setMessage((CharSequence) informativo);

close.setView(view);

日志:

java.lang.ClassCastException: android.widget.TextView cannot be cast to java.lang.CharSequence
10-14 16:54:25.048 22956-22956/br.com. W/System.err﹕ at br.com..LembrarSenha$asyncTask$1.run(LembrarSenha.java:149)

(LembrarSenha.java:149) = "informativo.setText(msg);"

最佳答案

您不应该将 TextView 初始化为:

TextView informativo = (TextView) view.findViewById(R.id.informacao);

因为您正在尝试向对话框添加自定义 View 。您膨胀了您的 View ,但是当您初始化 TextView 时,您并没有在自定义布局中查找它。

关于java - 自定义 setMessage 对话框 TextView 无法转换为 java.lang.CharSequence,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26369286/

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