我一直在通过谷歌寻找这个问题但事实证明我找不到解决这个问题的方法.实际上我有一个经典的main方法,我运行一个工作,但sonarqube不断重复我有一个未注释的主要方法找到.
这是代码:
/**
* Main : Run MapReduce job
*
* @param args
* arguments
*/
public static void main(String[] args) {
ExitManager exitManager = new ExitManager();
// run job
if (!runJob(args)) {
exitManager.exit(1);
}
}
Run Code Online (Sandbox Code Playgroud)
我没有看到任何特殊问题,所以这个问题来自哪里?你知道我怎么解决这个问题吗?
谢谢.
出于代码质量原因,我想稍微重构一下我的代码,以便break在循环中仅使用一个语句。但我不确定我是否可以按照 SonarQube 要求我的方式做到这一点......
这是我的代码:
for (Integer integer: integerKey.keySet()) {
if (map.containsKey(integerKey.get(integer))) {
TypeValue value = map.get(integerKey.get(integer));
sb.append(integerKey.get(integer)).append(":");
sb.append(encodeValue(value));
sb.append("|");
if (integerKey.get(integer).equals(min)) {
break;
}
} else if (integerKey.get(integer) <= min){
TypeValue value = map.get(min);
sb.append(min).append(":");
sb.append(encodeValue(value));
sb.append("|");
break;
} else {
sb.append(integerKey.get(integer)).append(":");
sb.append("0");
sb.append("|");
}
}
Run Code Online (Sandbox Code Playgroud)
我想做同样的事情,但只使用一个break,但我不确定if在这种情况下我可以只写一个条件而不是if-elseif-else.
有任何想法吗 ?
谢谢。
我有一个小项目,我需要使用Android设备的电池.起初,我希望能够打印电池,所以我使用了本教程.
然后,我在Eclipse中创建了一个名为"Testing"的新Android项目,在MainActivity.java中我放了这段代码:
package com.example.testing;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.BatteryManager;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
import android.widget.Toast;
import android.R.*;
public class MainActivity extends Activity {
TextView mTextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.MainActivity); //This is the MainActivity that contains the error
mTextView = (TextView) findViewById(R.id.batterTest);
findViewById(R.id.getBattery).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
mTextView.setText(String.valueOf(batteryLevel));
}
});
new Thread(new ThreadM()).start();
}
@Override
protected void onDestroy() …Run Code Online (Sandbox Code Playgroud) 我正在使用PHP中的使用对象(Codeacademy.com)进行属性恐慌(2),但是我有这个错误.这是我的代码:
<!DOCTYPE html>
<html>
<head>
<title>Reconstructing the Person Class</title>
<link type='text/css' rel='stylesheet' href='style.css'/>
</head>
<body>
<p>
<?php
class Person{
public $isAlive = true;
public $firstname;
public $lastname;
public $age;
}
public function __construct($firstname, $lastname, $age){
$this->firstname = $firstname;
$this->lastname = $lastname;
$this->age = $age;
}
$teacher = new Person("boring","12345",12345);
$student = new Person("a","b",23);
echo $teacher->age;
?>
</p>
</body>
Run Code Online (Sandbox Code Playgroud)
它从何而来?谢谢
我的Java代码在Eclipse中工作,但我需要添加一些功能.
首先,如何限制用户可以输入的位数?实际上我有一个JPasswordField让一个人输入一个pin代码,我希望这个JPasswordField最多限制为4位数.那么如何在输入4位数后立即停止输入?
然后,我如何玩JPassword框的大小?有没有办法像JTextField一样修改它?因为我的行"p1.setPreferredSize(new Dimension(100,25));" 似乎并没有真正让我修改盒子的大小.

如您所见,JPassworldField框具有默认大小,我无法弄清楚如何轻松修改.
这是我的代码:
package codePin;
import java.io.*;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Main extends JFrame {
private static final long serialVersionUID = 1L;
private JPanel container = new JPanel();
private JPasswordField p1 = new JPasswordField(4);
private JLabel label = new JLabel("Enter Pin: ");
private JButton b = new JButton("OK");
public Main() {
this.setTitle("NEEDS");
this.setSize(300, 500);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLocationRelativeTo(null);
container.setBackground(Color.white);
container.setLayout(new BorderLayout());
JPanel top = new JPanel();
p1.setPreferredSize(new Dimension(100, 25)); //How …Run Code Online (Sandbox Code Playgroud) 我有一个matrix.txt文件,其中有一个以这种方式编写的矩阵:
1 2 3
4 5 6
7 8 9
Run Code Online (Sandbox Code Playgroud)
我需要编写一个小程序,将该文件作为输入,并以与.txt文件相同的方式打印此矩阵.
这意味着当"./a.out matrix.txt"的输出必须与我的.txt文件完全相同时:
1 2 3
4 5 6
7 8 9
Run Code Online (Sandbox Code Playgroud)
我的问题是我所能做的就是这个功能:
void printMatrice(matrice) {
int x = 0;
int y = 0;
for(x = 0 ; x < numberOfLines ; x++) {
printf(" (");
for(y = 0 ; y < numberOfColumns ; y++){
printf("%d ", matrix[x][y]);
}
printf(")\n");
}
}
Run Code Online (Sandbox Code Playgroud)
但这根本不好.
有人有想法吗?
谢谢
我的问题是,为什么我在线程"main"java.lang.ArrayStoreException中得到一个Exception:
在Main.main的java.util.ArrayList.toArray(未知来源)的java.lang.System.arraycopy(本机方法)中(Main.java:50)
这是我的代码:
import java.io.*;
import java.util.*;
public class Main {
static public boolean readPinsData(File dataFile, ArrayList<Integer> data) {
boolean err = false;
try {
Scanner scanner = new Scanner(dataFile);
String line;
while (scanner.hasNext()) {
line = scanner.nextLine();
try {
data.add(Integer.parseInt(line));
} catch (NumberFormatException e) {
e.printStackTrace();
err = true;
}
}
scanner.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
err = true;
}
return err;
}
public static void main(String[] args) {
Console console = System.console();
int pinSize = 0; …Run Code Online (Sandbox Code Playgroud) 联系到这个问题,并且这其中也,我想知道如何做同样的事情,但有一个不同类型的JSON的:
这是我的JSON对象:
var myDb = {
"04c85ccab52880": {
"name": "name1",
"firstname": "fname1",
"societe": "soc1"
},
"04c95ccab52880": {
"name": "name2",
"firstname": "fname2",
"societe": "soc2"
},
"048574220e2a80": {
"name": "name3",
"firstname": "fname3",
"societe": "soc3"
}
};
Run Code Online (Sandbox Code Playgroud)
我的问题是我的JSON与他们的JSON不同,实际上我有一个数组数组.那么如何将其转换为Javascript数组呢?
var arr = [];
$.each( myDb, function( key, value ) {
arr.push( value );
});
console.log(user_list);
Run Code Online (Sandbox Code Playgroud)
这种脚本似乎返回了我的3个不同的对象但是我的uid来自JSON?我怎么能得到它们?因为现在我的钥匙是0,1,2而不再是我的uid.
有任何想法吗 ?谢谢