我们正在使用新的Java打印API,用于PrinterJob.printDialog(attributes)向用户显示对话框.
想要下次保存用户的设置,我想这样做:
PrintRequestAttributeSet attributes = loadAttributesFromPreferences();
if (printJob.printDialog(attributes)) {
// print, and then...
saveAttributesToPreferences(attributes);
}
Run Code Online (Sandbox Code Playgroud)
但是,我通过这样做发现,有时候(我还没弄清楚)属性是如何在内部获得一些不良数据,然后当你打印时,你会得到一个什么都没有的白页.然后代码将中毒的设置保存到首选项中,并且所有后续的打印运行也会中毒设置.此外,练习的整个点,使新运行的设置与用户为上一次运行选择的设置相同,将被取消,因为新对话框似乎不使用旧设置.
所以我想知道是否有正确的方法来做到这一点.当然,Sun并不打算用户每次启动应用程序时都必须选择打印机,页面大小,方向和边距设置.
编辑以显示存储方法的实现:
private PrintRequestAttributeSet loadAttributesFromPreferences()
{
PrintRequestAttributeSet attributes = null;
byte[] marshaledAttributes = preferences.getByteArray(PRINT_REQUEST_ATTRIBUTES_KEY, null);
if (marshaledAttributes != null)
{
try
{
@SuppressWarnings({"IOResourceOpenedButNotSafelyClosed"})
ObjectInput objectInput = new ObjectInputStream(new ByteArrayInputStream(marshaledAttributes));
attributes = (PrintRequestAttributeSet) objectInput.readObject();
}
catch (IOException e)
{
// Can occur due to invalid object data e.g. InvalidClassException, StreamCorruptedException
Logger.getLogger(getClass()).warn("Error trying to read print attributes from preferences", e);
}
catch (ClassNotFoundException …Run Code Online (Sandbox Code Playgroud) 你能告诉我如何以编程方式阻止Android Activity进入睡眠模式.或者我们可以在Android Manifest文件中声明与此相关的内容.
我和这里的一些人正在努力创业.我们目前正在使用Google OpenID API管理注册和登录我们的应用,但我们希望迁移到更简单的用户注册模式.为此,我们需要知道是否有一种方法可以检测到电子邮件(不是gmail)是否已经是Google帐户.有没有办法从Google Single Sign-on API获取此信息?
以前感谢您的帮助!:)
我一直在阅读胡子文档,看起来很酷:https: //github.com/defunkt/mustache
ruby代码和html标记之间有明显的区别.没有开始胡子项目,我的困惑是:如何处理生成标记的ruby?明显的例子是表单助手和link_to,更不用说任何自定义方法了.{{link_to ...}}是否合适(或可能)? - 在标记中包含代码.或者在视图ruby中定义自定义方法:{{whatever_link}}? - 这似乎不干,同样不受欢迎.胜利在哪里?
谢谢!
--Peter
我的应用程序包含SQLite.我的应用程序有时会收到以下错误
java.lang.RuntimeException: Unable to destroy activity {com.fitzsoftware.grocessaryList/com.fitzsoftware.grocessaryList.GrocessaryList}: android.database.sqlite.SQLiteException: unable to close due to unfinalised statements
at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3655)
at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3673)
at android.app.ActivityThread.access$2900(ActivityThread.java:125)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.database.sqlite.SQLiteException: unable to close due to unfinalised statements
at android.database.sqlite.SQLiteDatabase.dbclose(Native Method)
at android.database.sqlite.SQLiteDatabase.onAllReferencesReleased(SQLiteDatabase.java:320)
at android.database.sqlite.SQLiteDatabase.close(SQLiteDatabase.java:881)
at com.fitzsoftware.grocessaryList.GrocessaryList.onDestroy(GrocessaryList.java:103)
at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3642)
Run Code Online (Sandbox Code Playgroud)
我正在使用DataClass.dh.db.close()关闭Destroy()中的数据库; 为什么会出现这个错误.请给我解决方案.提前谢谢.
考虑一下这个POD:
struct T
{
int i;
char c;
};
Run Code Online (Sandbox Code Playgroud)
在哪个C++标准中,POD成员的要求是通过默认的c'tor引入(或者从标准开始)到初始化为零?
是的,这意味着没有用户指定的c'tor,'i'和'c'都将初始化为0.请参阅http://msdn.microsoft.com/en-us/library/80ks028k%28VS.80%29. ASPX
我必须在A和B页面,我想从A到B导航,然后在JSF中从B导航到A. 我在A的托管bean中设置托管属性B,反之亦然,但问题是我得到了像MANAGED BEAN CYCLIC DETECTION这样的错误.
<managed-bean>
<managed-bean-name>viewBulkMetalIssueBean</managed-bean-name>
<managed-bean-class>com.cc.jas.web.manufacturing.bulkmetalissue.ViewBulkMetalIssueBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
<managed-property>
<property-name>viewJobcardBean</property-name>
<property-class>com.cc.jas.web.manufacturing.jobcard.ViewJobcardBean</property-class>
<value>#{viewJobcardBean}</value>
</managed-property>
</managed-bean>
<managed-bean>
<managed-bean-name>viewJobcardBean</managed-bean-name>
<managed-bean-class>com.cc.jas.web.manufacturing.jobcard.ViewJobcardBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
<managed-property>
<property-name>viewBulkMetalIssueBean</property-name>
<property-class>com.cc.jas.web.manufacturing.bulkmetalissue.ViewBulkMetalIssueBean</property-class>
<value>#{viewBulkMetalIssueBean}</value>
</managed-property>
</managed-bean>
Run Code Online (Sandbox Code Playgroud)
这个问题有解决方案或替代解决方案吗?
我有一个关于从文本日志文件转换的数组的读取序列的问题.
由于在第一行[0]中的过程中我不需要读取文件头,是否有任何方法可以跳过读取行[0]并首先开始读取行[1]?
该程序利用foreach循环读取数组.并且有一种标记化方法,因此标记化需要foreach循环来重新调整数组的String格式.
请通过建议代码帮助!谢谢!
程序代码:
class Program
{
static void Main(string[] args)
{
System.Collections.Generic.IEnumerable<String> lines = File.ReadLines("C:\\syscrawl\\ntfs3.txt");
foreach (String r in lines) //Start reading from lines[1] first instead?
{
String[] token = r.Split(',');
}
}
}
Run Code Online (Sandbox Code Playgroud)
如果你需要日志文本文件,这里是一个例子:
Date,Size,Type,Mode,UID,GID,Meta,File Name // Lines[0]
Sun Jul 22 2001 02:37:46,73882,...b,r/rrwxrwxrwx,0,0,516-128-3,C:/WINDOWS/Help/digiras.chm // Lines [1]
Sun Jul 22 2001 02:44:18,10483,...b,r/rrwxrwxrwx,0,0,480-128-3,C:/WINDOWS/Help/cyycoins.chm
Sun Jul 22 2001 02:45:32,10743,...b,r/rrwxrwxrwx,0,0,482-128-3,C:/WINDOWS/Help/cyzcoins.chm
Sun Jul 22 2001 04:26:14,174020,...b,r/rrwxrwxrwx,0,0,798-128-3,C:/WINDOWS/system32/spool/drivers/color/kodak_dc.icm
Run Code Online (Sandbox Code Playgroud) 这就是我想要做的事情:
查询:
我创建了一个组合框,然后在运行时使用按钮填充它.我还创建了一个按钮,比如Button1循环浏览组框并删除这些按钮.这是我的Button1代码:
Public Sub removeControls()
For Each ctrl As Control In GroupBox1.Controls
GroupBox1.Controls.Remove(ctrl)
ctrl.Dispose()
Next
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
removeControls()
End Sub
Run Code Online (Sandbox Code Playgroud)
执行时,它只删除GroupBox1中的一些控件,而不是全部.你能解释我的代码中缺少什么使它工作吗?谢谢.