java - "FragmentLandscape" cannot be converted to Fragment -


i followed tutorial multiple layout fragments got error , have no idea is. i've searched v4 can't understand , don't know how apply code

package com.example.renboy94.fragmentsresponsive;  import android.app.activity; import android.app.fragmentmanager; import android.app.fragmenttransaction; import android.content.res.configuration; import android.os.bundle;   public class mainactivity extends activity{      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);          fragmentmanager fragmentmanager = getfragmentmanager();          fragmenttransaction fragmenttransaction = fragmentmanager.begintransaction();          configuration configinfo = getresources().getconfiguration();          if(configinfo.orientation == configuration.orientation_landscape){             fragmentlandscape fragmentlandscape = new fragmentlandscape();              fragmenttransaction.replace(r.id.landscape_fragment, fragmentlandscape);         }else{             fragmentportrait fragmentportrait = new fragmentportrait();              fragmenttransaction.replace(r.id.portrait_fragment, fragmentportrait);         }          fragmenttransaction.commit();      }  } 

fragmentlandscape class

package com.example.renboy94.fragmentsresponsive;  import  android.support.v4.app.fragment; import android.os.bundle; import android.support.annotation.nullable; import android.support.v4.app.fragment; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup;  public class fragmentlandscape extends fragment{  @nullable @override public view oncreateview(layoutinflater inflater, @nullable viewgroup   container, @nullable bundle savedinstancestate) {     return super.oncreateview(inflater, container,   savedinstancestate);   } } 

fragmentportrait

package com.example.renboy94.fragmentsresponsive;  import  android.support.v4.app.fragment; import android.os.bundle; import android.support.annotation.nullable; import android.support.v4.app.fragment; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup;  public class fragmentportrait extends fragment{  @nullable @override public view oncreateview(layoutinflater inflater, viewgroup container,  bundle savedinstancestate) {     return inflater.inflate(r.layout.portrait_fragment, container,   false);    }  } 

here error:

information:gradle tasks [:app:assembledebug]  :app:prebuild up-to-date :app:predebugbuild up-to-date :app:checkdebugmanifest :app:prereleasebuild up-to-date :app:preparecomandroidsupportappcompatv72220library up-to-date :app:preparecomandroidsupportsupportv42220library up-to-date :app:preparedebugdependencies :app:compiledebugaidl up-to-date :app:compiledebugrenderscript up-to-date :app:generatedebugbuildconfig up-to-date :app:generatedebugassets up-to-date :app:mergedebugassets up-to-date :app:generatedebugresvalues up-to-date :app:generatedebugresources up-to-date :app:mergedebugresources up-to-date :app:processdebugmanifest up-to-date :app:processdebugresources up-to-date :app:generatedebugsources up-to-date :app:processdebugjavares up-to-date :app:compiledebugjava     /home/renboy94/androidstudioprojects/fragmentsresponsive/app/src/main/java/com/example/renboy94/fragmentsresponsive/mainactivity.java error:(26, 66) error: incompatible types: fragmentlandscape cannot converted fragment error:(30, 65) error: incompatible types: fragmentportrait cannot converted fragment note: messages have been simplified; recompile -xdiags:verbose full output error:execution failed task ':app:compiledebugjava'. > compilation failed; see compiler error output details. information:build failed information:total time: 7.22 secs information:3 errors information:0 warnings information:see complete output in console 

your class fragmentlandscape must extend fragment.

if application's minimum api level 11 can use:

android.app.fragment

if wish support backward compatibility use:

android.support.v4.app.fragment

if want use support library in project:

edit build.gradle file , add dependency

defaultconfig {     minsdkversion 08     targetsdkversion 19     versioncode 1     versionname "1.0" }  buildtypes {     release {         runproguard false         proguardfiles getdefaultproguardfile('proguard-android.txt'), 'proguard-rules.txt'     } }  dependencies {     compile filetree(dir: 'libs', include: ['*.jar'])     compile 'com.android.support:support-v4:21.+' } 

Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -