0

hi i have two classes in android and in one class i have write an array and i want to access it in the main class but the error is give me that "force closed" here is my code

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);
        }
    });
    }
}

and the second class code is

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;
   }

please any one tell what well be the error in this code thaks

1

1 Answer 1

1

The error is probably here:

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

(You should post the error trace)

The Intent constructor expects a Component (Activity) class as the second argument. An arbitrary class isn't allowed.

The easiest way to do what you want is to use putExtra. You can pass a CharSequence array with this method and then retrieve it with getCharSequenceArrayExtra.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.