bonjour,

mon appli crash suite à la demande de l'Intent de ma class timerTime importer dans toute les vues de l'app.

ma class timerTime est comme ceci:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
public class timerTime extends AppCompatActivity {
 
    /** timer */
    private static Timer timer;
    private static TimerTask timerTask;
    private final static Handler handler = new Handler();
 
    private static Context mCtx = null;
 
    public timerTime(Context ctxt){
        this.mCtx = ctxt;
    }
 
    public void startTimer(){
        Log.i("startTimer()","start 30000");
        timer = new Timer();
        loadTimer(/*theContext*/);
        timer.schedule(timerTask,30000);
    }
 
    public void startTimer(int time){
        Log.i("startTimer()","time => "+time);
        timer = new Timer();
        loadTimer();
        timer.schedule(timerTask,time);
    }
 
    public static void stopTimer(){
        if (timer != null) {
            Log.i("stopTimer()","stop");
            timer.cancel();
            timer = null;
 
        }
    }
    public void loadTimer(){
        timerTask = new TimerTask(){
            public void run(){
                handler.post(new Runnable(){
                    @Override
                    public void run() {
                        stopTimer();
                        Intent i = new Intent(mCtx, MainActivity.class);
                        startActivity(i);
                    }
                });
            }
        };
    }
}
et voici une des vues qui l'utilise
je n'ai mis ici que ce qui est nécessaire pour l'exemple
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
public class logon extends AppCompatActivity implements View.OnTouchListener, View.OnClickListener {
 
    private EditText et_login, et_mdp;
    /** timer */
    private timerTime timerTime = new timerTime(this);
 
    private boolean update = false;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        hideNavigationBar();
        setContentView(R.layout.logon);
        hideNavigationBar();
 
        et_login = (EditText)findViewById(R.id.et_login);
        et_mdp = (EditText)findViewById(R.id.et_mdp);
 
        et_login.setOnTouchListener(this);
        et_mdp.setOnTouchListener(this);
 
        et_login.addTextChangedListener(verifForTimeLodin);
        et_mdp.addTextChangedListener(verifForTimeMdp);
    }
 
    @Override
    public boolean onTouch(View v, MotionEvent event){
 
        if (v == et_login){
            log("et_login: " + stringValue(event));
        }
        if (v == et_mdp) {
            log("et_mdp: " + stringValue(event));
        }
        return false;
    }
    @Override
    public boolean onTouchEvent(MotionEvent event) {
        log("Activity: " + stringValue(event));
        return true;
    }
    private String stringValue(MotionEvent event) {
 
        final int action = event.getAction();
 
        switch (action) {
            case MotionEvent.ACTION_DOWN:
                timerTime.stopTimer();
                timerTime.startTimer();
                return "ACTION_DOWN";
            case MotionEvent.ACTION_MOVE:
                return "ACTION_MOVE";
            case MotionEvent.ACTION_UP:
                return "ACTION_UP";
            case MotionEvent.ACTION_CANCEL:
                return "ACTION_CANCEL";
        }
 
        return "";
    }
 
    @Override
    protected void onResume() {
        timerTime.startTimer(10000);
        super.onResume();
    }
    TextWatcher verifForTimeLodin = new TextWatcher() {
        public void onTextChanged(CharSequence s, int start, int before, int count) {
 
        }
 
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
 
        }
 
        public void afterTextChanged(Editable s) {
            if (update){
                update = false;
                timerTime.startTimer();
            }else {
                timerTime.stopTimer();
                timerTime.startTimer();
            }
        }
    };
    TextWatcher verifForTimeMdp = new TextWatcher() {
        public void onTextChanged(CharSequence s, int start, int before, int count) {
 
        }
 
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
 
        }
 
        public void afterTextChanged(Editable s) {
            if (update){
                update = false;
                timerTime.startTimer();
            }else {
                timerTime.stopTimer();
                timerTime.startTimer();
            }
        }
    };
}
et dans le log quand il crash
java.lang.NullPointerException: Attempt to invoke virtual method 'android.app.ActivityThread$ApplicationThread android.app.ActivityThread.getApplicationThread()' on a null object reference
tools.timerTime$1$1.run(timerTime.java:71)
qui est :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
Intent i = new Intent(mCtx, MainActivity.class);
une idée?