-1
`import android.support.v4.view.ViewPager; 
 public class Home extends Activity {
 private ViewPager mainViewPager;
    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.home); 
        mainViewPager = (ViewPager) findViewById(R.id.home_vp_pager); //the log will redirect me from DDMS to this line.
} 
}
`

通过 OTA 更新我的应用程序时,我的应用程序遇到了崩溃。这是我的错误日志

引起:java.lang.ClassCastException: android.support.v4.view.ViewPager 不能转换为 android.support.v4.view.ViewPager
12-26 16:47:43.067: E/AndroidRuntime(3821): 在 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2572) 12-26 16:47:43.067: E/AndroidRuntime(3821): 在 android. app.ActivityThread.handleLaunchActivity(ActivityThread.java:2654) 12-26 16:47:43.067: E/AndroidRuntime(3821): 在 android.app.ActivityThread.-wrap11(ActivityThread.java) 12-26 16:47:43.067 : E/AndroidRuntime(3821): 在 android.app.ActivityThread$H.handleMessage(ActivityThread.java:1488) 12-26 16:47:43.067: E/AndroidRuntime(3821): 在 android.os.Handler.dispatchMessage( Handler.java:111) 12-26 16:47:43.067: E/AndroidRuntime(3821): 在 android.os.Looper.loop(Looper.java:207) 12-26 16:47:43.067: E/AndroidRuntime( 3821): 在 android.app.ActivityThread.main(ActivityThread.java:5728) 12-26 16:47:43.067: E/AndroidRuntime(3821): 在 java.lang。reflect.Method.invoke(Native Method) 12-26 16:47:43.067: E/AndroidRuntime(3821): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789) 12-26 16 :47:43.067: E/AndroidRuntime(3821): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679) 12-26 16:47:43.067: E/AndroidRuntime(3821): 原因: java.lang.ClassCastException: android.support.v4.view.ViewPager 无法转换为 android.support.v4.view.ViewPager 12-26 16:47:43.067: E/AndroidRuntime(3821): at com.android.home .Home.onCreate(Home.java:445) 12-26 16:47:43.067: E/AndroidRuntime(3821): 在 android.app.Activity.performCreate(Activity.java:6309) 12-26 16:47:43.067 : E/AndroidRuntime(3821): 在 android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1113) 12-26 16:47:43.067: E/AndroidRuntime(3821): 在 android.app。ActivityThread.performLaunchActivity(ActivityThread.java:2519) 12-26 16:47:43.067: E/AndroidRuntime(3821): ... 还有 9 个

我正在使用

安卓支持-v4.jar

甚至我的应用程序也反复显示此错误

新更新:

我正在使用

'compileSdkVersion 27
buildToolsVersion '27.0.3'

defaultconfig{
 ......
 minSdkVersion 19
    targetSdkVersion 21
 ....
 }
 .................
  dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')

    implementation 'com.android.support:support-v4:27.1.1'
   }'
4

1 回答 1

0

尝试扩展 AppCompatActivity 而不是 Activity

于 2016-12-26T13:15:25.443 回答