当我尝试设置套接字服务器时,我收到一条错误消息:
Exception in thread "main" java.net.BindException: Cannot assign requested address: JVM_Bind
at java.net.PlainSocketImpl.socketBind(Native Method)
at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:383)
at java.net.ServerSocket.bind(ServerSocket.java:328)
at java.net.ServerSocket.<init>(ServerSocket.java:194)
at java.net.ServerSocket.<init>(ServerSocket.java:106)
at socketyserver.SocketyServer.main(SocketyServer.java:12)
Java Result: 1
Run Code Online (Sandbox Code Playgroud)
整个代码最简单,因为它可以是:
public static void main(String[] args) throws UnknownHostException, IOException
{
ServerSocket serverSocket;
serverSocket = new ServerSocket(9999);
}
Run Code Online (Sandbox Code Playgroud)
我100%确定我的端口已转发,Windows防火墙已关闭.什么都没有阻止端口9999.还有什么可能出错?
我正在创建一个动态更改状态栏颜色的应用程序.
从任何片段调用时,我在主Activity类中的方法工作正常.片段放在Activity pager中:
public void setStatusBarColorIfPossible(int color) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
getWindow().setStatusBarColor(color);
}
}
Run Code Online (Sandbox Code Playgroud)
但是,在任何片段中创建并全屏显示的DialogFragment中,调用my方法无效.状态栏立即变黑(在styles.xml中设置),我无法更改它.
public class AddOrEditWeekPlanDialog extends DialogFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(DialogFragment.STYLE_NORMAL, R.style.MyDialog);
}
@Override
public void onStart() {
super.onStart();
Dialog d = getDialog();
if (d!=null){
int width = ViewGroup.LayoutParams.MATCH_PARENT;
int height = ViewGroup.LayoutParams.MATCH_PARENT;
d.getWindow().setLayout(width, height);
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.fragment_dialog, container, false);
Button button = (Button)root.findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() { …Run Code Online (Sandbox Code Playgroud) 我正在使用ProGuard来模糊我的apk,但是类和方法名称没有变化 - 它们和以前一样.只更改变量名称.
他们中的大多数都没有扩展像Activity这样的类; 我的代码中有一些继承,但它是100%由我自己编写的.
我正在使用d2j-dex2jar和jd-gui来检查结果.
由于GSON的使用,有些类被排除在外,这是我的proguard-project.txt:
-keep class com.google.ads.** # Don't proguard AdMob classes
-dontwarn com.google.ads.** # Temporary workaround for v6.2.1. It gives a warning that you can ignore
# Add any classes the interact with gson
-keep class com.revicostudio.gravityrun.playerdata.PlayerData
-keep class com.revicostudio.gravityrun.playerdata.SettingsDescriptor
-keep class com.revicostudio.gravityrun.playerdata.ShipStatus
-keep class com.revicostudio.gravityrun.descriptors.ShipDescriptor
-keep class com.revicostudio.gravityrun.descriptors.Ships
-keep class com.revicostudio.gravityrun.game.galaxies.Galaxies
-keep public class com.badlogic.** {*;}
##---------------Begin: proguard configuration common for all Android apps ----------
-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontskipnonpubliclibraryclassmembers
-dontpreverify
-verbose
-dump class_files.txt
-printseeds …Run Code Online (Sandbox Code Playgroud) 在我的2D游戏中,我使用图形工具创建由黑色代表的漂亮,平滑的地形:

用java编写的简单算法每15个像素查找一次黑色,创建以下一组行(灰色):

正如你所看到的,有些地方的地图非常糟糕,有些地方非常好.在其他情况下,没有必要对每15个像素进行采样,例如.如果地形平坦.
使用尽可能少的点将这条曲线转换为点[线]的最佳方法是什么?每15个像素采样= 55 FPS,10个像素= 40 FPS
以下算法正在执行该任务,从右到左采样,将可粘贴输出到代码数组中:
public void loadMapFile(String path) throws IOException {
File mapFile = new File(path);
image = ImageIO.read(mapFile);
boolean black;
System.out.print("{ ");
int[] lastPoint = {0, 0};
for (int x = image.getWidth()-1; x >= 0; x -= 15) {
for (int y = 0; y < image.getHeight(); y++) {
black = image.getRGB(x, y) == -16777216 ? true : false;
if (black) {
lastPoint[0] = x;
lastPoint[1] = y;
System.out.print("{" + (x) + ", " …Run Code Online (Sandbox Code Playgroud) 我想让我的JTextArea字段与当前的JPanel一样大.怎么做?
现在它是这样的:
JPanel statusBar = new StatusBar(project);
JTextArea outputBox = new JTextArea(1, 50);
outputBox.setEditable(true);
statusBar.add(outputBox);
Run Code Online (Sandbox Code Playgroud) 我认为我正在推动 Spring Boot 和 Hibernate 使用的极其简单的情况。我的目的是将有关班级的信息存储在班级Cyclist内部的关系User中OneToOne。
在注册期间,User创建类的实例并将其存储到数据库中。当用户刷新/home页面时,点击计数器会增加并保存(更新)实体。这是一个简单的会话测试和更新数据库,其工作原理如下:
@Controller
@SessionAttributes("user")
@RequestMapping("/home")
public class HomeController {
@Autowired private UserSession userSession;
@Autowired private UserDAO userDAO;
@GetMapping
public String home(Model model) {
User user = userSession.getUser();
user.setClicks(user.getClicks() + 1);
userDAO.save(user);
return "home";
}
}
Run Code Online (Sandbox Code Playgroud)
当用户填写表单时就会出现问题/createCyclist:
@Autowired private UserDAO userDAO;
@PostMapping
public String createCyclist(@Valid CyclistCreationForm cyclistCreationForm, BindingResult bindingResult, Model model) {
/* Form handling */
User user = userSession.getUser();
Cyclist cyclist = new …Run Code Online (Sandbox Code Playgroud) 我写了以下代码:
@Controller
@RequestMapping("/page{number}")
public class IndexController
{
@RequestMapping(method = RequestMethod.GET)
public String printIndex(ModelMap model, @PathVariable int number)
{
String numberText;
switch (number)
{
case 0:
numberText = "Zero";
break;
case 1:
numberText = "One";
break;
default:
numberText = "Unknown";
break;
}
model.addAttribute("number", numberText);
return "page";
}
}
Run Code Online (Sandbox Code Playgroud)
而且我想要实现像此方法控制的page1.html,page2.html,page3.html这样的网址,但有一个例外:page.html应该给出与page1.html相同的结果.我正在寻找能使{number}成为可选项的东西,现在它是必需的.
我说有没有办法做到这一点?
/
java ×5
android ×2
spring ×2
algorithm ×1
andengine ×1
bind ×1
curve ×1
hibernate ×1
jtextarea ×1
jvm ×1
obfuscation ×1
points ×1
proguard ×1
sockets ×1
spring-boot ×1
spring-mvc ×1
swing ×1
url-mapping ×1