Salut a tous. j'essaie de faire démarrer une activité par un service mais a l’exécution de l'application j'ai l'erreur ci-dessous dans le LogCat :
voici mon Activité
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 07-31 11:01:23.318: E/AndroidRuntime(1904): FATAL EXCEPTION: main 07-31 11:01:23.318: E/AndroidRuntime(1904): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.malambi.beamme/com.malambi.beamme.DialogAlert}: java.lang.InstantiationException: com.malambi.beamme.DialogAlert 07-31 11:01:23.318: E/AndroidRuntime(1904): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585) 07-31 11:01:23.318: E/AndroidRuntime(1904): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679) 07-31 11:01:23.318: E/AndroidRuntime(1904): at android.app.ActivityThread.access$2300(ActivityThread.java:125) 07-31 11:01:23.318: E/AndroidRuntime(1904): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033) 07-31 11:01:23.318: E/AndroidRuntime(1904): at android.os.Handler.dispatchMessage(Handler.java:99) 07-31 11:01:23.318: E/AndroidRuntime(1904): at android.os.Looper.loop(Looper.java:123) 07-31 11:01:23.318: E/AndroidRuntime(1904): at android.app.ActivityThread.main(ActivityThread.java:4627) 07-31 11:01:23.318: E/AndroidRuntime(1904): at java.lang.reflect.Method.invokeNative(Native Method) 07-31 11:01:23.318: E/AndroidRuntime(1904): at java.lang.reflect.Method.invoke(Method.java:521) 07-31 11:01:23.318: E/AndroidRuntime(1904): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:885) 07-31 11:01:23.318: E/AndroidRuntime(1904): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:643) 07-31 11:01:23.318: E/AndroidRuntime(1904): at dalvik.system.NativeStart.main(Native Method) 07-31 11:01:23.318: E/AndroidRuntime(1904): Caused by: java.lang.InstantiationException: com.malambi.beamme.DialogAlert 07-31 11:01:23.318: E/AndroidRuntime(1904): at java.lang.Class.newInstanceImpl(Native Method) 07-31 11:01:23.318: E/AndroidRuntime(1904): at java.lang.Class.newInstance(Class.java:1429) 07-31 11:01:23.318: E/AndroidRuntime(1904): at android.app.Instrumentation.newActivity(Instrumentation.java:1021) 07-31 11:01:23.318: E/AndroidRuntime(1904): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577) 07-31 11:01:23.318: E/AndroidRuntime(1904): ... 11 more
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 import android.os.Bundle; import android.app.Activity; import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; import android.util.Log; import android.view.Menu; import android.view.View; import android.widget.Button; import android.widget.Toast; public class DialogAlert extends Activity { Context context ; public DialogAlert (Context context){ this.context = context ; } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.alert); showDialog() ; } /*@Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.dialog_alert, menu); return true; }*/ public void showDialog() { Button btnAlert = (Button) findViewById(R.id.button1); btnAlert.setOnClickListener(new View.OnClickListener() { public void onClick(View arg0) { // Creating alert Dialog with one Button AlertDialog alertDialog = new AlertDialog.Builder(DialogAlert.this).create(); // Setting Dialog Title alertDialog.setTitle("Alert Dialog"); // Setting Dialog Message alertDialog.setMessage("Welcome to AndroidHive.info"); // Setting Icon to Dialog alertDialog.setIcon(R.drawable.tick); // Setting OK Button alertDialog.setButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // Write your code here to execute after dialog // closed Toast.makeText(getApplicationContext(), "You clicked on OK", Toast.LENGTH_SHORT) .show(); } }); // Showing Alert Message alertDialog.show(); } }); } public void doPositiveClick() { // Do stuff here. Toast.makeText(context, "Click sur Ok", Toast.LENGTH_SHORT).show(); Log.i("FragmentAlertDialog", "Positive click!"); } public void doNegativeClick() { // Do stuff here. Toast.makeText(context, "click sur Annuler", Toast.LENGTH_SHORT).show(); Log.i("FragmentAlertDialog", "Negative click!"); } }
j'effectue le démarrage de cette manière
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 public void StartActivity(){ Intent dialogIntent = new Intent(getBaseContext(), DialogAlert.class); dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); getApplication().startActivity(dialogIntent); } @Override public int onStartCommand(Intent intent, int flags, int startId) { Toast.makeText(this, "Demarrage du service", Toast.LENGTH_SHORT).show(); try { StartActivity() ; //bip.playSound(getApplicationContext()) ; // tone.startTone(8,8000); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SecurityException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalStateException e) { // TODO Auto-generated catch block e.printStackTrace(); } //timer.schedule(receivehelper.stock, 1000 , 1000) ; return super.onStartCommand(intent, flags, startId); }
Partager