Android将意图从onclick按钮创建编程 - 未找到活动例外
问题描述:
我必须意图通过点击一个按钮,其中整个布局是以编程方式创建的。 我检查了'Android content activity not found exception'的所有答案,并尝试了所有答案。但问题仍然存在。我使用了try catch块,但问题仍然存在。Android将意图从onclick按钮创建编程 - 未找到活动例外
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
db = new DBOperation(this);
document = getIntent().getStringExtra("document_id");
getAlldataList=db.getPartiesReport(db);
LinearLayout rootView = new LinearLayout(this);
LinearLayout rootView1 = new LinearLayout(this);
// RelativeLayout rootView2 = new RelativeLayout(this);
Button update1 = new Button(this);
update1.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
update1.setGravity(Gravity.CENTER);
update1.setText("UPDATE");
update1.setBackgroundColor(Color.parseColor("#ffa500"));
update1.setTextColor(Color.WHITE);
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) update1.getLayoutParams();
params.setMargins(20, 20, 20, 10);
update1.setLayoutParams(params);
update1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
for (int i = 0; i < poslist.size(); i++) {
//
// SQLiteDatabase base3 = db.getWritableDatabase();
// base3.delete(UPDATEPARTIES1, null, null);
// System.out.println("Parties DB Deleted");
SQLiteDatabase db7 = db.getWritableDatabase();
ContentValues values5= new ContentValues();
values5.put(DBManager.TableInfo.KEYID, ID1);
values5.put(DBManager.TableInfo.DOCUMENT, document);
values5.put(DBManager.TableInfo.ATTENDANCE,attendancelist.get(i));
values5.put(DBManager.TableInfo.EMAILNEW, emaillist.get(i));
values5.put(DBManager.TableInfo.PARTYTYPE,partytypelist.get(i));
values5.put(DBManager.TableInfo.BIOMETRIC,biometriclist.get(i));
values5.put(DBManager.TableInfo.KEY_LOGIN_USER,username2);
String condition5 = DBManager.TableInfo.DOCUMENT + " =?";
Cursor cursor5 = db7.query(DBManager.TableInfo.UPDATEPARTIES1, null, condition5, new String[]{DBManager.TableInfo.ATTENDANCE}, null, null, null);
long status5 = db7.insert(DBManager.TableInfo.UPDATEPARTIES1, null, values5);
System.out.println("Parties insert : " + status5);
cursor5.close();
db7.close();
}
itemlist.clear();
poslist.clear();
IDlist.clear();
attendancelist.clear();
partytypelist.clear();
emaillist.clear();
biometriclist.clear();
System.out.println("Poslist:" + poslist.size());
System.out.println("itemlist:" + itemlist.size());
System.out.println("IDlist:" + IDlist.size());
Intent i1=new Intent(anulom.executioner5.com3.anulom.newstatusinfo.this,SendPartyReport.class);
startActivity(i1);
finish();
}
});
答
你必须调用
startService(i1);
代替
startActivity(i1);
出现异常是因为您尝试启动活动,而不是服务。如果我不确定您是否正确指出SendPartyReport是服务,那么您将不得不使用startService方法。
问候
+0
是的,现在工作正常......谢谢.... !!!!!! – user7245
清单中的活动“SendPartyReport”? – RobVoisey
有你在申报清单文件 – Anil
是本次活动的 –
user7245