我在使用DocumentFilter后向JTextArea附加文本时遇到问题,我需要在从文件上传文本后在JTextArea上追加一个字符串,并从另一个JFrame的JTextArea返回一个字符串到指定的JTextArea
当我没有使用DocumentFilter.FilterBypass时,一切都很完美,直到我添加它.它仍然有效但只有在没有添加逗号(,)或空格("")时才有效.这与我给出的规范不符.
我怎么解决这个问题?或者是否有任何算法或实现没有给出这个问题?
这是用于过滤长度的insertString代码,仅允许空格和逗号
public void insertString(FilterBypass fb, int offset, String string, AttributeSet attr) throws BadLocationException {
// if (string == null || string.trim().equals("") || string.equals(","))
// {
// return;
// }
if (isNumeric(string)) {
// if (this.length > 0 && fb.getDocument().getLength() +
// string.length()
// > this.length) {
// return;
// }
if (fb.getDocument().getLength() + string.length() > this.length || string.trim().equals("") || string.equals(",")) {
this.insertString(fb, offset, string, attr);
}
// if (string == null || string.trim().equals("") ||
// string.equals(",")) { …Run Code Online (Sandbox Code Playgroud) 我在postexecute()上执行AlertDialog时遇到问题.抛出此异常引起:java.lang.RuntimeException:无法在未调用Looper.prepare()的线程内创建处理程序或者,当我放置AlertDialog.Builder时,它只是没有工作Pls帮助.同样在输入错误密码的情况下,该过程终止.如果用户名或密码无效,我怎样才能调用Toast方法以下是代码片段
public void Login() {
// Toast.makeText(getBaseContext(), pass.getText() + " "
// +user.getText(),
// Toast.LENGTH_SHORT).show();
String url = "http://107.20.195.151/mcast_ws/" + "?user="
+ user.getText().toString() + "&password="
+ pass.getText().toString();
result = getHttpResponse(url);
}
String result;
private String getHttpResponse(String location) {
result = "";
URL url = null;
Log.d(LOGTAG, " " + "location " + location);
try {
url = new URL(location);
} catch (MalformedURLException e) {
Log.e(LOGTAG, " " + "error" + e.getMessage());
}
if (url != null) {
try {
HttpURLConnection …Run Code Online (Sandbox Code Playgroud) 我正在尝试从文件读取数组.我尝试了两种不同的风格,两种都不起作用.以下是两种风格.
public class FileRead {
int i;
String a[] = new String[2];
public void read() throws FileNotFoundException {
//Z means: "The end of the input but for the final terminator, if any"
a[i] = new Scanner(new File("C:\\Users\\nnanna\\Documents\\login.txt")).useDelimiter("\\n").next();
for(i=0; i<=a.length; i++){
System.out.println("" + a[i]);
}
}
public static void main(String args[]) throws FileNotFoundException{
new FileRead().read();
}
}
Run Code Online (Sandbox Code Playgroud)
public class FileReadExample {
private int j = 0;
String path = null;
public void fileRead(File file){
StringBuilder attachPhoneNumber = new StringBuilder(); …Run Code Online (Sandbox Code Playgroud)