使用object访问数组

时间:2010-10-21 13:10:01

标签: android

嗨,我在android中有两个类,在一个类中,我已经编写了一个数组,我想在主类中访问它,但错误是给我“强制关闭”这里是我的代码

package com.semanticnotion.DAO;


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class DAO extends Activity {

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

WordsDAO DAO = new WordsDAO(new String[]{"Arte","Arquitectura","Familia","Moda","Cotilleos","Cine","Libros","Historia","Pintura","Musica","Tendencies","Modernimso","Pop art","Masteialismo","realities","filosofia","moda","fotografia","religion"});


Button next = (Button) findViewById(R.id.Button01);
next.setOnClickListener(new View.OnClickListener() {
    public void onClick(View view) {
        Intent myIntent = new Intent(view.getContext(), WordsDAO.class);

        startActivity(myIntent);
        }
    });
    }
}

,第二类代码是

package com.semanticnotion.DAO;

public class WordsDAO  {


 String[] words = new String[]{"Arte","Arquitectura","Familia","Moda","Cotilleos","Cine","Libros","Historia","Pintura","Musica","Tendencies","Modernimso","Pop art","Masteialismo","realities","filosofia","moda","fotografia","religion"};




 public  WordsDAO(String[] words ) {
  this.words=words;
   }

请任何人告诉这段代码中的错误是什么

1 个答案:

答案 0 :(得分:1)

错误可能在这里:

Intent myIntent = new Intent(view.getContext(), WordsDAO.class);

(您应该发布错误跟踪)

Intent构造函数需要一个Component(Activity)类作为第二个参数。不允许任意类。

最简单的方法是使用putExtra。您可以使用此方法传递CharSequence数组,然后使用getCharSequenceArrayExtra检索它。