English 中文(简体)
问题,从扼杀物中穿透。
原标题:problem filling string[] with string-array from strings.xml

EDIT: woah ... somehow i replaced this question with another one i was asking, glad there is this rollback feature

这一具体问题涉及从我的

public class Impacts extends Activity implements View.OnClickListener
{
    boolean[] impactsb = new boolean[] {false, false, false, false, false, false, false, false}-
    public void onCreate (Bundle savedInstanceState)
    {
    super.onCreate(savedInstanceState)
...

    String getImpacts ()
    {
    String[] impactsn = new String[length];
    Resources myResources = this.getResources();
    impactsn = myResources.getStringArray(R.array.impacts);
    StringBuilder impactss = new StringBuilder();
    for (int i = 0; i < length; i ++)
        {
        if (impactsb[i])
            impactss.append(impactsn[i] + " | ");
        }
    if (String.valueOf(impactss) != "")
        impactss.insert(0, "Impacts: ");
    return String.valueOf(impactss);
    }

(a) 具有这些错误之处:

Impacts(ContextWrapper).getResources() line: 80
Impacts.getImpacts() line: 78

the final bracket of the below code:

@Override
public Resources getResources()
{
    return mBase.getResources();
}

以及这一条码:

impactsn = getResources().getStringArray(R.array.impacts);

这里是我方言。

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string-array name="impacts">
        <item>GasOilChemical Pollutants</item>
        <item>Ghost Fishing</item>
        <item>Marsh Damage</item>
        <item>Navigational Hazard</item>
        <item>Shellfish Damage</item>
        <item>Waste Pollution</item>
        <item>Wildlife Entanglement</item>
        <item>Other</item>
    </string-array>
</resources>

i 最初的项目为:

<item>Gas/Oil/Chemical Pollutants</item>

但确定,如果不解决问题,至少会改变错误。 但是,没有错误。 任何帮助都会受到广泛赞赏,不十分熟悉阵列的使用,特别是为阵列提供资源。

例外:

06-05 23:02:30.792: ERROR/AndroidRuntime(3905): FATAL EXCEPTION: main
06-05 23:02:30.792: ERROR/AndroidRuntime(3905): java.lang.NullPointerException
06-05 23:02:30.792: ERROR/AndroidRuntime(3905): at android.content.ContextWrapper.getResources(ContextWrapper.java:80)
06-05 23:02:30.792: ERROR/AndroidRuntime(3905): at com.citsci.mardeb.Impacts.getImpacts(Impacts.java:79)
最佳回答

i 知道,这是不好的编码,是预发的道歉。 为了解决这个问题,一举

String[] impactsn;
impactsn = getResources().getStringArray(R.array.impacts);

对我的主要活动来说,这只是一个静态。 我现在在我的影响类别中把它称为(MainActative)。

i 知道这并不是你应如何在课堂之间分享物体,但看来是迄今为止最容易的方法。 这是我为什么对我决定整整整整项活动感到遗憾的另一个原因。 如果您对如何在不使用静态参考资料的情况下确定该守则,或出于我所有表格都应是同一活动的原因,请chim。

问题回答

建议不预先确定一个阵列,而直接使用,而不界定一个变量

mAutoComplete.setAdapter (new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, getResources().getStringArray(R.array.OmskStreets)));

并且更多。

班级

private String[] mStreets = null;

A. 方法

mStreets = getResources().getStringArray(R.array.OmskStreets);

不应在Create(Create)上界定任何关于“国际调查”的定义。

此外,下面是个不好的编码例子,但它运作良好。

public void onCreate(Bundle icicle){
     super.onCreate(icicle);
...
...
...
     COUNTRIES  = getResources().getStringArray(R.array.COUNTRIES_ARRAY);




相关问题
Simple JAVA: Password Verifier problem

I have a simple problem that says: A password for xyz corporation is supposed to be 6 characters long and made up of a combination of letters and digits. Write a program fragment to read in a string ...

Case insensitive comparison of strings in shell script

The == operator is used to compare two strings in shell script. However, I want to compare two strings ignoring case, how can it be done? Is there any standard command for this?

Trying to split by two delimiters and it doesn t work - C

I wrote below code to readin line by line from stdin ex. city=Boston;city=New York;city=Chicago and then split each line by ; delimiter and print each record. Then in yet another loop I try to ...

String initialization with pair of iterators

I m trying to initialize string with iterators and something like this works: ifstream fin("tmp.txt"); istream_iterator<char> in_i(fin), eos; //here eos is 1 over the end string s(in_i, ...

break a string in parts

I have a string "pc1|pc2|pc3|" I want to get each word on different line like: pc1 pc2 pc3 I need to do this in C#... any suggestions??

Quick padding of a string in Delphi

I was trying to speed up a certain routine in an application, and my profiler, AQTime, identified one method in particular as a bottleneck. The method has been with us for years, and is part of a "...