2

我有个问题。我有这个可打包的课程:

public class parametros implements Parcelable {

private String n="";
private String id="";

private  String[] e1= {"0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"};
private  String[] e2= {"0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"};
private  String[] e3= {"0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"};
private  String[] e4= {"0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"};
private  String[] e5= {"0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"};
private  String[] e6= {"0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"};
private  String[] e7= {"99","99","99","99","99","99","99","99","99","99","99","99","99","99","99","99","99","99","99","99"};

public parametros() {}


///////// SET/////////
public void setId(String i)
{
    id = i;
}

public void setN(String no)
{
    n = no;
}

public void sete1(String dir, int pos)
{
    e1[pos] = dir;
}

public void sete2(String mar, int pos)
{
    e2[pos] = mar;
}

public void sete3(String mar, int pos)
{
    e3[pos] = mar;
}

public void sete4(String mar, int pos)
{
    e4[pos] = mar;
}

public void sete5(String dir, int pos)
{
    e5[pos] = dir;
}

public void sete6(String per, int pos)
{
    e6[pos] = per;
}

public void sete7(String vel, int pos)
{
    e7[pos] = vel;
}

////////// GET/////////

public String getId()
{
    return id;
}

public String getN()
{
    return n;
}

public String get1(int pos)
{
    return e1[pos];
}

public String get2(int pos)
{
    return e2[pos];
}

public String get3(int pos)
{
    return e3[pos];
}

public String get4(int pos)
{
    return e4[pos];
}

public String get5(int pos)
{
    return e5[pos];
}

public String get6(int pos)
{
    return e6[pos];
}

public String get7(int pos)
{
    return e7[pos];
}

public int describeContents() {
    // TODO Auto-generated method stub
    return 0;
}

public void writeToParcel(Parcel dest, int flags) {
    // TODO Auto-generated method stub
    dest.writeString(n);
    dest.writeString(id);
    dest.writeStringArray(e1);
    dest.writeStringArray(e2);
    dest.writeStringArray(e3);
    dest.writeStringArray(e4);
    dest.writeStringArray(e5);
    dest.writeStringArray(e6);
    dest.writeStringArray(e7);
}


public parametros(Parcel in) {

    id = in.readString();
    n = in.readString();
    in.readStringArray(e1);
    in.readStringArray(e2);
    in.readStringArray(e3);
    in.readStringArray(e4);
    in.readStringArray(e5);
    in.readStringArray(e6);
    in.readStringArray(e7);
}

public static final Parcelable.Creator<parametros> CREATOR =
        new Parcelable.Creator<parametros>() {
            public parametros createFromParcel(Parcel in) {
                return new parametros(in);
            }

            public parametros[] newArray(int size) {
                return new parametros[size];
            }
        };

}

在主要活动中:

 Intent alert = new Intent(MainActivity.this,alert.class);
parametros param1 = new parametros();
param1.setNombreboya("SAG");
alert.putExtra("ob", param1);
startActivity(alert);

我得到了参数:

Bundle b = getIntent().getExtras();
parametros param = b.getParcelable("ob");

但是在开始崩溃时出现此错误:

运行时异常:无法实例化活动 componentInfo{previsiones/alert} java.langNullPointerxception

为什么会出现这个错误?谢谢 :)

4

0 回答 0