2012-12-07 41 views
1

在我的應用程序中,我使用Dialog片段作爲啓動畫面。所以它會在應用程序啓動時顯示啓動畫面。當我在Android版本3以下的設備上運行應用程序時,它顯示「No such method error:getFragmentManager」這樣的錯誤。我看到它可以通過使用getSupportFragmentManager()來解決。但是當我使用它時,Splash對話框不顯示。請幫助我..Thanks提前...當在android中使用getfragmentmanager()時出現「沒有這樣的方法錯誤」

主要活動=>

 ft = getFragmentManager().beginTransaction(); //Here I am using getFragmentManager 
    newFragment = SplashDialogFragment.newInstance(); 
    newFragment.show(MainActivity.ft, "dialog"); 

這裏是我的開機畫面片段=>

public class SplashDialogFragment extends DialogFragment { 

    private EditText mEditText; 


    static SplashDialogFragment newInstance() { 
     SplashDialogFragment f = new SplashDialogFragment(); 
     return f; 
    } 
    public void EditNameDialog() { 
     // Empty constructor required for DialogFragment 
    } 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState);  
     setStyle(DialogFragment.STYLE_NO_TITLE, android.R.style.Theme);   
    } 

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
      Bundle savedInstanceState) { 

     View view = inflater.inflate(R.layout.splash_fragment, container); 


     return view; 
    } 

    public void show(FragmentManager supportFragmentManager, String string) { 
     // TODO Auto-generated method stub 


    } 


} 

和埃羅日誌=>

> 12-07 11:09:09.330: E/AndroidRuntime(628): FATAL EXCEPTION: main 
    12-07 11:09:09.330: E/AndroidRuntime(628): java.lang.NoSuchMethodError: com.myapp.mlm.MainActivity.getFragmentManager 
    12-07 11:09:09.330: E/AndroidRuntime(628): at com.madhyamam.malayalam2.MainActivity.onCreate(MainActivity.java:103) 
    12-07 11:09:09.330: E/AndroidRuntime(628): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 
    12-07 11:09:09.330: E/AndroidRuntime(628): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611) 
    12-07 11:09:09.330: E/AndroidRuntime(628): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663) 
    12-07 11:09:09.330: E/AndroidRuntime(628): at android.app.ActivityThread.access$1500(ActivityThread.java:117) 
    12-07 11:09:09.330: E/AndroidRuntime(628): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931) 
    12-07 11:09:09.330: E/AndroidRuntime(628): at android.os.Handler.dispatchMessage(Handler.java:99) 
    12-07 11:09:09.330: E/AndroidRuntime(628): at android.os.Looper.loop(Looper.java:123) 
    12-07 11:09:09.330: E/AndroidRuntime(628): at android.app.ActivityThread.main(ActivityThread.java:3683) 
    12-07 11:09:09.330: E/AndroidRuntime(628): at java.lang.reflect.Method.invokeNative(Native Method) 
    12-07 11:09:09.330: E/AndroidRuntime(628): at java.lang.reflect.Method.invoke(Method.java:507) 
    12-07 11:09:09.330: E/AndroidRuntime(628): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 
    12-07 11:09:09.330: E/AndroidRuntime(628): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 
    12-07 11:09:09.330: E/AndroidRuntime(628): at dalvik.system.NativeStart.main(Native Method) 

回答

2

我已經通過我的MainActivity延伸到FragmentActivity解決了這個問題。以前它是擴展Activity.After我已經使用getSupportFragmentManager沒有任何問題。

0

android.support.v4.app.Fragment;因爲片段是在API層面提供11 請訪問以下鏈接: - http://developer.android.com/reference/android/support/v4/app/package-summary.html

與此鏈接: - 在庫

java.lang.NoSuchMethodError when use getFragmentManager() with actionbarsherlock library

看跌支持jar文件添加在構建路徑中的文件夾和進口,例如Android .support.v4.app.Fragment,而不是以前。 希望這會對你有所幫助。

+0

我需要做些什麼來解決這個問題? –

相關問題