2010-10-21 182 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

首先在此代码中的错误:在第二类的构造函数将不会被使用。将参数传递到另一个活动的方式是在代码中调用其他活动,并在你的其他活动使用Intent.putExtra使用

Bundle extras = getIntent().getExtras(); 
if(extras !=null) 
{ 
    String value = extras.getString("keyName"); 
} 

获得在onCreate数据。

这就是说,我想问题来自你的第二类没有提供一个明确的无参数构造函数。