[关闭]
@natsumi 2016-06-08T07:33:26.000000Z 字数 1181 阅读 1292

Acitivity打不开

Android


stackoverflow真是一个神奇的网站!
http://stackoverflow.com/questions/32109333/appcompatactivity-error-with-android-studio

错误信息类似下面这样~
其实还没有到E的几倍,是I和W,所以一直没注意到==

  1. 08-20 10:53:23.605 24192-24192/com.mkapp.apps.demo1 I/dalvikvm Could not find method android.support.v7.app.AppCompatActivity.onCreate, referenced from method com.mkapp.apps.demo1.TourActivity.onCreate
  2. 08-20 10:53:23.605 24192-24192/com.mkapp.apps.demo1 W/dalvikvm VFY: unable to resolve virtual method 8393: Landroid/support/v7/app/AppCompatActivity;.onCreate (Landroid/os/Bundle;Landroid/os/PersistableBundle;)V

这是为什么呢?
是因为targetSDK版本是23,编译版本也是23,但是
onCreate (Bundle savedInstanceState, PersistableBundle persistentState)方法 available only from API level 21.

会产生问题的代码:

  1. public class TourActivity extends AppCompatActivity {
  2. @Override
  3. protected void onCreate(Bundle savedInstanceState) {
  4. super.onCreate(savedInstanceState, new PersistableBundle());
  5. }
  6. @Override
  7. public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) {
  8. super.onCreate(savedInstanceState, persistentState);
  9. }
  10. }

应该检查哪里用到PersistableBundle,然后删除它
正确的代码:

  1. public class TourActivity extends AppCompatActivity {
  2. @Override
  3. protected void onCreate(Bundle savedInstanceState) {
  4. super.onCreate(savedInstanceState);
  5. }
  6. }
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注