1

我有一个打开联系人活动的按钮(我希望用户选择一个联系人),按钮如下所示:

<Button 
    android:id="@+id/ok1"
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"
    style="@style/button_contact"
    android:onClick="contact"
/>

联系功能刚刚打开新活动:

public void contact(View view) {
    Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
    startActivityForResult(intent, PICK_CONTACT);
}

ContactsContract.Contacts.CONTENT_URI 由 API 级别 5 (ECLAIR) 提供。所以我在函数上方添加了@TargetApi(5):

@TargetApi(5)
public void contact(View view) {
   Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
   startActivityForResult(intent, PICK_CONTACT);
}

我在 onCreate 方法中隐藏了这个按钮:

if(Build.VERSION.SDK_INT < Build.VERSION_CODES.ECLAIR){
    findViewById(R.id.ok1).setVisibility(View.GONE);
}

但是当活动开始时我仍然有一个例外:

07-21 08:36:26.223: E/AndroidRuntime(591): Uncaught handler: thread main exiting due to uncaught exception
07-21 08:36:26.223: E/AndroidRuntime(591): java.lang.VerifyError: com.krinsen.world.ui.MultiplayerActivity
07-21 08:36:26.223: E/AndroidRuntime(591):  at java.lang.Class.newInstanceImpl(Native Method)
07-21 08:36:26.223: E/AndroidRuntime(591):  at java.lang.Class.newInstance(Class.java:1472)
07-21 08:36:26.223: E/AndroidRuntime(591):  at android.app.Instrumentation.newActivity(Instrumentation.java:1097)
07-21 08:36:26.223: E/AndroidRuntime(591):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2316)
07-21 08:36:26.223: E/AndroidRuntime(591):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2417)
07-21 08:36:26.223: E/AndroidRuntime(591):  at android.app.ActivityThread.access$2100(ActivityThread.java:116)
07-21 08:36:26.223: E/AndroidRuntime(591):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
07-21 08:36:26.223: E/AndroidRuntime(591):  at android.os.Handler.dispatchMessage(Handler.java:99)
07-21 08:36:26.223: E/AndroidRuntime(591):  at android.os.Looper.loop(Looper.java:123)
07-21 08:36:26.223: E/AndroidRuntime(591):  at android.app.ActivityThread.main(ActivityThread.java:4203)
07-21 08:36:26.223: E/AndroidRuntime(591):  at java.lang.reflect.Method.invokeNative(Native Method)
07-21 08:36:26.223: E/AndroidRuntime(591):  at java.lang.reflect.Method.invoke(Method.java:521)
07-21 08:36:26.223: E/AndroidRuntime(591):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
07-21 08:36:26.223: E/AndroidRuntime(591):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
07-21 08:36:26.223: E/AndroidRuntime(591):  at dalvik.system.NativeStart.main(Native Method)

这个例外什么也没告诉我。任何人都可以帮忙吗?如果我删除联系功能,活动会正常开始。但这不是解决方案,因为它不适用于新设备(当按钮可见时)。

4

0 回答 0