访问与对象数组 [英] accessing array with object

查看:231
本文介绍了访问与对象数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我有两个班在Android和在同一个类我有写一个数组,我想访问主类,但错误的是给我说:强制关闭这里是我的code

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

和第二类code是

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

请任何一个可以告诉什么以及在此code thaks误差

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

推荐答案

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

First of all: the constructor in your second class would not be used. The way to pass parameters to another activity is to use Intent.putExtra in the code calling the other activity and in your other activity use

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

要获得的onCreate 数据。

这是说,我想从你的第二个类没有提供一个明确的参数的构造函数的问题出现了。

That said, I guess the problem arises from your second class not providing an explicit parameterless constructor.

这篇关于访问与对象数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆