2012-07-30 63 views
-1

我试图从一种形式的答案在与Android的应用程序。错误的logcat的Android

这里是我使用的代码:

package com.stage.sondage; 



    import android.app.Activity; 
    import android.content.Intent; 
    import android.database.sqlite.SQLiteException; 
    import android.os.Bundle; 
    import android.view.View; 
    import android.view.View.OnClickListener; 
    import android.widget.Button; 
    import android.widget.EditText; 
    import android.widget.RadioButton; 
    import android.widget.RadioGroup; 
    import android.widget.Toast; 

    public class Questionnaire extends Activity { 


EditText zone ; 

RadioGroup mRadioGroup1; 
RadioGroup mRadioGroup2; 
RadioGroup mRadioGroup3; 
RadioGroup mRadioGroup4; 
RadioGroup mRadioGroup5; 

RadioButton b1; 
RadioButton b2; 
RadioButton b3; 
RadioButton b4; 
RadioButton b5; 

Button enregistrer; 

//Création d'une instance de ma classe LivresBDD 
    SurveyAdapter survey; 
    Appreciation appreciation; 

public void onCreate(Bundle savedInstanceState){ 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.questions); 


    // We get a reference on the radio-group widget 
    mRadioGroup1 = (RadioGroup)findViewById(R.appreciation.rep1); 
    mRadioGroup2 = (RadioGroup)findViewById(R.appreciation.rep2); 
    mRadioGroup3 = (RadioGroup)findViewById(R.appreciation.rep3); 
    mRadioGroup4 = (RadioGroup)findViewById(R.appreciation.rep4); 
    mRadioGroup5 = (RadioGroup)findViewById(R.appreciation.rep5); 

    b1 = (RadioButton)findViewById(mRadioGroup1.getCheckedRadioButtonId()); 
    appreciation.setRep1((String) b1.getText()); 
    b2 = (RadioButton)findViewById(mRadioGroup1.getCheckedRadioButtonId()); 
    appreciation.setRep1((String) b2.getText()); 
    b3 = (RadioButton)findViewById(mRadioGroup1.getCheckedRadioButtonId()); 
    appreciation.setRep1((String) b3.getText()); 
    b4 = (RadioButton)findViewById(mRadioGroup1.getCheckedRadioButtonId()); 
    appreciation.setRep1((String) b4.getText()); 
    b5 = (RadioButton)findViewById(mRadioGroup1.getCheckedRadioButtonId()); 
    appreciation.setRep1((String) b5.getText()); 

    zone = (EditText) findViewById(R.appreciation.zone); 
    appreciation.setZone(zone.getText().toString()); 
    try{  

    enregistrer = (Button)findViewById(R.appreciation.enregistrer); 
    enregistrer.setOnClickListener(new OnClickListener() { 

     public void onClick(View view) {           

      //On ouvre la base de données pour écrire dedans 
      survey.open(); 

      //On insère le livre que l'on vient de créer 
      survey.insertAppreciation(appreciation); 

      //on ferme la base de données 
      survey.close(); 
      Intent intent = new Intent(Questionnaire.this,Questionnaire.class); 
      startActivity(intent); 
       } 

      }); 


} 
    // If there is an exception, for example the database is not usable... 
    catch (SQLiteException e) { 
     Toast.makeText(this, "Impossible d'ouvrir la base de donnees",  Toast.LENGTH_SHORT).show(); 
    } 
    catch (Exception e) { 
     Toast.makeText(this, "Problأ¨me... L'erreur vient probablement d'un fichier xml.", Toast.LENGTH_SHORT).show(); 
    } 
} 



} 

我想从这种形式的答案,并返回到相同的形式。

当我启动应用程序我从logcat的以下错误:

07-30 00:59:00.577:E/AndroidRuntime(239):未捕获的处理程序:螺纹主力退出,由于未捕获的异常 07-30 00:59:00.617:E/AndroidRuntime(239):java.lang.RuntimeException:无法启动活动ComponentInfo {com.stage.sondage/com.stage.sondage.Questionnaire}:java.lang.NullPointerException 07-30 00:59:00.617:E/AndroidRuntime(239):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496) 07-30 00:59:00.617:E/AndroidRuntime(239):在机器人.app.ActivityThread.handleLaunchActivity(ACTIV ityThread.java:2512) 07-30 00:59:00.617:E/AndroidRuntime(239):at android.app.ActivityThread.access $ 2200(ActivityThread.java:119) 07-30 00:59:00.617:E/AndroidRuntime(239):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1863) 07-30 00:59:00.617:E/AndroidRuntime(239):在android.os.Handler.dispatchMessage(处理程序.java:99) 07-30 00:59:00.617:E/AndroidRuntime(239):at android.os.Looper.loop(Looper.java:123) 07-30 00:59:00.617:E/AndroidRuntime (239):在android.app.ActivityThread.main(ActivityThread.java:4363) 07-30 00:59:00.617:E/AndroidRuntime(239):在java.lang.reflect.Method.invokeNative(本机方法) 07-30 00:59:00.617:E/AndroidRuntime(239):在java.lang.reflect.Method.invoke(Method.java:521) 07-30 00:59:00.617:E/AndroidRuntime(239):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:860) 07-30 00:59:00.617:E/AndroidRuntime(239):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) 07-30 00:59:00.617:E/AndroidRuntime(239):在dalvik.system.NativeStart.main(本地方法) 07-30 00:59:00.617:E/AndroidRuntime(239):引起于:java.lang.NullPointerException 07-30 00:59:00.617:E/AndroidRuntime(239):at com.stage。 sandage.Questionnaire.onCreate(Questionnaire.java:53) 07-30 00:59:00.617:E/AndroidRuntime(239):at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 07-30 00: 59:00.617:E/AndroidRuntime(239):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459) 07-30 00:59:00.617:E/AndroidRuntime(239):... 11更多

任何人都可以帮我解决这个问题吗?

+1

什么是线53?而你为什么你的按钮的onClick与尝试捕捉周围? – 0gravity 2012-07-30 01:17:30

+2

'survey'为空。 – 2012-07-30 01:24:01

+0

我删除了try catch仍然存在问题 – sigway 2012-07-30 03:52:24

回答

1

你调查变量为空,因为你不初始化。你只是这样做:

SurveyAdapter survey; 

,离开它这样。

这就是为什么你会得到NullPointerException异常错误。

+0

我改变了代码,但问题仍然存在 SurveyAdapter survey = new SurveyAdapter(this); 增值升值=新增值();我怎样才能发送这个论坛上的项目,所以你可以看到它entirly – sigway 2012-07-30 03:37:57