尝试将 TextView 文本复制到剪贴板时,我做错了吗?
我的活动课程中的代码:
@Override
public boolean onContextItemSelected(MenuItem item) {
String selectedItem = item.getTitle().toString().trim();
try {
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip;
if (selectedItem.equals("Copy Query")) {
clip = ClipData.newPlainText("Query",tv1.getText());
clipboard.setPrimaryClip(clip);
}
return true;
}
错误:
04-17 03:10:54.056: E/AndroidRuntime(503): FATAL EXCEPTION: main
04-17 03:10:54.056: E/AndroidRuntime(503): java.lang.NoClassDefFoundError: android.content.ClipboardManager
04-17 03:10:54.056: E/AndroidRuntime(503): at com.ewe.radixcalculator.CalculatorActivity.onContextItemSelected(CalculatorActivity.java:68)
04-17 03:10:54.056: E/AndroidRuntime(503): at android.app.Activity.onMenuItemSelected(Activity.java:2199)
04-17 03:10:54.056: E/AndroidRuntime(503): at com.android.internal.policy.impl.PhoneWindow$ContextMenuCallback.onMenuItemSelected(PhoneWindow.java:2744)
04-17 03:10:54.056: E/AndroidRuntime(503): at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:143)
04-17 03:10:54.056: E/AndroidRuntime(503): at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:855)
04-17 03:10:54.056: E/AndroidRuntime(503): at com.android.internal.view.menu.MenuDialogHelper.onClick(MenuDialogHelper.java:137)
04-17 03:10:54.056: E/AndroidRuntime(503): at com.android.internal.app.AlertController$AlertParams$3.onItemClick(AlertController.java:874)
04-17 03:10:54.056: E/AndroidRuntime(503): at android.widget.AdapterView.performItemClick(AdapterView.java:284)
04-17 03:10:54.056: E/AndroidRuntime(503): at android.widget.ListView.performItemClick(ListView.java:3382)
04-17 03:10:54.056: E/AndroidRuntime(503): at android.widget.AbsListView$PerformClick.run(AbsListView.java:1696)
04-17 03:10:54.056: E/AndroidRuntime(503): at android.os.Handler.handleCallback(Handler.java:587)
04-17 03:10:54.056: E/AndroidRuntime(503): at android.os.Handler.dispatchMessage(Handler.java:92)
04-17 03:10:54.056: E/AndroidRuntime(503): at android.os.Looper.loop(Looper.java:123)
04-17 03:10:54.056: E/AndroidRuntime(503): at android.app.ActivityThread.main(ActivityThread.java:4627)
04-17 03:10:54.056: E/AndroidRuntime(503): at java.lang.reflect.Method.invokeNative(Native Method)
04-17 03:10:54.056: E/AndroidRuntime(503): at java.lang.reflect.Method.invoke(Method.java:521)
04-17 03:10:54.056: E/AndroidRuntime(503): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-17 03:10:54.056: E/AndroidRuntime(503): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-17 03:10:54.056: E/AndroidRuntime(503): at dalvik.system.NativeStart.main(Native Method)
04-17 03:10:54.056: E/AndroidRuntime(503): Caused by: java.lang.ClassNotFoundException: android.content.ClipboardManager in loader dalvik.system.PathClassLoader[/data/app/com.ewe.radixcalculator-2.apk]
04-17 03:10:54.056: E/AndroidRuntime(503): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
04-17 03:10:54.056: E/AndroidRuntime(503): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
04-17 03:10:54.056: E/AndroidRuntime(503): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)