2013-05-19 51 views
0

我需要在我的appps搜索產品和som引用該產品在anather表中 我創建了表和當我執行應用程序logcat說這是一個問題oncreat你可以幫我understous,以及如何解決它 Ĵ在android中的oncreate活動有什麼不對

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 
    //@[email protected]  Intent i = new Intent(getApplicationContext(), VenteBoxClass.class); 
    //@[email protected]  startActivity(i); 
      } 
     }); 
     Button btnvalider = (Button) findViewById(R.id.Valider_choix); 
     Button btnrecherche = (Button) findViewById(R.id.btn_chercher); 

    } 
+0

什麼是第35行? – EyalBellisha

+0

在txtrechercheProduit.requestFocus()之前移動所有findviwebyid的代碼。並嘗試。 – Raghunandan

回答

0
package tabet.ventas; 

import java.util.Locale; 
import android.os.Bundle; 
import android.app.Activity; 
import android.content.Intent; 
import android.database.Cursor; 
import android.database.sqlite.SQLiteDatabase; 
import android.view.Menu; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.Button; 
import android.widget.EditText; 
import android.widget.Toast; 

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 prix_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); 
     quantite_stock_vente=(EditText)findViewById(R.id.quantite_stock_vente); 
     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 
    //@[email protected]  Intent i = new Intent(getApplicationContext(), VenteBoxClass.class); 
    //@[email protected]  startActivity(i); 
      } 
     }); 
     Button btnvalider = (Button) findViewById(R.id.Valider_choix); 
     Button btnrecherche = (Button) findViewById(R.id.btn_chercher); 

    } 
相關問題