Bonjour,
Lorsque je compile mon programme j'obtiens cette erreur
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 03-28 20:25:35.571 949-949/com.example.user.cercles E/AndroidRuntime﹕ FATAL EXCEPTION: main java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.user.cercles/com.example.user.cercles.MainActivity}: java.lang.NullPointerException at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1983) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084) at android.app.ActivityThread.access$600(ActivityThread.java:130) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:4745) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.NullPointerException at android.content.ContextWrapper.getResources(ContextWrapper.java:81) at android.view.View.<init>(View.java:3228) at com.example.user.cercles.MyView.<init>(MyView.java:25) at com.example.user.cercles.MainActivity.<init>(MainActivity.java:59) at java.lang.Class.newInstanceImpl(Native Method) at java.lang.Class.newInstance(Class.java:1319) at android.app.Instrumentation.newActivity(Instrumentation.java:1053) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1974) ************at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084) ************at android.app.ActivityThread.access$600(ActivityThread.java:130) ************at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195) ************at android.os.Handler.dispatchMessage(Handler.java:99) ************at android.os.Looper.loop(Looper.java:137) ************at android.app.ActivityThread.main(ActivityThread.java:4745) ************at java.lang.reflect.Method.invokeNative(Native Method) ************at java.lang.reflect.Method.invoke(Method.java:511) ************at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) ************at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) ************at dalvik.system.NativeStart.main(Native Method)
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 public class MainActivity extends ActionBarActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //setContentView(new MyView(this)); Button boutonOk = (Button)findViewById(R.id.ok); boutonOk.setOnClickListener(okOnClick); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } EditText varNbCercle; EditText varEpaisseur; String StrNbCercle; String StrEpaisseur; int intNbCercle; int intEpaisseur; MyView Cercle = new MyView(this); private View.OnClickListener okOnClick = new View.OnClickListener() { @Override public void onClick(View v) { varNbCercle = (EditText) findViewById(R.id.nbCercle); varEpaisseur = (EditText) findViewById(R.id.epaisseur); StrNbCercle = varNbCercle.getText().toString(); StrEpaisseur = varEpaisseur.getText().toString(); try { intNbCercle = Integer.parseInt(StrNbCercle); intEpaisseur = Integer.parseInt(StrEpaisseur); Cercle.setNbCercle(intNbCercle); Cercle.setEpaisseur(intEpaisseur); Cercle.invalidate();//force l'appel de onDraw() } catch (NumberFormatException nfe) {} } }; }
Partager