- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试从我的对话框中打印一条消息,该消息来自 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/
场景 1: 我得到了 Set来自某处,这意味着我无法控制该集合的创建方式。 Set dataSet = GET_DATA_SET(); 我想转换 Set 中的数据至Set 。有没有一种有效的方法可以在
我一直认为 CharSequence[] 和 String[] 本质上是一样的,但是: 我有一些代码具有以下内容: CharSequence[] mEntries; ... String[] mEnt
存在类转换问题。请告诉我如何转换这个。我想要这个 ArrayList在我的 CharSequence[]名为 Contacts . java.lang.ClassCastException (在 An
setText(CharSequence, TextView.BufferType) 和 setText(CharSequence) 有什么区别,什么时候应该使用它们? 最佳答案 setText (C
虽然 String 实现了 CharSequence,但 Java 不允许这样做。做出此设计决定的原因是什么? 最佳答案 之所以禁止这样做是因为它不是类型安全的: public class MyEvi
我无法使用 API 26 更新应用。当我尝试运行项目时出现以下错误 错误: "ServerRunningNotification.java": error: cannot find symbol me
我有一个名为 customObjectList 的自定义对象列表。我想让它绑定(bind)到AlertDialog.Builder.setMultiChoiceItems(),需要先把它转换成Char
public void drawCities(ArrayList cities, Graphics page) { for(int i=0; i(TravelPanel.java:26) at
我需要显示一个对话框,其中包含可供选择的颜色列表。我找到了这个解决方案 here . CharSequence colors[] = new CharSequence[] {"red", "green
如何在Java中将String转换为CharSequence? 最佳答案 由于 String IS-A CharSequence,您可以在需要 的任何地方传递 String CharSequence,
我有一个 Map 并使用 转换为 charsequence[] final CharSequence[] treatmentNameList = treatmentListMap.keySet().t
我定义了以下CharSequence: final CharSequence[] videoQualities = {"any", "medium", "high", "hd"}; 我收到两个字符串值
为什么 String 类中的某些方法具有 CharSequence 类型的参数而其他方法具有 String 类型的参数,是否有逻辑解释? 例如: public String replace(CharS
这将返回一个空指针。 array[0].toString() 也是如此。我做错了什么? final CharSequence[] array = res.getTextArray(R.array.ar
我可以像这样组合两个 CharSequence 变量吗? if (status == 1) { for (int i = 0; i < get.length(); i++) {
有什么方法可以将 CharSequence 转换为 char 数组?为什么接口(interface)没有获取字符数组的方法? 最佳答案 我首先将 CharSequence 转换为 String 然后将
我有一个使用 charseqquence 的简单 Java 代码: static class baloon { CharSequence Titles[]; public
有这个代码: if (cs.equals(keywordUnderProcess)) { } else { } cs 和keywordUnderProcess 都是CharSequence,值为sta
CharSequence[] items = { “Google”, “Apple”, “Microsoft” }; 如果CharSequence是一个接口(interface),那么在上面的例子中我
我正在尝试遍历我的数组列表并打印无效的电子邮件地址。如果地址不包含@符号或句点,则无效。 我收到一个错误,int 无法转换为我的方法的 charsequence。 public static void
我是一名优秀的程序员,十分优秀!