我遇到了HTC Legend(Android 2.2)的烦人问题.没有在Xperia,Galaxy,Nexus等上看到这个问题.
当我在3G连接上启动我的应用程序,获取一些数据,然后进入手机设置并启用WIFI,手机自动获得一个比3G更受欢迎的WIFI连接.麻烦的是,一旦我切换回应用程序,它似乎已经失去了所有的网络连接,无法连接到任何东西.但是,其他应用程序(例如Web浏览器)使用新的Wifi连接没有问题.Ping可以通过手机外壳正常工作.
如果我等待足够长的时间(例如15分钟),网络堆栈似乎会自动修复,我的应用程序可以再次建立网络连接.当然,这种延迟是不可接受的.
有没有办法以编程方式重新启动网络堆栈?我每次都创建一个新的java.net.HttpURLConnection,但是一旦获得了WIFI,它仍然会超时.
谢谢
码:
byte[] response = null;
HttpURLConnection connection = null;
int responseCode = -1;
// check the cache first
String readyResponse = ResponseCache.getInstance().get(getUrl());
if (readyResponse != null) {
Log.d(LOG_TAG, "Returning CACHED server response for " + getUrl());
return readyResponse.getBytes();
}
try {
URL url = new URL(getUrl());
Log.i(LOG_TAG, "Sending Request: " + url.toExternalForm());
connection = (HttpURLConnection) url.openConnection();
connection.setUseCaches(false);
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setConnectTimeout(ApplicationConfiguration.HTTP_CONNECT_TIMEOUT);
connection.setReadTimeout(ApplicationConfiguration.HTTP_READ_TIMEOUT);
if (BuildType.getHTTPMethod() == BuildType.METHOD_GET)
{
connection.setRequestMethod("GET");
}
else
{
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); …Run Code Online (Sandbox Code Playgroud) 什么是动态的静态等价物
String CLASS_NAME = this.getClass().getCanonicalName()
请注意,以下不是我正在寻找的,因为它特别指的是特定的类.我想在方法之外引用类名(即在静态{}部分)
static String CLASS_NAME = Foo.class.getCanonicalName()
谢谢.
OpenAL 1.1 中不推荐使用以下函数调用,什么是正确的替换?我在谷歌上找到的唯一答案是“编写你自己的函数!!” ;-)
alutLoadWAVFile
alutUnloadWAV
Run Code Online (Sandbox Code Playgroud) 为什么第二次调用会产生它的作用?我认为,通过铸造this来Super,只Super's m1()应该叫!
Super!
And Sub!
---
Super!
And Sub!
Run Code Online (Sandbox Code Playgroud)
码:
public class TestSuper {
public static void main(String[] args) {
(new Sub()).m1();
System.out.println("---");
(new Sub()).m2(); // !!!!!!!!!!!!!!!!
}
}
class Super {
void m1() {
System.out.println("Super!");
}
}
class Sub extends Super {
void m1() {
super.m1();
System.out.println("And Sub!");
}
void m2() {
((Super) this).m1();
}
}
Run Code Online (Sandbox Code Playgroud) 我使用相对布局将一个较小的图像叠加在较大的图像上.我希望较小图像的右下角与较大图像的BR角一致.我在我的布局xml中使用了边距参数(指定在倾角中测量),但这似乎并不适用于所有设备和分辨率 - 在某些情况下,小图像从边框移动了4-5px.
是否可以指定较小图像的位置而没有像素值?即重力还是什么?
我试图弄清楚为什么我在使用FFMPEG库时会破坏堆栈.我已经使用调试信息重新编译了FFMPEG,并且从回溯中,违规行是libavformat/mpegtsenc.c:800.然而,该行只是}函数的结束括号mpegts_write_pes.
我相信函数返回地址被覆盖(因此gdb指向大括号).
这是源代码的链接,http://git.ffmpeg.org/?p =ffmpeg; a = blob; f = libavformat/mpegtsenc.c; hb = 1a505867a57d7dc74d414b5adb9a0264c9a6c6c
那条线路将是814.
谢谢
*** stack smashing detected ***: /home/victor/workspace/segmenter/segmenter terminated
======= Backtrace: =========
/lib/libc.so.6(__fortify_fail+0x50)[0x419970]
/lib/libc.so.6(+0xe591a)[0x41991a]
/home/victor/workspace/segmenter/segmenter[0x80be004]
======= Memory map: ========
00110000-0012c000 r-xp 00000000 08:01 158181 /lib/ld-2.12.1.so
0012c000-0012d000 r--p 0001b000 08:01 158181 /lib/ld-2.12.1.so
0012d000-0012e000 rw-p 0001c000 08:01 158181 /lib/ld-2.12.1.so
0012e000-0012f000 r-xp 00000000 00:00 0 [vdso]
0012f000-0013f000 r-xp 00000000 08:01 130866 /lib/libbz2.so.1.0.4
0013f000-00140000 r--p 0000f000 08:01 130866 /lib/libbz2.so.1.0.4
00140000-00141000 rw-p …Run Code Online (Sandbox Code Playgroud) 我有一个JDesktopPane包含许多JInternalFrames的.我希望能够将任何东西JInternalFrame带到前面,覆盖任何其他活动帧.我找到了许多代码示例来执行此操作,但似乎没有一个工作 - 框架不会在其他活动JInternalFrames 之上.例如
public static void moveToFront(final JInternalFrame fr) {
if (fr != null) {
processOnSwingEventThread(new Runnable() {
public void run() {
fr.moveToFront();
fr.setVisible(true);
try {
fr.setSelected(true);
if (fr.isIcon()) {
fr.setIcon(false);
}
fr.setSelected(true);
} catch (PropertyVetoException ex) {
ex.printStackTrace();
}
fr.requestFocus();
fr.toFront();
}
});
}
}
为什么我尝试时会抛出NumberFormatException Integer.parseInt("80000010", 16)?这是一个32位的数字,这是java的int的大小.
编辑:最好的部分是这...
int z = 0x80000010;
System.err.println("equal to " + z);
Run Code Online (Sandbox Code Playgroud)
打印-2147483632确实0x80000010根据我的计算器;)
我有这个
int [] abc = new int[30];
Object arr = abc;
Run Code Online (Sandbox Code Playgroud)
我如何施展arr回int[]?即
int [] foo = (int[])arr
Run Code Online (Sandbox Code Playgroud)
另外,如果arr可以指向int[]或者byte[],如何区分它们?
我检查arr.getClass().getName()的回报[I 和arr.getClass().isPrimitive()为false.必须是另一种检测它的方法吗?
谢谢.
PS.我必须在我的数组中使用原始类型.