- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在将 String
转换为 UTF-8 时遇到问题。
我尝试了这些转换方法,但结果不正确:
String fname = new String(_fnameText.getText().toString().getBytes(UTF8));
String fname = URLEncoder.encode(_fnameText.getText().toString(),"UTF8");
第一个结果如下:?????? ??????
第二个的结果如下:%30%D%40.....
如何将字符串
转换为UTF-8?
这是我的代码:
public void signup() {
String name;
String fname;
String lname;
String password;
final Charset UTF8=Charset.forName("utf-8");
name = new String();
fname = new String(_fnameText.getText().toString().getBytes(UTF8));
lname = new String(_lnameText.getText().toString().getBytes(UTF8));
password = new String(_passwordText.getText().toString().getBytes(UTF8));
// TODO: Implement your own signup logic here.
if(name!=null && fname!=null && lname!=null && password!=null) {
if (isConnected()) {
if (validate()) {
_signupButton.setEnabled(false);
jsonSignup = new JSON_Signup(SignupActivity.this, "http://teroject.com/api/android.php", name, password);
jsonSignup.valuesForServer.add(new BasicNameValuePair("api_key", "teroapi_php_java_1395"));
jsonSignup.valuesForServer.add(new BasicNameValuePair("api_function", "register"));
jsonSignup.valuesForServer.add(new BasicNameValuePair("username", name));
jsonSignup.valuesForServer.add(new BasicNameValuePair("password", password));
jsonSignup.valuesForServer.add(new BasicNameValuePair("fname", fname));
jsonSignup.valuesForServer.add(new BasicNameValuePair("lname", lname));
jsonSignup.execute();
}
}
}else {
Toast.makeText(getApplicationContext(),"لطفا از کاراکتر های مجاز استفاده کنید",Toast.LENGTH_SHORT).show();
}
}
public JSON_Signup(Context context,String url,String username,String password){
this.context=context;
this.url=url;
this.username=username;
this.password=password;
progressDialog=new ProgressDialog(this.context);
}
@Override
protected void onPreExecute() {
progressDialog.setMessage("در حال ثبت نام لطفا صبر کنید....");
progressDialog.show();
progressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
public void onCancel(DialogInterface arg0) {
JSON_Signup.this.cancel(true);
}
});
}
@Override
protected String doInBackground(String... params) {
try {
// Set up HTTP post
// HttpClient is more then less deprecated. Need to change to URLConnection
HttpParams httpParameters = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParameters, 20000);
HttpConnectionParams.setSoTimeout(httpParameters, 20000);
DefaultHttpClient httpClient = new DefaultHttpClient(httpParameters);
HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(new UrlEncodedFormEntity(valuesForServer));
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
StatusLine statusLine = httpResponse.getStatusLine();
if (statusLine.getStatusCode() == HttpStatus.SC_OK) {
// Read content & Log
inputStream = httpEntity.getContent();
}else{
return null;
}
}catch (NetworkOnMainThreadException e7){
Log.i("Network on Main Thread", e7 + "");
e7.printStackTrace();
return null;
} catch(SocketTimeoutException e6){
Log.i("Connection Timeout", e6 + "");
e6.printStackTrace();
return null;
} catch (UnsupportedEncodingException e1) {
Log.i("Unsupported Encoding",e1+"");
e1.printStackTrace();
return null;
} catch (ClientProtocolException e2) {
Log.i("Client Protocol", e2 + "");
e2.printStackTrace();
return null;
} catch (IllegalStateException e3) {
Log.i("Illegal State", e3 + "");
e3.printStackTrace();
return null;
} catch (IOException e4) {
Log.i("Exception", e4 + "");
e4.printStackTrace();
return null;
}
// Convert response to string using String Builder
if(inputStream!=null) {
try {
BufferedReader bReader = new BufferedReader(new InputStreamReader(inputStream, "utf-8"), 8);
StringBuilder sBuilder = new StringBuilder();
String line = null;
while ((line = bReader.readLine()) != null) {
sBuilder.append(line + "\n");
}
inputStream.close();
result = sBuilder.toString();
} catch (Exception e) {
Log.i("Exception", e + "");
return null;
}
}else {
return null;
}
return result;
}
@Override
protected void onPostExecute(String result) {
if (result != null) {
//parse JSON data
try {
mainFile = new JSONObject(result);
success = mainFile.getString("success");
message = mainFile.getString("message");
if (success.equals("1")) {
_signupButton.setEnabled(true);
Toast.makeText(this.context, message, Toast.LENGTH_LONG).show();
if (isConnected()) {
JSON json;
json = new JSON(this.context, "http://teroject.com/api/android.php",
this.username,this.password);
json.valuesForServer.add(new BasicNameValuePair("api_key", "teroapi_php_java_1395"));
json.valuesForServer.add(new BasicNameValuePair("api_function", "login"));
json.valuesForServer.add(new BasicNameValuePair("username",this.username));
json.valuesForServer.add(new BasicNameValuePair("password",this.password));
json.execute();
}
} else if (success.equals("0")) {
Toast.makeText(this.context, message, Toast.LENGTH_LONG).show();
_signupButton.setEnabled(true);
}
this.progressDialog.dismiss();
} catch (JSONException e) {
Toast.makeText(this.context, e + "", Toast.LENGTH_SHORT).show();
_signupButton.setEnabled(true);
this.progressDialog.dismiss();
}
}else {
_signupButton.setEnabled(true);
progressDialog.dismiss();
Toast.makeText(this.context,"خطا در برقراری ارتباط",Toast.LENGTH_LONG).show();
}
}
}
这是日志:
08-02 01:22:59.185 1108-1159/? E/ActivityManager: Invalid thumbnail dimensions: 384x384
08-02 01:22:59.445 15868-15868/? E/chromium: [ERROR:layer_tree_host_impl.cc(2218)] Forcing zero-copy tile initialization as worker context is missing
08-02 01:23:00.349 271-822/? E/BandwidthController: [LG DATA] No such appUid: 10044
08-02 01:23:00.767 275-1078/? E/audio_hw_primary: select_devices: enter and usecase(1)
08-02 01:23:00.767 275-1078/? E/audio_hw_primary: enable_snd_device: enter 2
08-02 01:23:01.683 30716-30716/? E/MusicBrowser: [MusicUtils.java:633:getSmartShareVersion()] oooooo getSmartShareVersion ERROR :: android.content.pm.PackageManager$NameNotFoundException: com.lge.smartshare
08-02 01:23:02.445 32207-32207/? E/LGDMClient: [DmNotiService.java] [onCreate()] : [153] : DmNotiService.onCreate()
08-02 01:23:03.971 275-1324/? E/audio_hw_primary: disable_snd_device: enter 2
08-02 01:23:13.001 32587-32587/com.teroject.teroject E/GMPM: GoogleService failed to initialize, status: 10, Missing an expected resource: 'R.string.google_app_id' for initializing Google services. Possible causes are missing google-services.json or com.google.gms.google-services gradle plugin.
08-02 01:23:13.001 32587-32587/com.teroject.teroject E/GMPM: Scheduler not set. Not logging error/warn.
08-02 01:23:13.042 32587-32616/com.teroject.teroject E/GMPM: Uploading is not possible. App measurement disabled
08-02 01:23:13.724 32587-32587/com.teroject.teroject E/MediaProfilesEx-JNI: register_com_lge_media_MediaProfilesEx
08-02 01:23:13.724 32587-32587/com.teroject.teroject E/MediaRecorderEx-JNI: register_com_lge_media_MediaRecorderEx
08-02 01:23:13.726 32587-32587/com.teroject.teroject E/SurfaceControlEx: register_com_lge_view_SurfaceControlEx
08-02 01:23:13.736 32587-32587/com.teroject.teroject E/MediaPlayerEx-jni: register_com_lge_view_MediaPlayerEx
08-02 01:23:17.325 32587-32587/com.teroject.teroject E/CliptrayUtils: hideClipTrayIfNeeded() TextView is focused!! hideClipTray()
08-02 01:23:19.477 2636-2636/? E/NetworkScheduler.SR: Invalid parameter app
08-02 01:23:19.477 2636-2636/? E/NetworkScheduler.SR: Invalid package name : Perhaps you didn't include a PendingIntent in the extras?
08-02 01:23:19.579 2032-4467/? E/Drive.UninstallOperation: Package still installed com.teroject.teroject
08-02 01:23:21.148 275-1078/? E/audio_hw_primary: select_devices: enter and usecase(1)
08-02 01:23:21.148 275-1078/? E/audio_hw_primary: enable_snd_device: enter 2
08-02 01:23:21.577 409-409/? E/Finsky: [1] com.google.android.finsky.wear.bo.a(837): onConnectionFailed: ConnectionResult{statusCode=API_UNAVAILABLE, resolution=null, message=null}
08-02 01:23:22.539 275-1324/? E/audio_hw_primary: select_devices: enter and usecase(1)
08-02 01:23:23.112 275-1324/? E/audio_hw_primary: select_devices: enter and usecase(1)
08-02 01:23:23.293 275-1324/? E/audio_hw_primary: select_devices: enter and usecase(1)
08-02 01:23:24.199 275-1324/? E/audio_hw_primary: select_devices: enter and usecase(1)
08-02 01:23:24.565 275-1324/? E/audio_hw_primary: select_devices: enter and usecase(1)
08-02 01:23:24.954 275-1324/? E/audio_hw_primary: select_devices: enter and usecase(1)
08-02 01:23:25.744 275-1324/? E/audio_hw_primary: select_devices: enter and usecase(1)
08-02 01:23:26.073 275-1324/? E/audio_hw_primary: select_devices: enter and usecase(1)
08-02 01:23:26.273 275-1324/? E/audio_hw_primary: select_devices: enter and usecase(1)
08-02 01:23:26.714 275-1324/? E/audio_hw_primary: select_devices: enter and usecase(1)
08-02 01:23:28.023 275-1324/? E/audio_hw_primary: select_devices: enter and usecase(1)
08-02 01:23:28.259 275-1324/? E/audio_hw_primary: select_devices: enter and usecase(1)
08-02 01:23:28.445 275-1324/? E/audio_hw_primary: select_devices: enter and usecase(1)
08-02 01:23:28.638 275-1324/? E/audio_hw_primary: select_devices: enter and usecase(1)
08-02 01:23:28.835 275-1324/? E/audio_hw_primary: select_devices: enter and usecase(1)
08-02 01:23:29.042 275-1324/? E/audio_hw_primary: select_devices: enter and usecase(1)
08-02 01:23:29.275 275-1324/? E/audio_hw_primary: select_devices: enter and usecase(1)
08-02 01:23:29.739 275-1324/? E/audio_hw_primary: select_devices: enter and usecase(1)
08-02 01:23:30.509 2032-905/? E/IntentOperationSvc: Failed to instantiate Chimera operation impl, dropping operation
08-02 01:23:30.583 275-1324/? E/audio_hw_primary: select_devices: enter and usecase(1)
08-02 01:23:30.658 32587-32587/com.teroject.teroject E/View: hasTransientState decremented below 0: unmatched pair of setHasTransientState calls
08-02 01:23:32.265 914-914/? E/Finsky: [1] com.google.android.finsky.wear.bo.a(837): onConnectionFailed: ConnectionResult{statusCode=API_UNAVAILABLE, resolution=null, message=null}
08-02 01:23:32.958 275-1324/? E/audio_hw_primary: select_devices: enter and usecase(1)
08-02 01:23:33.229 275-1324/? E/audio_hw_primary: select_devices: enter and usecase(1)
08-02 01:23:33.823 275-1324/? E/audio_hw_primary: select_devices: enter and usecase(1)
08-02 01:23:34.129 275-1324/? E/audio_hw_primary: select_devices: enter and usecase(1)
08-02 01:23:34.336 275-1324/? E/audio_hw_primary: select_devices: enter and usecase(1)
08-02 01:23:34.387 2636-2636/? E/NetworkScheduler.SR: Invalid parameter app
08-02 01:23:34.387 2636-2636/? E/NetworkScheduler.SR: Invalid package name : Perhaps you didn't include a PendingIntent in the extras?
08-02 01:23:34.662 1186-1186/? E/App: [App][onCreate()] 4.40.21
08-02 01:23:34.785 275-1324/? E/audio_hw_primary: select_devices: enter and usecase(1)
08-02 01:23:36.379 275-1324/? E/audio_hw_primary: select_devices: enter and usecase(1)
08-02 01:23:36.488 32587-32587/com.teroject.teroject E/View: hasTransientState decremented below 0: unmatched pair of setHasTransientState calls
08-02 01:23:37.519 1310-1310/? E/LGDMClient: [DmNotiService.java] [onCreate()] : [153] : DmNotiService.onCreate()
08-02 01:23:37.600 271-822/? E/BandwidthController: [LG DATA] No such appUid: 10100
08-02 01:23:37.832 275-1324/? E/audio_hw_primary: select_devices: enter and usecase(1)
08-02 01:23:38.623 275-1324/? E/audio_hw_primary: select_devices: enter and usecase(1)
08-02 01:23:38.972 275-1324/? E/audio_hw_primary: select_devices: enter and usecase(1)
08-02 01:23:39.463 275-1324/? E/audio_hw_primary: select_devices: enter and usecase(1)
08-02 01:23:39.810 1310-1310/? E/LGDMClient: [DmNotiService.java] [onCreate()] : [153] : DmNotiService.onCreate()
08-02 01:23:40.283 275-1324/? E/audio_hw_primary: select_devices: enter and usecase(1)
08-02 01:23:40.548 275-1324/? E/audio_hw_primary: select_devices: enter and usecase(1)
08-02 01:23:40.749 275-1324/? E/audio_hw_primary: select_devices: enter and usecase(1)
08-02 01:23:41.392 275-1324/? E/audio_hw_primary: select_devices: enter and usecase(1)
08-02 01:23:42.272 275-1324/? E/audio_hw_primary: select_devices: enter and usecase(1)
08-02 01:23:42.368 32587-32587/com.teroject.teroject E/View: hasTransientState decremented below 0: unmatched pair of setHasTransientState calls
08-02 01:23:42.509 1228-1228/? E/ActivityThread: Failed to find provider info for com.facebook.katana.provider.AttributionIdProvider
08-02 01:23:42.537 1228-1267/? E/ActivityThread: Failed to find provider info for com.facebook.katana.provider.AttributionIdProvider
08-02 01:23:42.642 275-1324/? E/audio_hw_primary: select_devices: enter and usecase(1)
08-02 01:23:42.922 271-822/? E/BandwidthController: [LG DATA] No such appUid: 10101
08-02 01:23:42.942 275-1324/? E/audio_hw_primary: select_devices: enter and usecase(1)
08-02 01:23:43.205 271-822/? E/BandwidthController: [LG DATA] No such appUid: 10101
08-02 01:23:43.435 275-1324/? E/audio_hw_primary: select_devices: enter and usecase(1)
08-02 01:23:44.025 275-1324/? E/audio_hw_primary: select_devices: enter and usecase(1)
08-02 01:23:44.285 275-1324/? E/audio_hw_primary: select_devices: enter and usecase(1)
08-02 01:23:44.495 275-1324/? E/audio_hw_primary: select_devices: enter and usecase(1)
08-02 01:23:45.733 275-1324/? E/audio_hw_primary: select_devices: enter and usecase(1)
08-02 01:23:46.999 275-1324/? E/audio_hw_primary: select_devices: enter and usecase(1)
08-02 01:23:47.101 32587-32587/com.teroject.teroject E/View: hasTransientState decremented below 0: unmatched pair of setHasTransientState calls
08-02 01:23:47.967 1566-1566/? E/Finsky: [1] com.google.android.finsky.wear.bo.a(837): onConnectionFailed: ConnectionResult{statusCode=API_UNAVAILABLE, resolution=null, message=null}
08-02 01:23:48.401 271-822/? E/BandwidthController: [LG DATA] No such appUid: 10151
08-02 01:23:48.469 32587-32587/com.teroject.teroject E/CliptrayUtils: hideClipTrayIfNeeded() TextView is focused!! hideClipTray()
08-02 01:23:50.138 275-1324/? E/audio_hw_primary: disable_snd_device: enter 2
08-02 01:23:54.695 1310-1310/? E/LGDMClient: [DmNotiService.java] [onCreate()] : [153] : DmNotiService.onCreate()
08-02 01:23:55.483 271-822/? E/BandwidthController: [LG DATA] No such appUid: 10151
08-02 01:24:00.979 1310-1310/? E/LGDMClient: [DmNotiService.java] [onCreate()] : [153] : DmNotiService.onCreate()
08-02 01:24:01.475 32587-32587/com.teroject.teroject E/OneSignal: You must initialize OneSignal before modifying tags! Omitting this tag operation.
08-02 01:24:02.643 32587-32587/com.teroject.teroject E/CliptrayUtils: hideClipTrayIfNeeded() TextView is focused!! hideClipTray()
08-02 01:24:04.019 2636-1894/? E/CommitToConfigurationOperation: Malformed snapshot token (size):
08-02 01:24:04.045 2636-1894/? E/CommitToConfigurationOperation: Malformed snapshot token (size):
08-02 01:24:04.079 2636-1894/? E/CommitToConfigurationOperation: Malformed snapshot token (size):
08-02 01:24:04.142 271-822/? E/BandwidthController: [LG DATA] No such appUid: 10004
08-02 01:24:04.408 275-1078/? E/audio_hw_primary: select_devices: enter and usecase(1)
08-02 01:24:04.408 275-1078/? E/audio_hw_primary: enable_snd_device: enter 2
08-02 01:24:05.356 275-1324/? E/audio_hw_primary: select_devices: enter and usecase(1)
08-02 01:24:08.505 275-1324/? E/audio_hw_primary: disable_snd_device: enter 2
08-02 01:24:10.637 271-822/? E/BandwidthController: [LG DATA] No such appUid: 10151
最佳答案
将String
转换为UTF-8的正确方法是单独调用getBytes()
:
byte[] fname = _fnameText.getText().toString().getBytes(UTF8);
你做得很好,但是你用这个输出做其他事情就不好了。
您的第一个示例是错误的,因为您正在使用 Java 的默认字符集将 UTF-8 字节转换回 String
,而您的系统上显然不是 UTF-8。
您的第二个示例是错误的,因为您在 HTTP 逻辑的错误阶段手动对 UTF-8 字节进行 URL 编码。
您根本不应该将个人输入字符串转换为 UTF-8。根据需要构建 HTTP 请求值,然后在通过 HTTP 发布时让 UrlEncodedFormEntity
处理到 UTF-8 的转换。 UrlEncodedFormEntity()
有两个构造函数,其中之一采用 encoding
作为输入参数,但您没有使用该构造函数。
尝试更多类似这样的事情:
public void signup() {
String name = new String();
String fname = _fnameText.getText().toString();
String lname = _lnameText.getText().toString();
String password = _passwordText.getText().toString();
// TODO: Implement your own signup logic here.
if(name!=null && fname!=null && lname!=null && password!=null) {
if (isConnected()) {
if (validate()) {
_signupButton.setEnabled(false);
jsonSignup = new JSON_Signup(SignupActivity.this, "http://teroject.com/api/android.php", name, password);
jsonSignup.valuesForServer.add(new BasicNameValuePair("api_key", "teroapi_php_java_1395"));
jsonSignup.valuesForServer.add(new BasicNameValuePair("api_function", "register"));
jsonSignup.valuesForServer.add(new BasicNameValuePair("username", name));
jsonSignup.valuesForServer.add(new BasicNameValuePair("password", password));
jsonSignup.valuesForServer.add(new BasicNameValuePair("fname", fname));
jsonSignup.valuesForServer.add(new BasicNameValuePair("lname", lname));
jsonSignup.execute();
}
}
}else {
Toast.makeText(getApplicationContext(), "لطفا از کاراکتر های مجاز استفاده کنید", Toast.LENGTH_SHORT).show();
}
}
public JSON_Signup(Context context, String url, String username, String password){
this.context=context;
this.url=url;
this.username=username;
this.password=password;
valuesForServer=new List<BasicNameValuePair>();
progressDialog=new ProgressDialog(this.context);
}
@Override
protected void onPreExecute() {
progressDialog.setMessage("در حال ثبت نام لطفا صبر کنید....");
progressDialog.show();
progressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
public void onCancel(DialogInterface arg0) {
JSON_Signup.this.cancel(true);
}
});
}
@Override
protected String doInBackground(String... params) {
try {
// Set up HTTP post
// HttpClient is more then less deprecated. Need to change to URLConnection
HttpParams httpParameters = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParameters, 20000);
HttpConnectionParams.setSoTimeout(httpParameters, 20000);
DefaultHttpClient httpClient = new DefaultHttpClient(httpParameters);
HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(new UrlEncodedFormEntity(valuesForServer, "utf-8"));
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
StatusLine statusLine = httpResponse.getStatusLine();
if (statusLine.getStatusCode() == HttpStatus.SC_OK) {
// Read content & Log
inputStream = httpEntity.getContent();
}else{
return null;
}
}catch (NetworkOnMainThreadException e7){
Log.i("Network on Main Thread", e7 + "");
e7.printStackTrace();
return null;
} catch(SocketTimeoutException e6){
Log.i("Connection Timeout", e6 + "");
e6.printStackTrace();
return null;
} catch (UnsupportedEncodingException e1) {
Log.i("Unsupported Encoding",e1+"");
e1.printStackTrace();
return null;
} catch (ClientProtocolException e2) {
Log.i("Client Protocol", e2 + "");
e2.printStackTrace();
return null;
} catch (IllegalStateException e3) {
Log.i("Illegal State", e3 + "");
e3.printStackTrace();
return null;
} catch (IOException e4) {
Log.i("Exception", e4 + "");
e4.printStackTrace();
return null;
}
// Convert response to string using String Builder
if(inputStream!=null) {
try {
BufferedReader bReader = new BufferedReader(new InputStreamReader(inputStream, "utf-8"), 8);
StringBuilder sBuilder = new StringBuilder();
String line = null;
while ((line = bReader.readLine()) != null) {
sBuilder.append(line + "\n");
}
inputStream.close();
result = sBuilder.toString();
} catch (Exception e) {
Log.i("Exception", e + "");
return null;
}
}else {
return null;
}
return result;
}
@Override
protected void onPostExecute(String result) {
if (result != null) {
//parse JSON data
try {
mainFile = new JSONObject(result);
success = mainFile.getString("success");
message = mainFile.getString("message");
if (success.equals("1")) {
_signupButton.setEnabled(true);
Toast.makeText(this.context, message, Toast.LENGTH_LONG).show();
if (isConnected()) {
JSON json = new JSON(this.context, "http://teroject.com/api/android.php", this.username, this.password);
json.valuesForServer.add(new BasicNameValuePair("api_key", "teroapi_php_java_1395"));
json.valuesForServer.add(new BasicNameValuePair("api_function", "login"));
json.valuesForServer.add(new BasicNameValuePair("username", this.username));
json.valuesForServer.add(new BasicNameValuePair("password", this.password));
json.execute();
}
} else if (success.equals("0")) {
Toast.makeText(this.context, message, Toast.LENGTH_LONG).show();
_signupButton.setEnabled(true);
}
this.progressDialog.dismiss();
} catch (JSONException e) {
Toast.makeText(this.context, e + "", Toast.LENGTH_SHORT).show();
_signupButton.setEnabled(true);
this.progressDialog.dismiss();
}
}else {
_signupButton.setEnabled(true);
progressDialog.dismiss();
Toast.makeText(this.context,"خطا در برقراری ارتباط",Toast.LENGTH_LONG).show();
}
}
}
您没有显示 JSON.execute()
的代码,但概念是相同的。将 HTTP 值收集为普通 String
值,然后让 UrlEncodedFormEntity
在发布最终 HTTP 请求时将这些值转换为 UTF-8。
关于java - 在android中使用JSON将字符串编码为UTF-8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38708023/
我正在编写一个具有以下签名的 Java 方法。 void Logger(Method method, Object[] args); 如果一个方法(例如 ABC() )调用此方法 Logger,它应该
我是 Java 新手。 我的问题是我的 Java 程序找不到我试图用作的图像文件一个 JButton。 (目前这段代码什么也没做,因为我只是得到了想要的外观第一的)。这是我的主课 代码: packag
好的,今天我在接受采访,我已经编写 Java 代码多年了。采访中说“Java 垃圾收集是一个棘手的问题,我有几个 friend 一直在努力弄清楚。你在这方面做得怎么样?”。她是想骗我吗?还是我的一生都
我的 friend 给了我一个谜语让我解开。它是这样的: There are 100 people. Each one of them, in his turn, does the following
如果我将使用 Java 5 代码的应用程序编译成字节码,生成的 .class 文件是否能够在 Java 1.4 下运行? 如果后者可以工作并且我正在尝试在我的 Java 1.4 应用程序中使用 Jav
有关于why Java doesn't support unsigned types的问题以及一些关于处理无符号类型的问题。我做了一些搜索,似乎 Scala 也不支持无符号数据类型。限制是Java和S
我只是想知道在一个 java 版本中生成的字节码是否可以在其他 java 版本上运行 最佳答案 通常,字节码无需修改即可在 较新 版本的 Java 上运行。它不会在旧版本上运行,除非您使用特殊参数 (
我有一个关于在命令提示符下执行 java 程序的基本问题。 在某些机器上我们需要指定 -cp 。 (类路径)同时执行java程序 (test为java文件名与.class文件存在于同一目录下) jav
我已经阅读 StackOverflow 有一段时间了,现在我才鼓起勇气提出问题。我今年 20 岁,目前在我的家乡(罗马尼亚克卢日-纳波卡)就读 IT 大学。足以介绍:D。 基本上,我有一家提供簿记应用
我有 public JSONObject parseXML(String xml) { JSONObject jsonObject = XML.toJSONObject(xml); r
我已经在 Java 中实现了带有动态类型的简单解释语言。不幸的是我遇到了以下问题。测试时如下代码: def main() { def ks = Map[[1, 2]].keySet()
一直提示输入 1 到 10 的数字 - 结果应将 st、rd、th 和 nd 添加到数字中。编写一个程序,提示用户输入 1 到 10 之间的任意整数,然后以序数形式显示该整数并附加后缀。 public
我有这个 DownloadFile.java 并按预期下载该文件: import java.io.*; import java.net.URL; public class DownloadFile {
我想在 GUI 上添加延迟。我放置了 2 个 for 循环,然后重新绘制了一个标签,但这 2 个 for 循环一个接一个地执行,并且标签被重新绘制到最后一个。 我能做什么? for(int i=0;
我正在对对象 Student 的列表项进行一些测试,但是我更喜欢在 java 类对象中创建硬编码列表,然后从那里提取数据,而不是连接到数据库并在结果集中选择记录。然而,自从我这样做以来已经很长时间了,
我知道对象创建分为三个部分: 声明 实例化 初始化 classA{} classB extends classA{} classA obj = new classB(1,1); 实例化 它必须使用
我有兴趣使用 GPRS 构建车辆跟踪系统。但是,我有一些问题要问以前做过此操作的人: GPRS 是最好的技术吗?人们意识到任何问题吗? 我计划使用 Java/Java EE - 有更好的技术吗? 如果
我可以通过递归方法反转数组,例如:数组={1,2,3,4,5} 数组结果={5,4,3,2,1}但我的结果是相同的数组,我不知道为什么,请帮助我。 public class Recursion { p
有这样的标准方式吗? 包括 Java源代码-测试代码- Ant 或 Maven联合单元持续集成(可能是巡航控制)ClearCase 版本控制工具部署到应用服务器 最后我希望有一个自动构建和集成环境。
我什至不知道这是否可能,我非常怀疑它是否可能,但如果可以,您能告诉我怎么做吗?我只是想知道如何从打印机打印一些文本。 有什么想法吗? 最佳答案 这里有更简单的事情。 import javax.swin
我是一名优秀的程序员,十分优秀!