我需要在我的应用程序中搜索产品以及该产品在另一个表中的某些引用我创建了两个 to 表,当我执行应用程序时,logcat 说这是 oncreat 中的一个问题,你能帮我了解一下以及如何修复它j
ava.lang.RuntimeException: Unable to start activity ComponentInfo{tabet.ventas/tabet.ventas.LigneVente}: java.lang.NullPointerException
05-19 15:20:46.934: E/AndroidRuntime(799): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
05-19 15:20:46.934: E/AndroidRuntime(799): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
05-19 15:20:46.934: E/AndroidRuntime(799): at android.app.ActivityThread.access$600(ActivityThread.java:141)
05-19 15:20:46.934: E/AndroidRuntime(799): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
05-19 15:20:46.934: E/AndroidRuntime(799): at android.os.Handler.dispatchMessage(Handler.java:99)
05-19 15:20:46.934: E/AndroidRuntime(799): at android.os.Looper.loop(Looper.java:137)
05-19 15:20:46.934: E/AndroidRuntime(799): at android.app.ActivityThread.main(ActivityThread.java:5039)
05-19 15:20:46.934: E/AndroidRuntime(799): at java.lang.reflect.Method.invokeNative(Native Method)
05-19 15:20:46.934: E/AndroidRuntime(799): at java.lang.reflect.Method.invoke(Method.java:511)
05-19 15:20:46.934: E/AndroidRuntime(799): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
05-19 15:20:46.934: E/AndroidRuntime(799): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
05-19 15:20:46.934: E/AndroidRuntime(799): at dalvik.system.NativeStart.main(Native Method)
05-19 15:20:46.934: E/AndroidRuntime(799): Caused by: java.lang.NullPointerException
05-19 15:20:46.934: E/AndroidRuntime(799): at tabet.ventas.LigneVente.onCreate(LigneVente.java:42)
05-19 15:20:46.934: E/AndroidRuntime(799): at android.app.Activity.performCreate(Activity.java:5104)
05-19 15:20:46.934: E/AndroidRuntime(799): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
05-19 15:20:46.934: E/AndroidRuntime(799): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
05-19 15:20:46.934: E/AndroidRuntime(799): ... 11 more
对于我的活动 LigneVente
public class LigneVente extends Activity {
SQLiteDatabase dlv;
EditText inputNom;
EditText inputDate;
EditText txtrechercheProduit;
EditText nom_produit_vente;
EditText quantite_stock_vente;
EditText prix_ligne_vente;
EditText Qte_voulue;
String recID="0";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ligne_vente);
txtrechercheProduit =(EditText)findViewById(R.id.txtrechercheProduit);
nom_produit_vente=(EditText)findViewById(R.id.nom_produit_vente);
Qte_voulue=(EditText)findViewById(R.id.Qte_voulue);
prix_ligne_vente=(EditText)findViewById(R.id.prix_ligne_vente);
txtrechercheProduit.requestFocus();
nom_produit_vente.setEnabled(false);
quantite_stock_vente.setEnabled(false);
prix_ligne_vente.setEnabled(false);
createDB();
Qte_voulue=(EditText)findViewById(R.id.Qte_voulue);
Button btn_chercher=(Button)findViewById(R.id.btn_chercher);
Button btn_valid=(Button)findViewById(R.id.Valider_choix);
dlv=openOrCreateDatabase("produitbase.db", SQLiteDatabase.CREATE_IF_NECESSARY, null);
btn_chercher.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
if (txtrechercheProduit.getText().toString().equals(""))
{
Toast.makeText(LigneVente.this, "Entrer le produit a rechercher.", Toast.LENGTH_SHORT).show();
}
else
{
searchRecord();
}
}
});
btn_valid.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
if (Qte_voulue.getText().toString().equals(""))
{
Toast.makeText(LigneVente.this, "Entrer la Qte a vouloir acheté", Toast.LENGTH_SHORT).show();
}
else
{
insert();
}
}
});
inputNom = (EditText) findViewById(R.id.nom);
inputDate = (EditText) findViewById(R.id.date);
Button btnenvoifact = (Button) findViewById(R.id.btnEnvoyer);
btnenvoifact.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
//Starting a new Intent
Intent verifierFacture = new Intent(getApplicationContext(), FactureActivity.class);
//envoyer nom du client et la date a la facture
verifierFacture.putExtra("nom", inputNom.getText().toString());
verifierFacture.putExtra("date", inputDate.getText().toString());
// ouvrire la fenétre facture ou nn ..!!???
startActivity(verifierFacture);
}
});
Button btnretour = (Button) findViewById(R.id.btn_retour);
btnretour.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// Launching produit Screen
//@_@ Intent i = new Intent(getApplicationContext(), VenteBoxClass.class);
//@_@ startActivity(i);
}
});
Button btnvalider = (Button) findViewById(R.id.Valider_choix);
Button btnrecherche = (Button) findViewById(R.id.btn_chercher);
}