我正在尝试编写dashclock扩展名,所以我从example-extension开始
但我无法使其正常运行。我可以在扩展列表中的dashclock设置中看到此示例扩展,但它不在实际的dashclock小部件上。该堆栈跟踪会定期在背景中崩溃:
02-22 17:04:31.118: E/AndroidRuntime(25888): FATAL EXCEPTION: main
02-22 17:04:31.118: E/AndroidRuntime(25888): java.lang.RuntimeException: Unable to instantiate service com.example.dashclock.exampleextension.ExampleExtension: java.lang.ClassNotFoundException: Didn't find class "com.example.dashclock.exampleextension.ExampleExtension" on path: /data/app/com.example.dashclock.exampleextension-1.apk
02-22 17:04:31.118: E/AndroidRuntime(25888): at android.app.ActivityThread.handleCreateService(ActivityThread.java:2513)
02-22 17:04:31.118: E/AndroidRuntime(25888): at android.app.ActivityThread.access$1600(ActivityThread.java:141)
02-22 17:04:31.118: E/AndroidRuntime(25888): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
02-22 17:04:31.118: E/AndroidRuntime(25888): at android.os.Handler.dispatchMessage(Handler.java:99)
02-22 17:04:31.118: E/AndroidRuntime(25888): at android.os.Looper.loop(Looper.java:137)
02-22 17:04:31.118: E/AndroidRuntime(25888): at android.app.ActivityThread.main(ActivityThread.java:5041)
02-22 17:04:31.118: E/AndroidRuntime(25888): at java.lang.reflect.Method.invokeNative(Native Method)
02-22 17:04:31.118: E/AndroidRuntime(25888): at java.lang.reflect.Method.invoke(Method.java:511)
02-22 17:04:31.118: E/AndroidRuntime(25888): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
02-22 17:04:31.118: E/AndroidRuntime(25888): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
02-22 17:04:31.118: E/AndroidRuntime(25888): at dalvik.system.NativeStart.main(Native Method)
02-22 17:04:31.118: E/AndroidRuntime(25888): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.dashclock.exampleextension.ExampleExtension" on path: /data/app/com.example.dashclock.exampleextension-1.apk
02-22 17:04:31.118: E/AndroidRuntime(25888): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
02-22 17:04:31.118: E/AndroidRuntime(25888): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
02-22 17:04:31.118: E/AndroidRuntime(25888): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
02-22 17:04:31.118: E/AndroidRuntime(25888): at android.app.ActivityThread.handleCreateService(ActivityThread.java:2510)
02-22 17:04:31.118: E/AndroidRuntime(25888): ... 10 more
感谢帮助
最佳答案
错误:
java.lang.ClassNotFoundException:找不到类
路径上的“ com.example.dashclock.exampleextension.ExampleExtension”:
/data/app/com.example.dashclock.exampleextension-1.apk
这意味着它无法找到应位于ExampleExtension.java
com.example.dash
包中的clock.exampleextension
首先,不要将示例文件导入eclipse中,启动一个全新的Android应用程序
询问时取消选择创建活动按钮
创建完成后,右键单击src文件夹并添加一个程序包。
然后右键单击该程序包并创建一个新类。
这个新课程将是您的扩展。
从Dashclock网站here获取2个jar文件
将它们拖到您的libs文件夹中
将此添加到清单
<application android:label="@string/app_name"
android:icon="@drawable/ic_extension_yourIcon"
android:theme="@android:style/Theme.Holo">
<service android:name=".YourExtension"
android:icon="@drawable/ic_extension_your_icon"
android:label="@string/your_extension_title"
android:permission="com.google.android.apps.dashclock.permission.READ_EXTENSION_DATA">
<intent-filter>
<action android:name="com.google.android.apps.dashclock.Extension" />
</intent-filter>
<meta-data android:name="protocolVersion" android:value="1" />
<meta-data android:name="description"
android:value="@string/your_extension_description" />
</service>
</application>
保存清单,找到红线指示的错误,然后将适当的字符串添加到您的strings.xml中
这是一个空的扩展类
public class YourExtension extends DashClockExtension {
@Override
protected void onUpdateData(int reason) {
publishUpdate(new ExtensionData()
.visible(true)
.icon(R.drawable.ic_extension_yourIcon)
.status("This is the text when minimized")
.expandedTitle("This is the white Title text when expanded")
.expandedBody("This is the grey footer text when expanded")
.clickIntent(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"))));
}
}