簡體   English   中英

Android Studio錯誤類型不兼容

[英]Incompatible types Android Studio error

我創建了一個函數,我在return語句中出錯,為什么?

import android.app.Fragment;
@Override
public android.support.v4.app.Fragment getItem(int position) {

    Bundle bundle = new Bundle();
    bundle.putString(DeviceFragment.DescriptionKey,deviceDescription[position]);
    bundle.putInt(DeviceFragment.ImageIDKey, getDeviceImageID(position));

    DeviceFragment deviceFragment = new DeviceFragment();
    deviceFragment.setArguments(bundle);

    return deviceFragment;

錯誤:

Error:(38, 16) incompatible types
found   : com.example.sergiumereuta.swipeviewtest.DeviceFragment
required: android.support.v4.app.Fragment

我認為是因為你正在使用Fragment,並且同時支持Fragment。

如果重寫android.app.Fragment getItem(int position)而不是android.support.v4.app.Fragment getItem(int position)。

這可能是因為DeviceFragment擴展了android.app.Fragment而不是android.support.v4.app.Fragment

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM