Java getDrawingCache()返回空指针异常-Cordova插件

Java getDrawingCache()返回空指针异常-Cordova插件,java,android,cordova,phonegap-plugins,Java,Android,Cordova,Phonegap Plugins,这里我在Cordova插件中创建TextView的位图,但是getDrawingCache()方法返回null。。在谷歌搜索之后,我发现你需要添加setDrawingCacheEnabled(True),但这也没有帮助。所以请帮助…在设置文本之后添加这一行 @Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { t

这里我在Cordova插件中创建TextView的位图,但是getDrawingCache()方法返回null。。在谷歌搜索之后,我发现你需要添加setDrawingCacheEnabled(True),但这也没有帮助。所以请帮助…

在设置文本之后添加这一行

@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
try {
           Log.i(LOG_TAG, "[Custom toast] toastTitle: toastTitle \n toastText:" );

            Runnable runnable = new Runnable() {
                public void run() {
                    int duration = Toast.LENGTH_SHORT;


                    Context context = cordova.getActivity().getApplicationContext();

                    Toast toast = new Toast(context);
                    toast.setDuration(duration);    

                    LayoutInflater inflater = LayoutInflater.from(context);

                    Resources resources = context.getResources();                       
                    String packageName = context.getPackageName();

                    View appearance = inflater.inflate(resources.getIdentifier("main","layout",packageName),null);
                    toast.setView(appearance);

                    TextView toastTitleView = (TextView) appearance.findViewById(resources.getIdentifier("textView","id",packageName));
                    toastTitleView.setText("Title");

                    toastTitleView.buildDrawingCache();

                    Bitmap bmp = Bitmap.createBitmap(toastTitleView.getDrawingCache());


                    toast.show();
                }
            };
            this.cordova.getActivity().runOnUiThread(runnable);
            callbackContext.success();
            return true;


        callbackContext.error("Invalid action");
        return false;
    } catch (Exception e) {
        System.err.println("Exception: " + e.getMessage());
        callbackContext.error(e.getMessage());
        return false;
    }
}

谢谢Savan,这对我很有用:)
toastTitleView.layout(0, 0, 480, 800);