2012-02-28 28 views
0

初心者のチュートリアルの後、時間のかかる時間をかけてメディアを再生するタイマーアプリを作成するための一連のレッスンが完成しました。アプリは完璧に...昨日働いた。私は何も変えていないが、今日デバッグしようとすると、アプリは自分の電話にロードされ、インストールされ、クラッシュするだろう。 ...アプリの起動時に「FATAL EXCEPTION:main」

02-28 15:12:58.864: E/AndroidRuntime(26257): FATAL EXCEPTION: main 
02-28 15:12:58.864: E/AndroidRuntime(26257): java.lang.RuntimeException: Unable to start activity ComponentInfo{digital.clock.activity/digital.clock.activity.DigitalActivity}: java.lang.NullPointerException 
02-28 15:12:58.864: E/AndroidRuntime(26257): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647) 
02-28 15:12:58.864: E/AndroidRuntime(26257): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663) 
02-28 15:12:58.864: E/AndroidRuntime(26257): at android.app.ActivityThread.access$1500(ActivityThread.java:117) 
02-28 15:12:58.864: E/AndroidRuntime(26257): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931) 
02-28 15:12:58.864: E/AndroidRuntime(26257): at android.os.Handler.dispatchMessage(Handler.java:99) 
02-28 15:12:58.864: E/AndroidRuntime(26257): at android.os.Looper.loop(Looper.java:130) 
02-28 15:12:58.864: E/AndroidRuntime(26257): at android.app.ActivityThread.main(ActivityThread.java:3683) 
02-28 15:12:58.864: E/AndroidRuntime(26257): at java.lang.reflect.Method.invokeNative(Native Method) 
02-28 15:12:58.864: E/AndroidRuntime(26257): at java.lang.reflect.Method.invoke(Method.java:507) 
02-28 15:12:58.864: E/AndroidRuntime(26257): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 
02-28 15:12:58.864: E/AndroidRuntime(26257): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 
02-28 15:12:58.864: E/AndroidRuntime(26257): at dalvik.system.NativeStart.main(Native Method) 
02-28 15:12:58.864: E/AndroidRuntime(26257): Caused by: java.lang.NullPointerException 
02-28 15:12:58.864: E/AndroidRuntime(26257): at digital.clock.activity.DigitalActivity.onCreate(DigitalActivity.java:74) 
02-28 15:12:58.864: E/AndroidRuntime(26257): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 
02-28 15:12:58.864: E/AndroidRuntime(26257): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611) 
02-28 15:12:58.864: E/AndroidRuntime(26257): ... 11 more 

をそして、私のメインの活動はそれほどのように見える、それはあなたのボタンを見つけていないよう

package digital.clock.activity; 

import android.app.Activity; 
import android.content.Intent; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.Button; 
import android.widget.EditText; 
import android.widget.Toast; 
import android.app.AlarmManager; 
import android.app.PendingIntent; 
import java.util.ArrayList; 
import android.gesture.Gesture; 
import android.gesture.GestureLibraries; 
import android.gesture.GestureLibrary; 
import android.gesture.GestureOverlayView; 
import android.gesture.Prediction; 
import android.gesture.GestureOverlayView.OnGesturePerformedListener; 


public class DigitalActivity extends Activity 
{ 

private GestureLibrary gLib; 

@Override 
public void onCreate(Bundle savedInstanceState) 
{ 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    gLib = GestureLibraries.fromRawResource(this, R.raw.gestures); 
    if (!gLib.load()) 
    { 
     Toast.makeText(this, "Could not load Gesture Library", Toast.LENGTH_LONG).show(); 
     finish(); 
    } 

    GestureOverlayView gestures = (GestureOverlayView) findViewById(R.id.gestures); 



    final OnGesturePerformedListener handleGestureListener = new OnGesturePerformedListener() 
    { 
     @Override 
     public void onGesturePerformed(GestureOverlayView gestureView, Gesture gesture) 
     { 

      ArrayList<Prediction> predictions = gLib.recognize(gesture); 

      // one prediction needed 
      if (predictions.size() > 0) 
      { 
       Prediction prediction = predictions.get(0); 
       // checking prediction 
       if (prediction.score > 1.0) 
       { 
        // and action 
        timerAlert2(); 
       } 
      } 

     } 
    }; 

    gestures.addOnGesturePerformedListener(handleGestureListener); 





    //Create button and do something with intents... 
    Button Activity2 = (Button) findViewById(R.id.Button01); 
    Activity2.setOnClickListener(new View.OnClickListener() 
    { 
     public void onClick (View view) 
     { 
      Intent replyIntent = new Intent(); 
      setResult(RESULT_OK, replyIntent); 
      finish(); 
     } 
    }); 

    Button startTimer = (Button) findViewById(R.id.startTimer); 
    startTimer.setOnClickListener(new View.OnClickListener() 
    { 
     public void onClick (View view) 
     { 
      timerAlert(view); 
     } 
    }); 

    Button stopAlarm = (Button) findViewById(R.id.stopAlarm); 
    stopAlarm.setOnClickListener(new View.OnClickListener() 
    { 
     public void onClick (View view) 
     { 
      stopService(new Intent(getBaseContext(), MediaPlayerService.class)); 
     } 
    }); 
} 




public void timerAlert (View view) 
{ 

    //Declare the EditText object 
    EditText textField = (EditText) findViewById(R.id.timeInSeconds); 

    //Get user-entered number and convert to string 

    int i = Integer.parseInt(textField.getText().toString()); 

    //Declare intent object 
    Intent timerIntent = new Intent(this, TimerBroadcastReceiver.class); 

    //Create PendingIntent and set parameters (context, code, intent object to use, constants) 
    PendingIntent myPendingIntent = PendingIntent.getBroadcast(this.getApplicationContext(), 0, timerIntent, 0); 

    //Create AlarmManager and assign it the ALARM_SERVICE 
    AlarmManager myAlarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); 

    //set AlarmManager parameters (type, TriggerTime, Operation) 
    //RTC_WAKEUP will wake up the phone for the alarm, RTC will activate the alarm next time the phone wakes 
    myAlarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + (i * 1000), myPendingIntent); 

    Toast.makeText(this, "Alarm is set for " + i + " seconds!", Toast.LENGTH_LONG).show(); 
} 

public void timerAlert2() 
{ 
    int i = 5; 

    //Declare intent object 
    Intent timerIntent = new Intent(this, TimerBroadcastReceiver.class); 

    //Create PendingIntent and set parameters (context, code, intent object to use, constants) 
    PendingIntent myPendingIntent = PendingIntent.getBroadcast(this.getApplicationContext(), 0, timerIntent, 0); 

    //Create AlarmManager and assign it the ALARM_SERVICE 
    AlarmManager myAlarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); 

    //set AlarmManager parameters (type, TriggerTime, Operation) 
    //RTC_WAKEUP will wake up the phone for the alarm, RTC will activate the alarm next time the phone wakes 
    myAlarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + (i * 60000), myPendingIntent); 

    Toast.makeText(this, "Alarm is set for " + i + " minutes!", Toast.LENGTH_LONG).show(); 
} 

} 
+1

原因:digital.clock.activity.DigitalActivity.onCreate(DigitalActivity.java:74)のjava.lang.NullPointerException – SLaks

+0

ボタンが存在しますか?Button01? – JProgrammer

+0

私はそれが迅速な修正であることを知っていました。 Button01はもうありません。それを取り除いて固定しました。どうもありがとうございました! – Jodron

答えて

0

は思える:私は理解していないエラーメッセージの負荷を取得します(これを73行目でインスタンス化したボタン(Button01)にアクセスしようとしている行でクラッシュします。

プロジェクトを検索するには、resと呼ばれるサブディレクトリが必要です。main.xmlという名前のファイルが存在する必要があります。その中に要素があるはずです

プロジェクトにこのファイルが含まれていて、その行があるかどうかを確認する必要があります。それでも問題が解決しない場合は、プロジェクトを修正してください。

関連する問題