Intent.setClass error
I have the following ClickListener code. It will do different stuff depending on what button was pressed. If the Vehicle button is pressed I want it to start another activity by loading开发者_开发问答 the Vehicles.class but it is erroring during the setClass() statement.I believe it is erroring when trying to instantiate the Vehicles class. The error returned is NoClassDefFoundError.
Can someone tell me what I'm doing wrong here?
Thanks Patrick
OnClickListener code:
private OnClickListener mClickListener = new OnClickListener() {
@Override
public void onClick(View v) {
Button btn = (Button) v;
String txt = (String) btn.getText().toString();
mSaveButton = (Button) findViewById(R.id.btnSaveTripInfo);
mVehiclesButton = (Button) findViewById(R.id.btnVehicles);
if(btn.equals(mSaveButton)) {
onSaveClick(v);
}else if (btn.equals(mStartStopButton)){
onStartStopClick(v);
}else if (btn.equals(mVehiclesButton)) {
Intent intent = new Intent();
intent.setClass(v.getContext(),Vehicles.class);
startActivity(intent);
}
}
};
The Vehicles class code:
public class Vehicles extends Activity {
private static final String TAG = "Vehicles";
private static int m_id;
private static String mVehName;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.vehicles);
}
}
Check that your Vehicles
activity is declared in your AndroidManifest.xml
精彩评论