Android getParcelable空指针异常
我的捆绑包可包裹性有问题(NullPointerException): 日志: 舆论活动:Android getParcelable空指针异常,android,Android,我的捆绑包可包裹性有问题(NullPointerException): 日志: 舆论活动: public class OpisMiejscaActivity extends FragmentActivity { Miejsce zMiejsce; boolean mShowMap; GoogleMap zMap; private ImageView imgView; @Override protected void onCreate(Bun
public class OpisMiejscaActivity extends FragmentActivity
{
Miejsce zMiejsce;
boolean mShowMap;
GoogleMap zMap;
private ImageView imgView;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.opis_miejsca_activity);
getActionBar().setDisplayHomeAsUpEnabled(true);
//
mShowMap = GooglePlayServiceUtility.isPlayServiceAvailable(this) && initMap();
Bundle b = getIntent().getExtras();
zMiejsce = b.getParcelable(".model.Miejsce");
display();
}
//
private boolean initMap()
{
// TODO Auto-generated method stub
if(zMap == null)
{
SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
zMap = fm.getMap();
// MapFragment mapFrag = (MapFragment) getFragmentManager().findFragmentById(R.id.map);
// zMap = mapFrag.getMap();
}
return (zMap != null);
}
private void display()
{
TextView tv = (TextView) findViewById(R.id.titleText);
tv.setText(zMiejsce.getTytul1());
NumberFormat nf = NumberFormat.getCurrencyInstance();
tv = (TextView) findViewById(R.id.priceText);
tv.setText(nf.format(zMiejsce.getKoszt()));
tv = (TextView) findViewById(R.id.descText);
tv.setText(zMiejsce.getOpis());
//imgView = (ImageView) findViewById(R.id.imageView1);
//imgView.setImageResource(R.drawable.map_whitney);
//imgView.setImageBitmap(BitmapFactory.decodeFile(zMiejsce.getImage()));
/*imgView = (ImageView) findViewById(R.id.imageView1);
imgView.setImageBitmap(BitmapFactory.decodeFile(zMiejsce.getImage()));
*/
//
if (mShowMap)
{
CameraUpdate update = CameraUpdateFactory.newLatLngZoom(zMiejsce.getLatLng(), 5);
zMap.moveCamera(update);
}
/*SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
GoogleMap zMap = fm.getMap();*/
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.opis_miejsca, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_goto_action :
// Go to external mapping app
sendToActionIntent();
break;
case android.R.id.home:
// User pressed the 'Up' button on the action bar
finish();
break;
}
return false;
}
}
Bundle b = getIntent().getExtras();
zMiejsce = b.getParcelable(".model.Miejsce");
display();
在我看来,OpismieJSCA活动中的片段有些问题:
public class OpisMiejscaActivity extends FragmentActivity
{
Miejsce zMiejsce;
boolean mShowMap;
GoogleMap zMap;
private ImageView imgView;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.opis_miejsca_activity);
getActionBar().setDisplayHomeAsUpEnabled(true);
//
mShowMap = GooglePlayServiceUtility.isPlayServiceAvailable(this) && initMap();
Bundle b = getIntent().getExtras();
zMiejsce = b.getParcelable(".model.Miejsce");
display();
}
//
private boolean initMap()
{
// TODO Auto-generated method stub
if(zMap == null)
{
SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
zMap = fm.getMap();
// MapFragment mapFrag = (MapFragment) getFragmentManager().findFragmentById(R.id.map);
// zMap = mapFrag.getMap();
}
return (zMap != null);
}
private void display()
{
TextView tv = (TextView) findViewById(R.id.titleText);
tv.setText(zMiejsce.getTytul1());
NumberFormat nf = NumberFormat.getCurrencyInstance();
tv = (TextView) findViewById(R.id.priceText);
tv.setText(nf.format(zMiejsce.getKoszt()));
tv = (TextView) findViewById(R.id.descText);
tv.setText(zMiejsce.getOpis());
//imgView = (ImageView) findViewById(R.id.imageView1);
//imgView.setImageResource(R.drawable.map_whitney);
//imgView.setImageBitmap(BitmapFactory.decodeFile(zMiejsce.getImage()));
/*imgView = (ImageView) findViewById(R.id.imageView1);
imgView.setImageBitmap(BitmapFactory.decodeFile(zMiejsce.getImage()));
*/
//
if (mShowMap)
{
CameraUpdate update = CameraUpdateFactory.newLatLngZoom(zMiejsce.getLatLng(), 5);
zMap.moveCamera(update);
}
/*SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
GoogleMap zMap = fm.getMap();*/
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.opis_miejsca, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_goto_action :
// Go to external mapping app
sendToActionIntent();
break;
case android.R.id.home:
// User pressed the 'Up' button on the action bar
finish();
break;
}
return false;
}
}
Bundle b = getIntent().getExtras();
zMiejsce = b.getParcelable(".model.Miejsce");
display();
也许是钥匙出了问题
Miejsce:
public class Miejsce implements Parcelable
{
private long identyfikator;
private String miasto;
private String tytul1;
private String tytul2;
private String opis;
private String marker = "";
private double koszt;
private double poziomTrudnosci;
private String image;
private double latitude = 51.108342;
private double longitude = 17.060831;
private static String LOGTAG = "MYSTERIOUSPOLAND";
public Miejsce()
{
}
public Miejsce(Parcel in)
{
Log.i(LOGTAG, "Parcel");
identyfikator = in.readLong();
miasto = in.readString();
tytul1 = in.readString();
tytul2 = in.readString();
koszt = in.readDouble();
poziomTrudnosci = in.readDouble();
image = in.readString();
latitude = in.readDouble();
longitude = in.readDouble();
marker = in.readString();
}
public long getIdentyfikator()
{
return identyfikator;
}
public void setIdentyfikator(long identyfikator)
{
this.identyfikator = identyfikator;
}
public String getMiasto()
{
return miasto;
}
public void setMiasto(String miasto)
{
this.miasto = miasto;
}
public String getTytul1()
{
return tytul1;
}
public void setTytul1(String tytul1)
{
this.tytul1 = tytul1;
}
public String getTytul2()
{
return tytul2;
}
public void setTytul2(String tytul2)
{
this.tytul2 = tytul2;
}
public String getOpis()
{
return opis;
}
public void setOpis(String opis)
{
this.opis = opis;
}
public double getKoszt()
{
return koszt;
}
public void setKoszt(double koszt)
{
this.koszt = koszt;
}
public double getPoziomTrudnosci()
{
return poziomTrudnosci;
}
public void setPoziomTrudnosci(double poziomTrudnosci)
{
this.poziomTrudnosci = poziomTrudnosci;
}
public String getImage()
{
return image;
}
public void setImage(String image)
{
this.image = image;
}
public double getLatitude()
{
return latitude;
}
public void setLatitude(double latitude)
{
this.latitude = latitude;
}
public double getLongitude()
{
return longitude;
}
public void setLongitude(double longitude)
{
this.longitude = longitude;
}
public String getMarker()
{
return marker;
}
public void setMarker(String marker)
{
this.marker = marker;
}
@Override
public String toString()
{
NumberFormat nf = NumberFormat.getCurrencyInstance();
return tytul1 + "\n(" + nf.format(koszt) + ")";
}
public LatLng getLatLng()
{
LatLng latLng = new LatLng(latitude, longitude);
return latLng;
}
@Override
public int describeContents()
{
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags)
{
dest.writeLong(identyfikator);
dest.writeString(miasto);
dest.writeString(tytul1);
dest.writeString(tytul2);
dest.writeString(opis);
dest.writeDouble(koszt);
dest.writeDouble(poziomTrudnosci);
dest.writeString(image);
dest.writeDouble(latitude);
dest.writeDouble(longitude);
dest.writeString(marker);
}
public static final Parcelable.Creator<Miejsce> CREATOR = new Parcelable.Creator<Miejsce>()
{
@Override
public Miejsce createFromParcel(Parcel source)
{
return new Miejsce(source);
}
@Override
public Miejsce[] newArray(int size)
{
return new Miejsce[size];
}
};
}
public类Miejsce实现了Parcelable
{
私人长标识符;
私有字符串miasto;
私有字符串tytul1;
私有字符串类型2;
私人字符串OPI;
私有字符串标记=”;
私人双koszt;
私人双坡齐奥姆特鲁德诺西;
私有字符串图像;
私人双纬度=51.108342;
私人双经度=17.060831;
私有静态字符串LOGTAG=“神秘波兰”;
公共部门
{
}
公共Miejsce(包裹内)
{
日志i(日志标签,“包裹”);
identifIkator=in.readLong();
miasto=in.readString();
tytul1=in.readString();
tytul2=in.readString();
koszt=in.readDouble();
poziomTrudnosci=in.readDouble();
image=in.readString();
纬度=in.readDouble();
经度=in.readDouble();
marker=in.readString();
}
公共长getIdentityFicator()
{
返回识别器;
}
public void setidentityficator(长identityficator)
{
this.identifikator=identifikator;
}
公共字符串getMiasto()
{
返回米亚斯托;
}
公共无效setMiasto(字符串miasto)
{
this.miasto=miasto;
}
公共字符串getTytul1()
{
返回tytul1;
}
公共无效设置tytul1(字符串tytul1)
{
this.tytul1=tytul1;
}
公共字符串getTytul2()
{
返回tytul2;
}
公共无效集合tytul2(字符串tytul2)
{
this.tytul2=tytul2;
}
公共字符串getOpis()
{
返回OPI;
}
公共无效设置opis(字符串opis)
{
this.opis=opis;
}
公共双getKoszt()
{
返回koszt;
}
公共空间设置koszt(双koszt)
{
this.koszt=koszt;
}
公共双getPoziomTrudnosci()
{
返回poziomTrudnosci;
}
公共无效setPoziomTrudnosci(双poziomTrudnosci)
{
this.poziomTrudnosci=poziomTrudnosci;
}
公共字符串getImage()
{
返回图像;
}
公共void setImage(字符串图像)
{
这个图像=图像;
}
公共双纬度()
{
返回纬度;
}
公共纬度(双纬度)
{
这个。纬度=纬度;
}
公共双getLongitude()
{
返回经度;
}
公共经度(双经度)
{
这个经度=经度;
}
公共字符串getMarker()
{
返回标记;
}
公共无效设置标记(字符串标记)
{
this.marker=标记;
}
@凌驾
公共字符串toString()
{
NumberFormat nf=NumberFormat.getCurrencyInstance();
返回tytul1+“\n(“+nf.format(koszt)+”);
}
公共LatLng getLatLng()
{
LatLng LatLng=新LatLng(纬度、经度);
返回板条;
}
@凌驾
公共int描述内容()
{
返回0;
}
@凌驾
公共无效写入包裹(包裹目的地,内部标志)
{
目的地记录长(识别者);
目的地书面记录(miasto);
目的地登记(tytul1);
目的地书面记录(tytul2);
目的地书面资源(opis);
目的地可写资产(koszt);
目的地可写资产(poziomTrudnosci);
目标写入限制(图像);
目的地可写双(纬度);
目的地可写双倍(经度);
目的地记录(标记);
}
public static final Parcelable.Creator=新建Parcelable.Creator()
{
@凌驾
公共Miejsce createFromParcel(地块源)
{
返回新的Miejsce(来源);
}
@凌驾
公共Miejsce[]新数组(整数大小)
{
返回新的Miejsce[size];
}
};
}
您可以通过执行b.hasKey(“.model.Miejsce”) 你有没有用托盘getIntent().getParcelableExtra()
代替b.getParcelable
键“.model.Miejsce”与putExtra???.model.Miejsce”相同!=“.model.Miejsca”:)谢谢:)