2010-10-21 145 views
0

嗨我有两个类在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; 
    } 

请任何一个可以告诉什么以及在此代码中的错误thaks

+0

这是一个确切的重复http://stackoverflow.com/questions/3987349/accessing-array-with-object?不要这样做。 – 2010-10-21 13:43:01

回答

1

该错误可能是在这里:

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

(你应该张贴的错误跟踪)

意图构造函数需要一个组件(活动)类作为第二个参数。一个任意的类是不允许的。

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