截圖方法,我一直試圖讓這個代碼片段內工作。這段代碼在一個Activity中運行良好,但是我無法讓它在這個片段中工作。採取內部片段
當我點擊一個按鈕,它會調用takeScreenshot方法。
這是截圖代碼:
public Bitmap takeScreenshot() {
View rootView = findViewById(android.R.id.content).getRootView();
rootView.setDrawingCacheEnabled(true);
return rootView.getDrawingCache();
}
的「findViewById」這不是由於片段被認可。
我已經試過:
View rootView = getView().findViewById(android.R.id.content).getRootView();
,但它不工作要麼。我得到
07-25 09:37:32.746: E/AndroidRuntime(31221): FATAL EXCEPTION: main
07-25 09:37:32.746: E/AndroidRuntime(31221): java.lang.NullPointerException
07-25 09:37:32.746: E/AndroidRuntime(31221): at com.dream3ncore.thefinalwordcounts.level01.Song01.takeScreenshot(Song01.java:763)
07-25 09:37:32.746: E/AndroidRuntime(31221): at com.dream3ncore.thefinalwordcounts.level01.Song01.onClick(Song01.java:152)
07-25 09:37:32.746: E/AndroidRuntime(31221): at android.view.View.performClick(View.java:4211)
07-25 09:37:32.746: E/AndroidRuntime(31221): at android.view.View$PerformClick.run(View.java:17362)
07-25 09:37:32.746: E/AndroidRuntime(31221): at android.os.Handler.handleCallback(Handler.java:725)
07-25 09:37:32.746: E/AndroidRuntime(31221): at android.os.Handler.dispatchMessage(Handler.java:92)
07-25 09:37:32.746: E/AndroidRuntime(31221): at android.os.Looper.loop(Looper.java:137)
07-25 09:37:32.746: E/AndroidRuntime(31221): at android.app.ActivityThread.main(ActivityThread.java:5227)
07-25 09:37:32.746: E/AndroidRuntime(31221): at java.lang.reflect.Method.invokeNative(Native Method)
07-25 09:37:32.746: E/AndroidRuntime(31221): at java.lang.reflect.Method.invoke(Method.java:511)
07-25 09:37:32.746: E/AndroidRuntime(31221): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
07-25 09:37:32.746: E/AndroidRuntime(31221): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
07-25 09:37:32.746: E/AndroidRuntime(31221): at dalvik.system.NativeStart.main(Native Method)
任何幫助將不勝感激。