嗨,我正在開發一個應用程序在Android中,我已經嘗試在Communicator.generateMessageId()中的空對象引用上調用vitrual方法。Android應用程序的空對象引用
這裏是我的代碼發生錯誤:
public class StatsActivity extends TaxiplonActivity {
protected Communicator comm;
protected TaxiMapGoogle messageId;
Message statusMessageBody;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.stats_activity);
ToggleButton toggleButton = (ToggleButton) findViewById (R.id.toggleButton1);
// get action bar
ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setTitle("Driver Options");
testRequest();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.option_menu, menu);
return super.onCreateOptionsMenu(menu);
}
public void testRequest() {
sendMessage(comm.generateMessageId(),"agent=driver&action=get&driverid=6609",
OPTION_DRIVER, activityHandler,null);
//System.out.println("MessageId: "+comm.generateMessageId());
}
@Override
public void postConnectionSuccessful() {
// TODO Auto-generated method stub
}
@Override
public void preConnectionReset() {
// TODO Auto-generated method stub
}
}
,這裏是我從我的通訊器類調用方法:
public String generateMessageId() {
try {
TaxiplonApp taxiplonApp = (TaxiplonApp) parent
.getApplicationContext();
TwoFishEncryprion twoFishEncryprion = new TwoFishEncryprion(
messageIdKey);
String cleanMessageId = taxiplonApp.getDriverId() + "|"
+ taxiplonApp.getDeviceId() + "|"
+ ntpClock.getCachedDate().getTime();
return twoFishEncryprion.encrypt(cleanMessageId).replace(" ", "");
} catch (NTPClockException e) {
AploonLogger.error("Problem generating imei messageId", e);
parent.showNtpClockDialog();
}
return null;
}
我initiallize在COMM我TaxiplonActivity.class here:
protected class Connector extends AsyncTask<Runnable, Void, Void> {
@Override
protected void onPreExecute() {
showBusyDialog();
}
@Override
protected Void doInBackground(Runnable... runnables) {
//init communication
comm = Communicator.getInstance(TaxiplonActivity.this, false);
//if connection is already available, proceed to postConnectionInit (it will not be called, like when connection is established)
if(comm.isConnected()) {
postConnectionSuccessful();
}
return null;
}
@Override
protected void onPostExecute(Void v) {
hideBusyDialog();
}
}
任何人都可以幫助我如何解決這個錯誤?
你在哪裏初始化'comm'? – poss
'comm'初始化在哪裏? – Piyush
我更新了我的問題,告訴你我在哪裏初始化它 – appLogic