2010-10-21 217 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數據。

這就是說,我想問題來自你的第二類沒有提供一個明確的無參數構造函數。