我想打开一个FileDialog窗口进入用户主文件夹(即/ home/user或/ Users/unsername)
我使用System.getProperty读取用户主文件夹:
String homefolder = System.getProperty(user.home);
Run Code Online (Sandbox Code Playgroud)
变量包含正确的主文件夹.但是当我在FileDialog中设置filterpath时,它打开(在linux中)只有/ home级别没有进入用户主目录.
这是源代码:
FileDialog dialog = new FileDialog(shell);
dialog.setText("Choose a certificate");
String platform = SWT.getPlatform();
String homefolder = System.getProperty("user.home");
dialog.setFilterPath(homefolder);
Run Code Online (Sandbox Code Playgroud)
任何的想法?这是一个截图:

如何使用SWT InputDialog对象输入密码,用普通字符替换普通字符*?
还是不可能?
我有一个语言词典(即英语,意大利语等),基本上是一个文件,每行都有一个单词.
现在我想用一个方法创建一个类,该方法在输入中给出一个字符串,检查该字符串是否存在于该字典中.
我的想法是该方法返回一个布尔值.在伪代码中:
boolean checkWord(String s){
if(StringIsInDictionary) return true;
return false
}
Run Code Online (Sandbox Code Playgroud)
应该是实现该功能的最佳方式是什么?
考虑该文件将包含~65000个单词.
我在读取某些 XWindow ICCCM 属性时遇到问题。
问题实际上是当我尝试读取 _NET_WM_STATUS 属性时。我正在使用的功能是:
int get_property_value(Display* display, Window window,char *propname, long max_length,
unsigned long *nitems_return, unsigned char **prop_return){
int result;
Atom property;
Atom actual_type_return;
int actual_format_return;
unsigned long bytes_after_return;
unsigned char* prop_to_return;
unsigned long n_items;
printf("-----GET_PROPERTY_VALUE-------\n");
printf("\tPropname: %s\n", propname);
property = XInternAtom(display, propname, True);
if(property==None){
printf("\tWrong Atom\n");
return;
}
result = XGetWindowProperty(display, window, property, 0, /* long_offset */
(~0L), /* long_length */
False, /* delete */
AnyPropertyType, /* req_type */
&actual_type_return,
&actual_format_return,
&n_items, &bytes_after_return, &prop_to_return);
if (result …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个实现 MarshalXML 输出的 XML。但目前我面临几个问题。
我用于存储数据的结构是:
type Edition struct {
Launch string `xml:"launch" json:"launch"`
Code string `xml:"code" json:"code"`
Names []NameNode `xml:"names>name"`
Cards CardsComposition `xml:"cards" json:"cards,omitempty"`
Preconstructed PreconstructedInfo `xml:"preconstructed" json:"preconstructed,omitempty"`
Vault *struct{} `xml:"vault" json:"vault"`
Online *struct{} `xml:"online" json:"online"`
}
Run Code Online (Sandbox Code Playgroud)
我想要的是:如果未设置 Preconstructed 字段,请不要放置<preconstructed>标签(使用标准封送拆收器,即使它为空也将其放置)。
所以我所做的是:
func (preconstructed PreconstructedInfo) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
if (PreconstructedInfo{} == preconstructed) {
return nil
}
return e.EncodeElement(preconstructed, start)
}
Run Code Online (Sandbox Code Playgroud)
如果我使用它来编码单个版本实体,它显然有效。但是,如果我尝试对一系列 Edition 实体进行编码,则会出现以下错误:
runtime: goroutine stack exceeds 1000000000-byte limit
fatal error: stack overflow
Run Code Online (Sandbox Code Playgroud)
(数组是 ~200 个条目) …
我无法理解为什么我在实施"应用内结算"时会收到"RESULT_DEVELOPER_ERROR".
我做了什么:
与Google Play交流的开始是:
那我可以使用4个保留的产品ID吗?
我错过了什么吗?
我是Android/Java编程的新手,并尝试从webview.capturePicture()获取位图.但是,如果网页很长,则图片的高度太大而createBitmap()返回的内存不足.我的问题是:
任何帮助表示赞赏.
我正在开发一个从字符串中提取日期并将其转换为日期的函数。日期格式如下:
dd-mmm-yyyy
其中 mmm 是全部小写的 3 位月份名称。
这段代码如下:
if(queryLine.contains("Expiration Date:")){
String expString = queryLine.replace("Expiration Date:", "").trim();
DateFormat df = new SimpleDateFormat("dd-MMM-yyyy");
try {
log.info("Exp: " + queryLine.replace("Expiration Date:", "").trim());
expDate = df.parse(expString);
} catch (ParseException e) {
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
如果我在计算机 jvm 上尝试该代码,它可以正常工作并且可以毫无问题地转换日期,但是如果我尝试在 android 上运行它,则会出现以下错误:
java.text.ParseException: Unparseable date: "14-sep-2020"
at org.whoislibrary.servers.WhoisCom.parseResponse(WhoisCom.java:39)
at java.text.DateFormat.parse(DateFormat.java:626)
at org.whoislibrary.WhoisAbstract.executeQuery(WhoisAbstract.java:47)
at org.whoislibrary.WhoisCommand.executeQuery(WhoisCommand.java:72)
at org.HttpTest.HttpTestActivity.onCreate(HttpTestActivity.java:35)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1586)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1638)
at android.app.ActivityThread.access$1500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:928)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3647)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at …Run Code Online (Sandbox Code Playgroud) 我正在尝试捕捉蓝牙设备断开连接意图过滤器.我在onReceive中添加了一个日志,但它从未到达它并且没有显示在logcat中.我怀疑问题出在我的manifest.xml配置上:
表现:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.company"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="16" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<receiver android:name="com.company.MyReceiver" android:enabled="true" android:exported="true">
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.bluetooth.device.action.ACL_DISCONNECT_REQUESTED" />
<action android:name="android.bluetooth.adapter.action.CONNECTION_STATE_CHANGED" />
<action android:name="android.bluetooth.adapter.action.DISCOVERY_STARTED" />
</intent-filter>
</receiver>
<activity
android:name=".BTActivity"
android:label="BTActivity" >
</activity>
</application>
</manifest>
Run Code Online (Sandbox Code Playgroud)
MyReceiver扩展了BroadcastReceiver:
@Override
public void onReceive(Context context, Intent intent) {
Log.i("got-in", "got-in-");
// String action = intent.getAction();
BluetoothDevice device = intent
.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
Log.i("disconnect", device.getName());
Intent i = new Intent(context, BTActivity.class);
Bundle b …Run Code Online (Sandbox Code Playgroud) 我正在编写一个使用 xmllint 解析 rss 的小脚本。
现在我使用以下命令获取标题列表:
ITEMS=`echo "cat //title" | xmllint --shell rss.xml `
echo $ITEMS > tmpfile
Run Code Online (Sandbox Code Playgroud)
但它返回:
<title>xxx</title> ------- <title>yyy :)</title> ------- <title>zzzzzz</title>
Run Code Online (Sandbox Code Playgroud)
没有换行符或空格。现在我只对标题标签的文本内容感兴趣,如果可能的话,我想使用 for/while 循环浏览标题,例如:
for val in $ITEMS
do
echo $val
done
Run Code Online (Sandbox Code Playgroud)
怎么做?提前致谢
我正在我的应用中实施应用内结算功能.我刚刚实现了REQUEST_PURCHASE,CONFIRM_NOTIFICATION和CHECK_BILLING,它们工作正常.
现在我正在尝试实现REQUEST_TRANSACTIONS方法,但我有一个问题,一旦我用sendBIllingRequest发送请求,我收到RESULT_DEVELOPER_ERROR(5)的RESPONSE_CODE响应.
这就是我提出请求的方式:
Log.d(TAG, "Action equals RESTORE_TRANSACTIONS");
Bundle request = makeRequestBundle("RESTORE_TRANSACTIONS");
request.putLong("NONCE", BillingSecurity.newNonce());
try {
Bundle response = mService.sendBillingRequest(request);
int response_code = response.getInt("RESPONSE_CODE", -1);
Log.d(TAG, "RESPONSE Restore: " + response_code);
restored=true;
} catch (RemoteException e) {
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
我读了其他问题,当禁用调试模式时需要启动RESTORE_TRANSACTIONS.我从Manifest禁用它(我清除了字段,因为如果我把假LogCat没有显示任何调试打印),那么这是我的Android Manifest:
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="resistorcalc.main"
android:versionName="3.0" android:versionCode="9">
<uses-sdk android:minSdkVersion="8"></uses-sdk>
<uses-permission android:name="com.android.vending.BILLING" />
<application android:label="@string/app_name" android:name=".App" android:icon="@drawable/resistoricon">
<activity android:name=".launchActivity"
android:label="@string/app_name" android:screenOrientation="portrait" android:clearTaskOnLaunch="true" android:finishOnTaskLaunch="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:launchMode="standard" android:label="@string/app_name" android:name="SupportusActivity" android:finishOnTaskLaunch="true" android:clearTaskOnLaunch="true" android:screenOrientation="portrait"></activity>
<activity android:launchMode="standard" …Run Code Online (Sandbox Code Playgroud) 我在尝试访问私有属性时遇到了一种奇怪的行为.请考虑以下代码:
class CLASSE
{
private:
int X;
public:
CLASSE(int x) { X = x; }
int GetX(){ return X; }
void CopyFrom(CLASSE Src){ X = Src.X; }
};
main ()
{
CLASSE A = 123;
CLASSE B = 456;
cout << "A = " << A.GetX() << endl;
cout << "B = " << B.GetX() << endl << endl;
A.CopyFrom (B);
cout << "A = " << A.GetX() << endl;
// cout << "A = " << A.X << endl; …Run Code Online (Sandbox Code Playgroud) 我希望在我的应用程序中有一个alertdialog,每次显示时都会更新其消息.这是因为对话框值取决于应用程序上的某些值.
现在我尝试使用showDialog方法:
@Override
public boolean onTouch(View arg0, MotionEvent arg1) {
showDialog(RESULT_DIALOG);
return false;
}
Run Code Online (Sandbox Code Playgroud)
但是一旦创建了对话框,它就不会改变消息(我知道如果创建了对话框,它会使用已启动的版本).
我的onCreateDialog方法代码是:
public Dialog onCreateDialog(int dialogId) {
AlertDialog dialog;
switch(dialogId) {
case RESULT_DIALOG:
// do the work to define the pause Dialog
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(localTv.getText())
.setCancelable(false)
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
dialog = builder.create();
break;
default:
dialog = null;
}
return dialog;
}
Run Code Online (Sandbox Code Playgroud)
有一种方法可以更新AlertDialog的内容.实际上我每次调用onTouch事件时都会创建一个新的对话框.但我不确定这是解决这个问题最干净的方法.
任何的想法?谢谢 :)
java ×7
android ×6
swt ×2
xml ×2
algorithm ×1
bash ×1
bluetooth ×1
c ×1
c++ ×1
date ×1
date-format ×1
dialog ×1
dictionary ×1
exception ×1
filedialog ×1
go ×1
jface ×1
linux ×1
marshalling ×1
parsing ×1
x11 ×1
xlib ×1
xml-parsing ×1
xmllint ×1