- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想做的就是引用存储在 xml 文件中的字符串,然后在数组中使用相同的字符串。这是在非 Activity 类 MyDataProvider 中发生的,如下所示。问题是,当我在屏幕上显示字符串时,我的引用字符串只显示单词“null”。据我所知,我已经正确引用了它们,但它们不会返回 null。我确信这是一个愚蠢的错误,但我对 Android 还是个新手,非常感谢您的帮助。
我的数据提供者:
package com.gmd.referenceapplication;
import android.content.Context;
import java.util.HashMap;
import java.util.Map;
public class MyDataProvider {
Context context;
String test; //string variable
//constructor for class MyDataProvider
public MyDataProvider(Context context1){
context=context1;
test = context.getString(R.string.app_name);//tester string is assigned
putInCommonMap();
putInElectromagneticMap();
}
//strings for sub and superscript
//data for common constants
ListViewItem constant_common_data[] = new ListViewItem[]
{
new ListViewItem(R.drawable.star, "Atomic Mass Constant " +test, "1.660 539 040 e-27", "kg", "0.000 000 020 e-27"),//test string is used, shows up as word "null" on display
new ListViewItem(R.drawable.star, "Avogadro Constant", "6.022 140 857 e23"," mol^-1", "0.000 000 074 x e23"),
new ListViewItem(R.drawable.star, "Boltzmann Constant", "1.380 648 52 e-23", "K^-1", "0.000 000 79 e-23"),
new ListViewItem(R.drawable.star, "Conductance Quantum", "7.748 091 7310 e-5", "s","0.000 000 0018 e-5"),
new ListViewItem(R.drawable.star, "Electric Constant", "8.854 187 817... e-12", "F m^-1", "(exact)"),
new ListViewItem(R.drawable.star, "Electron mass", "9.109 383 56 e-31", "kg", "0.000 000 11 e-31"),
new ListViewItem(R.drawable.star, "Electron volt", "1.602 176 6208 e-19"," J", "0.000 000 0098 e-19"),
new ListViewItem(R.drawable.star, "Elementary charge ", "1.602 176 6208 e-19", "C", "0.000 000 0098 e-19"),
new ListViewItem(R.drawable.star, "Faraday constant ", "96 485.332 89 e-5", "C mol^-1", "0.000 59"),
new ListViewItem(R.drawable.star, "Fine-structure constant ", "7.297 352 5664 e-3", " ", "0.000 000 0017 e-3"),
new ListViewItem(R.drawable.star, "Inverse fine-structure constant", "137.035 999 139", " ", "0.000 000 031"),
new ListViewItem(R.drawable.star, "Magnetic constant", "4pi e-7 = 12.566 370 614... e-7"," N A^-2", "(exact)"),
new ListViewItem(R.drawable.star, "Magnetic Flux Quantum", "2.067 833 831 e-15", "Wb", "0.000 000 013 e-15"),
new ListViewItem(R.drawable.star, "Molar Gas constant", "8.314 4598", "J mol^-1 K^-1", "0.000 0048"),
new ListViewItem(R.drawable.star, "Newtonian constant of gravitation ", "6.674 08 e-11", "m^3 kg^-1 s^-2", "0.000 31 e-11"),
new ListViewItem(R.drawable.star, "Planck constant", "6.626 070 040 e-34", "J s", "0.000 000 081 e-34"),
new ListViewItem(R.drawable.star, "Planck constant over 2 pi", "1.054 571 800 e-34"," J s", "0.000 000 013 e-34"),
new ListViewItem(R.drawable.star, "Proton Mass", "1.672 621 898 e-27", "kg", "0.000 000 021 e-27"),
new ListViewItem(R.drawable.star, "Proton-Electron Mass Ratio", "1836.152 673 89", " ", "0.000 000 17"),
new ListViewItem(R.drawable.star, "Rydberg constant", "10 973 731.568 508", "m^-1", "0.000 065"),
new ListViewItem(R.drawable.star, "Speed of Light in Vacuum", "299 792 458", "m s^-1", "(exact)"),
new ListViewItem(R.drawable.star, "Stefan-Boltzmann constant", "5.670 367 e-8", "Wm^-2 K^-4", "0.000 013 e-8"),
new ListViewItem(R.drawable.star, "Bohr Radius", "0.529 177 210 67 e-10", "m", "0.000 000 000 12 e-10"),
new ListViewItem(R.drawable.star, "Bohr Magneton ", "927.400 9994 e-26"," J T^-1", "0.000 0057 e-26"),
new ListViewItem(R.drawable.star, "Josephson constant", "483 597.8525 e9", "Hz V^-1", "0.0030 e9"),
new ListViewItem(R.drawable.star, "Von Klitzing constant", "25 812.807 4555", "Ohm", "0.000 0059"),
new ListViewItem(R.drawable.star, "Unified Atomic Mass Unit", "1.660 539 040 e-27"+ test , "kg", "0.000 000 020 e-27")
};
HashMap<String,ListViewItem> commonMap = new HashMap<String, ListViewItem>();
//data entry for electromagnetic constants
ListViewItem constant_electromagnetic_data[] = new ListViewItem[]
{
new ListViewItem(R.drawable.star, "Bohr Magneton ", "927.400 9994 e-26"," J T^-1", "0.000 0057 e-26"),
new ListViewItem(R.drawable.star, "Bohr magneton in (eV)/T", "5.788 381 8012 e-5", "(eV)/T", "0.000 000 0026 e-5"),
new ListViewItem(R.drawable.star, "Bohr magneton in Hz/T", "13.996 245 042 e9"," Hz T^-1", "0.000 000 086 e9"),
new ListViewItem(R.drawable.star, "Bohr magneton in inverse meters per tesla", "46.686 448 14", "m^-1 T^-1", "0.000 000 29"),
new ListViewItem(R.drawable.star, "Bohr magneton in K/T", "0.671 714 05", "K T^-1","0.000 000 39"),
new ListViewItem(R.drawable.star, "Conductance Quantum", "7.748 091 7310 e-5", "s","0.000 000 0018 e-5"),
new ListViewItem(R.drawable.star, "Elementary charge ", "1.602 176 6208 e-19", "C", "0.000 000 0098 e-19"),
new ListViewItem(R.drawable.star, "Electron volt", "1.602 176 6208 e-19"," J", "0.000 000 0098 e-19"),
new ListViewItem(R.drawable.star, "Elementary charge ", "1.602 176 6208 e-19", "C", "0.000 000 0098 e-19"),
new ListViewItem(R.drawable.star, "elementary charge over h", "2.417 989 262 e14", "A J^-1", "0.000 000 015 e14"),
new ListViewItem(R.drawable.star, "inverse of conductance quantum", "12 906.403 7278", "Ohms", "0.000 0029"),
new ListViewItem(R.drawable.star, "Josephson constant", "483 597.8525 e9", "Hz V^-1", "0.0030 e9"),
new ListViewItem(R.drawable.star, "Magnetic Flux Quantum", "2.067 833 831 e-15", "Wb", "0.000 000 013 e-15"),
new ListViewItem(R.drawable.star, "nuclear magneton", "5.050 783 699 e-27", "J T^-1", "0.000 000 031 e-27"),
new ListViewItem(R.drawable.star, "nuclear magneton in (eV)/T ", "3.152 451 2550 e-8", "(eV)/T", "0.000 000 0015 e-8"),
new ListViewItem(R.drawable.star, "nuclear magneton in inverse meters per tesla", "2.542 623 432 e-2", "m^-1 T^-1", "0.000 000 016 e-2"),
new ListViewItem(R.drawable.star, "nuclear magneton in K/T", "3.658 2690 e-4","K T^-1", "0.000 0021"),
new ListViewItem(R.drawable.star, "nuclear magneton in MHz/T ", "7.622 593 285", "MHz T^-1", "0.000 000 047"),
new ListViewItem(R.drawable.star, "Von Klitzing constant", "25 812.807 4555", "Ohm", "0.000 0059")
};
HashMap<String,ListViewItem> electromagneticMap = new HashMap<String, ListViewItem>();
//data entry for Atomic and nuclear constants :(
ListViewItem constant_atomic_data[] = new ListViewItem[]
{
new ListViewItem(R.drawable.star, "alpha particle mass", "6.644 657 230 e-27"," kg", "0.000 000 082 e-27"),
new ListViewItem(R.drawable.star, "alpha particle mass energy equivalent", "5.971 920 097 e-10", "J", "0.000 000 073 e-10"),
new ListViewItem(R.drawable.star, "alpha particle mass energy equivalent in MeV ", "3727.379 378"," MeV", "0.000 023"),
new ListViewItem(R.drawable.star, "alpha particle mass in u", "4.001 506 179 127", "u", "0.000 000 000 063"),
new ListViewItem(R.drawable.star, "alpha particle molar mass", "4.001 506 179 127 e-3", "mol^-1","0.000 000 000 063 e-3"),
new ListViewItem(R.drawable.star, "alpha particle-electron mass ratio", "7294.299 541 36", "(none)","0.000 000 24"),
new ListViewItem(R.drawable.star, "alpha particle-proton mass ratio ", "3.972 599 689 07", "(none)", "0.000 000 000 36"),
new ListViewItem(R.drawable.star, "Bohr Radius", "0.529 177 210 67 e-10", "m", "0.000 000 000 12 e-10"),
new ListViewItem(R.drawable.star, "classical electron radius", "2.817 940 3227 e-15","m", "0.000 000 0019 e-15"),
new ListViewItem(R.drawable.star, "Compton wavelength", "2.426 310 2367 e-12", "m", "0.000 000 0011 e-12"),
new ListViewItem(R.drawable.star, "Compton wavelength over 2 pi", "386.159 267 64 e-15", "m", "0.000 000 18 e-15"),
new ListViewItem(R.drawable.star, "deuteron g factor ", "0.857 438 2311", "(none)", "0.000 000 0048"),
new ListViewItem(R.drawable.star, "deuteron magnetic moment ", "0.433 073 5040 e-26", "J T^-1", "0.000 000 0036 e-26"),
new ListViewItem(R.drawable.star, "deuteron magnetic moment to Bohr magneton ratio ", "0.466 975 4554 e-3", "(none)", "0.000 000 0026 e-3"),
new ListViewItem(R.drawable.star, "deuteron magnetic moment to nuclear magneton ratio", "0.857 438 2311", "(none)", "0.000 000 0048"),
new ListViewItem(R.drawable.star, "deuteron mass ", "3.343 583 719 e-27", "kg", "0.000 000 041 e-27"),
new ListViewItem(R.drawable.star, "deuteron mass energy equivalent ", "3.005 063 183 e-10", "J", "0.000 000 037 e-10"),
new ListViewItem(R.drawable.star, "deuteron mass energy equivalent in MeV", " 1875.612 928","MeV", "0.000 012"),
new ListViewItem(R.drawable.star, "deuteron mass in u", "2.013 553 212 745", "u", "0.000 000 000 040"),
new ListViewItem(R.drawable.star, "deuteron molar mass", "2.013 553 212 745 e-3", "kg mol ^-1", "0.000 000 000 040 e-3"),
//resume data entry here
new ListViewItem(R.drawable.star, "deuteron rms charge radius", "2.1413 e-15","m", "0.0025 e-15"),
new ListViewItem(R.drawable.star, "deuteron-electron magnetic moment ratio", "-4.664 345 535 e-4", "(none)", "0.000 000 026 e-4"),
new ListViewItem(R.drawable.star, "deuteron-electron mass ratio", "3670.482 967 85","(none)", "0.000 000 13"),
new ListViewItem(R.drawable.star, "deuteron-neutron magnetic moment ratio", "-0.448 206 52", "(none)", "0.000 000 11"),
new ListViewItem(R.drawable.star, "deuteron-proton magnetic moment ratio", "0.307 012 2077", "(none)","0.000 000 0015"),
new ListViewItem(R.drawable.star, "deuteron-proton mass ratio", "1.999 007 500 87", "(none)","0.000 000 000 19"),
new ListViewItem(R.drawable.star, "electron charge to mass quotient", "-1.758 820 024 e11", "C kg^-1", "0.000 000 011 e11"),
new ListViewItem(R.drawable.star, "electron g factor ", "-2.002 319 304 361 82","(none)", "0.000 000 000 000 52"),
new ListViewItem(R.drawable.star, "Elementary charge ", "1.602 176 6208 e-19", "C", "0.000 000 0098 e-19"),
new ListViewItem(R.drawable.star, "elementary charge over h", "2.417 989 262 e14", "A J^-1", "0.000 000 015 e14"),
new ListViewItem(R.drawable.star, "inverse of conductance quantum", "12 906.403 7278", "Ohms", "0.000 0029"),
new ListViewItem(R.drawable.star, "Josephson constant", "483 597.8525 e9", "Hz V^-1", "0.0030 e9"),
new ListViewItem(R.drawable.star, "Magnetic Flux Quantum", "2.067 833 831 e-15", "Wb", "0.000 000 013 e-15"),
new ListViewItem(R.drawable.star, "nuclear magneton", "5.050 783 699 e-27", "J T^-1", "0.000 000 031 e-27"),
new ListViewItem(R.drawable.star, "nuclear magneton in (eV)/T ", "3.152 451 2550 e-8", "(eV)/T", "0.000 000 0015 e-8"),
new ListViewItem(R.drawable.star, "nuclear magneton in inverse meters per tesla", "2.542 623 432 e-2", "m^-1 T^-1", "0.000 000 016 e-2"),
new ListViewItem(R.drawable.star, "nuclear magneton in K/T", "3.658 2690 e-4","K T^-1", "0.000 0021"),
new ListViewItem(R.drawable.star, "nuclear magneton in MHz/T ", "7.622 593 285", "MHz T^-1", "0.000 000 047"),
new ListViewItem(R.drawable.star, "Von Klitzing constant", "25 812.807 4555", "Ohm", "0.000 0059")
};
HashMap<String,ListViewItem> AtomicMap = new HashMap<String, ListViewItem>();
//enters all data in common array into the common HashMap
public void putInCommonMap(){
for(ListViewItem i : constant_common_data) commonMap.put(i.getKey(),i);
}
public void putInElectromagneticMap(){
for(ListViewItem i : constant_electromagnetic_data) electromagneticMap.put(i.getKey(),i);
}
//returns common hashmap
public HashMap getCommonMap(){
return commonMap;
}
//returns electromagnetic HashMap
public HashMap getElectromagneticMap(){
return electromagneticMap;
}
}
字符串 xml:
<resources>
<string name="app_name">Reference Application</string>
<string name="search_hint">Search constants, rules, and properties of water </string>
<string name="to_2"><![CDATA[ m<sup><small>-2]></small></sup> </string>
<string name="E_mc2">E=mc<sup><small>2</small></sup></string>
<string name="welcome">Welcome to <b>Android</b>!</string>
</resources>
谢谢大家!
最佳答案
在构造函数中初始化您的项目,如下所示。
public class MyDataProvider {
Context context;
String test; //string variable
ListViewItem constant_common_data[];
//constructor for class MyDataProvider
public MyDataProvider(Context context1){
context=context1;
test = context.getString(R.string.app_name);//tester string is assigned
init_constant_common_data();
putInCommonMap();
putInElectromagneticMap();
}
//strings for sub and superscript
//data for common constants
private void init_constant_common_data(){
constant_common_data = new ListViewItem[]
{
new ListViewItem(R.drawable.star, "Atomic Mass Constant " +test, "1.660 539 040 e-27", "kg", "0.000 000 020 e-27"),//test string is used, shows up as word "null" on display
new ListViewItem(R.drawable.star, "Avogadro Constant", "6.022 140 857 e23"," mol^-1", "0.000 000 074 x e23"),
new ListViewItem(R.drawable.star, "Boltzmann Constant", "1.380 648 52 e-23", "K^-1", "0.000 000 79 e-23"),
new ListViewItem(R.drawable.star, "Conductance Quantum", "7.748 091 7310 e-5", "s","0.000 000 0018 e-5"),
new ListViewItem(R.....
....
..
..
}
关于java - 返回字 "null"的字符串引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37869629/
我正在维护一些 Java 代码,我目前正在将它们转换为 C#。 Java 代码是这样做的: sendString(somedata + '\000'); 在 C# 中,我正在尝试做同样的事情: sen
如何确定函数中传递的参数是字符串还是字符(不确定如何正确调用它)文字? 我的函数(不正确): void check(const char* str) { // some code here }
我真的不知道如何准确地提出这个问题,但我希望标题已经说明了这一点。 我正在寻找一种方法(一个框架/库),它提供了执行 String.contains() 函数的能力,该函数告诉我给定的字符串是否与搜索
我正在尝试编写一些读取 Lambda 表达式并输出 beta 缩减版本的东西。 Lambda 的类型如下:\variable -> expression,应用程序的形式为 (表达式) (表达式)。因此
StackOverflow 上的第 1 篇文章,如果我没能把它做好,我深表歉意。我陷入了一个愚蠢的练习,我需要制作一个“刽子手游戏”,我尝试从“.txt”文件中读取单词,然后我得到了我的加密函数,它将
我想在 Groovy 中测试我的 Java 自定义注释,但由于字符问题而未能成功。 Groovyc: Expected 'a' to be an inline constant of type cha
当我尝试在单击按钮期间运行 javascript location.href 时,出现以下错误“字 rune 字中的字符过多”。 最佳答案 这应该使用 OnClientClick相反? 您可能还想停
我想要类似的东西: let a = ["v".utf8[0], 1, 2] 我想到的最接近的是: let a = [0x76, 1, 2] 和 "v".data(using: String.Encod
有没有办法在 MySQL 中指定 Unicode 字 rune 字? 我想用 Ascii 字符替换 Unicode 字符,如下所示: Update MyTbl Set MyFld = Replace(
阅读 PNG 规范后,我有点惊讶。我读过字 rune 字应该用像 0x41 这样的二进制值进行硬编码,而不是在(程序员友好的)'A' 中。问题似乎是在具有不同底层字符集的不同系统上编译期间字 rune
考虑一个具有 UTF-8 执行字符集的 C++11 编译器(并且符合要求 char 类型为有符号 8 位字节的 x86-64 ABI) . 字母 Ä(元音变音)具有 0xC4 的 unicode 代码
为什么即使有 UTF-8 字符串文字,C11 或 C++11 中也没有 UTF-8 字 rune 字?我知道,一般来说,字 rune 字表示单个 ASCII 字符,它与单字节 UTF-8 代码点相同,
我怎样才能用 Jade 做到这一点? how would I do this 我几乎可以做任何事情,除了引入一个 span 中间句子。 最佳答案 h3.blur. how would I do t
这似乎是一个非常简单的问题,但我只是想澄清我的疑问。我正在查看其他开发人员编写的代码。有一些涉及 float 的计算。 示例:Float fNotAvlbl = new Float(-99); 他为什
我想知道第 3 行“if dec:”中的“dec”是什么意思 1 def dec2bin(dec): 2 result='' 3 if dec:
我试图在字符串中查找不包含任何“a”字符的单词。我写了下面的代码,但它不起作用。我怎么能对正则表达式说“不包括”?我不能用“^”符号表示“不是”吗? import re string2 = "asfd
这个问题在这里已经有了答案: Is floating point math broken? (31 个答案) Is floating point arbitrary precision availa
我正在创建一个时尚的文本应用程序,但在某些地方出现错误(“字 rune 字中的字符太多”)。我只写了一个字母,但是当我粘贴它时,它会转换成许多这样的字母:“\uD83C\uDD89”,原始字母是“🆉
我正在尝试检查用户是否在文本框中输入了一个数字值,是否接受了小数位。非常感谢任何帮助。 Private Sub textbox1_AfterUpdate() If IsNumeric(textbox1
我知道一个 Byte 是 8 位,但其他的代表什么?我正在参加一个使用摩托罗拉 68k 架构的汇编类(class),我对目前的词汇感到困惑。 最佳答案 如 operator's manual for
我是一名优秀的程序员,十分优秀!