Bonjour,
Je souhaite surcharger la classe TextView. Pour cela j'ai créé une classe EditDateView :
Pour tester cette classe j'ai une activité de test :
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 package com.googlecode.android.widgets.DateSlider; import android.content.Context; import android.widget.TextView; public class EditDateView extends TextView { public EditDateView(Context context) { super(context); // TODO Auto-generated constructor stub } public void changerTexte(){ this.setText("ca a change de texte"); } }et mon layout " main " :
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 /* * Copyright (C) 2011 Daniel Berndt - Codeus Ltd - DateSlider * * This is a small demo application which demonstrates the use of the * dateSelector * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.googlecode.android.widgets.DateSlider; import java.util.Calendar; import android.app.Activity; import android.app.Dialog; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.TextView; import com.googlecode.android.widgets.DateSlider.labeler.TimeLabeler; /** * Small Demo activity which demonstrates the use of the DateSlideSelector * * @author Daniel Berndt - Codeus Ltd * */ public class Demo extends Activity { private EditDateView edv; @Override public void onCreate(Bundle savedInstanceState) { // load and initialise the Activity super.onCreate(savedInstanceState); setContentView(R.layout.main); edv = (EditDateView) this.findViewById(R.id.edv); // set up a listener for when the button is pressed edv.setOnClickListener(new OnClickListener() { public void onClick(View arg0) { // call the internal showDialog method using the predefined ID edv.changerTexte(); } }); }Maintenant voici mon erreur logcat :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <com.googlecode.android.widgets.DateSlider.EditDateView android:layout_height="wrap_content" android:layout_width="fill_parent" android:text="cestcluila" android:id="@+id/edv" /> </LinearLayout>Mon paquetage où j'ai ma classe s'apelle bien com.googlecode.android.widgets.DateSlider.
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 09-05 09:48:56.708: ERROR/AndroidRuntime(920): Uncaught handler: thread main exiting due to uncaught exception 09-05 09:48:56.977: ERROR/AndroidRuntime(920): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.googlecode.android.widgets.DateSlider/com.googlecode.android.widgets.DateSlider.Demo}: java.lang.ClassNotFoundException: com.googlecode.android.widgets.DateSlider.Demo in loader dalvik.system.PathClassLoader@43735ce8 09-05 09:48:56.977: ERROR/AndroidRuntime(920): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2194) 09-05 09:48:56.977: ERROR/AndroidRuntime(920): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2284) 09-05 09:48:56.977: ERROR/AndroidRuntime(920): at android.app.ActivityThread.access$1800(ActivityThread.java:112) 09-05 09:48:56.977: ERROR/AndroidRuntime(920): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1692) 09-05 09:48:56.977: ERROR/AndroidRuntime(920): at android.os.Handler.dispatchMessage(Handler.java:99) 09-05 09:48:56.977: ERROR/AndroidRuntime(920): at android.os.Looper.loop(Looper.java:123) 09-05 09:48:56.977: ERROR/AndroidRuntime(920): at android.app.ActivityThread.main(ActivityThread.java:3948) 09-05 09:48:56.977: ERROR/AndroidRuntime(920): at java.lang.reflect.Method.invokeNative(Native Method) 09-05 09:48:56.977: ERROR/AndroidRuntime(920): at java.lang.reflect.Method.invoke(Method.java:521) 09-05 09:48:56.977: ERROR/AndroidRuntime(920): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782) 09-05 09:48:56.977: ERROR/AndroidRuntime(920): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540) 09-05 09:48:56.977: ERROR/AndroidRuntime(920): at dalvik.system.NativeStart.main(Native Method) 09-05 09:48:56.977: ERROR/AndroidRuntime(920): Caused by: java.lang.ClassNotFoundException: com.googlecode.android.widgets.DateSlider.Demo in loader dalvik.system.PathClassLoader@43735ce8 09-05 09:48:56.977: ERROR/AndroidRuntime(920): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243) 09-05 09:48:56.977: ERROR/AndroidRuntime(920): at java.lang.ClassLoader.loadClass(ClassLoader.java:573) 09-05 09:48:56.977: ERROR/AndroidRuntime(920): at java.lang.ClassLoader.loadClass(ClassLoader.java:532) 09-05 09:48:56.977: ERROR/AndroidRuntime(920): at android.app.Instrumentation.newActivity(Instrumentation.java:1097) 09-05 09:48:56.977: ERROR/AndroidRuntime(920): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2186) 09-05 09:48:56.977: ERROR/AndroidRuntime(920): ... 11 more
Voilà, avez-vous des explications à mon problème ? Je vous remercie
Partager