我正在使用媒体播放器.
我可以选择启动,停止和暂停播放器.我遇到的问题是我找不到从之前暂停的那一点恢复歌曲的选项.
任何帮助提供将是非常有帮助的.
我们有一个实用工具,将在周一至周五之间的任何一天运行.它将更新内容管理工具中的一些文件.与该文件关联的最后修改日期应该是该周的星期一日期.我编写了以下程序来检索当前周的星期一日期.但我仍然不确定这是否适用于所有情况.有没有人有更好的解决方案?
Calendar c = Calendar.getInstance();
c.setTime(new Date());
System.out.println(c.get(Calendar.DAY_OF_MONTH));
System.out.println(c.get(Calendar.DAY_OF_WEEK));
int mondayNo = c.get(Calendar.DAY_OF_MONTH)-c.get(Calendar.DAY_OF_WEEK)+2;
c.set(Calendar.DAY_OF_MONTH,mondayNo);
System.out.println("Date "+c.getTime());
Run Code Online (Sandbox Code Playgroud) 我知道它的包装差异
1) org.apache.log4j.Logger logger = Logger.getLogger(clazz);
2) org.apache.commons.logging.Log log = LogFactory.getLog(clazz);
第一个使用记录器log4j
,第二个使用commons.logging
.我们有一个庞大的项目,在某些类中使用记录器配置log4j
,在某些情况下使用它commons.logging
.
我确实找到了一个log4j属性文件.是否有类似的属性文件commons.logging
?我在哪里配置commons-logging?我无法看到生成的日志commons-logging
.
任何帮助表示赞赏.
我正在开发一个聊天应用程序,其中Android客户端将使用多播(UDP)交换他们的IP.
每个设备都会在一个单独的线程中将其ip发送到多个客户端(运行此应用程序的所有设备).将有另一个接收器线程将侦听这些多播数据包.这是我的代码.
//多播代码
DatagramSocket socket = new DatagramSocket(9898);
byte buff[] = ip.getBytes();
DatagramPacket packet = new DatagramPacket(buff, buff.length, InetAddress.getByName("224.0.0.1"),9999);
socket.send(packet);
socket.close();
Run Code Online (Sandbox Code Playgroud)
//接收者代码
MulticastSocket socket = new MulticastSocket(9999);
InetAddress group = InetAddress.getByName("224.0.0.1");
socket.joinGroup(group);
DatagramPacket packet;
byte[] buf = new byte[256];
byte b = 'x'; //just a separator for time being
Arrays.fill(buf,b);
packet = new DatagramPacket(buf, buf.length);
String received= "";
while(received!=null)
{
socket.receive(packet);
received = new String(packet.getData());
received = received.substring(0,received.indexOf('x'));
this.setIp(received);
System.out.println("Address: " + received);
}
socket.leaveGroup(group);
socket.close();
Run Code Online (Sandbox Code Playgroud)
问题是每个设备都打印自己的地址.它似乎永远不会收听其他多播包(我的意思是它应该打印其他的ip).我也得到一个下面的日志,不知道这是否相关.
11-04 23:56:17.985: I/OSNetworkSystem(603): …
Run Code Online (Sandbox Code Playgroud) 我为Listview中的每个项目创建了一个自定义Listview
(没有重写getView()
方法),具有以下布局
contactlayout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent" android:weightSum="1">
<CheckBox android:id="@+id/checkBox1" android:text="CheckBox" android:layout_width="134dp" android:layout_height="108dp" android:focusable="false"></CheckBox>
<LinearLayout android:id="@+id/linearLayout1" android:layout_height="match_parent" android:orientation="vertical" android:layout_width="87dp" android:layout_weight="0.84" android:weightSum="1" >
<TextView android:text="TextView" android:layout_height="wrap_content" android:layout_width="match_parent" android:id="@+id/name" android:layout_weight="0.03"></TextView>
<TextView android:text="TextView" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/phone"></TextView>
<TextView android:text="TextView" android:layout_height="wrap_content" android:layout_weight="0.03" android:layout_width="match_parent" android:id="@+id/contactid" android:visibility="invisible"></TextView>
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我正在以下列方式填充Listview
使用a SimpleCursorAdapter
...
Cursor c = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,null,null, ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME);
String from[] = new String[]{ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,ContactsContract.CommonDataKinds.Phone.NUMBER,ContactsContract.CommonDataKinds.Phone.CONTACT_ID};
int to[] = new int[]{R.id.name,R.id.phone,R.id.contactid};
SimpleCursorAdapter s = new SimpleCursorAdapter(this,R.layout.contactlayout,c,from,to);
lv.setAdapter(s);
Run Code Online (Sandbox Code Playgroud)
单击按钮我正在读取所有复选框的状态.问题是,如果我检查其他CheckBox
几个下线就会自动检查.我知道这是重用Views.我该如何避免呢?getView() …
我正在为在Brightcove视频云上托管视频的网站创建视频站点地图.为了从网站获取所有视频信息,Brightcove建议从他们的以下表格的网址阅读回复
http://api.brightcove.com/services/library?token="+accountToken+"&page_size=1&command=find_all_videos&output=JSON&get_item_count=true
Run Code Online (Sandbox Code Playgroud)
url的输出是JSON,其中accountToken
只是帐户的标识符.
当我在浏览器中使用Token点击上面的url时,它会给我正确的响应.
我写了下面的程序片段来读取该URL
URL jsonURL = new URL("http://api.brightcove.com/services/library?token="+accountToken+"&page_size=1&command=find_all_videos&output=JSON&get_item_count=true");
HttpURLConnection connection = (HttpURLConnection) jsonURL.openConnection();
connection.setRequestMethod("GET");
connection.connect();
BufferedReader reader = new BufferedReader(
new InputStreamReader(connection.getInputStream()));
String lineRead = "";
while (reader.ready()) {
lineRead = lineRead + reader.readLine();
}
Run Code Online (Sandbox Code Playgroud)
由于我的浏览器使用代理,我添加了以下代码以包含代理设置
System.setProperty("http.proxyHost", "my.proxyurl.com");
System.setProperty("http.proxyPort", "80");
Run Code Online (Sandbox Code Playgroud)
不使用代理设置,它返回java.net.ConnectException: Connection refused: connect
并使用代理它给我java.io.IOException: Server returned HTTP response code: 503
所以我的问题是,为什么它给我503(服务不可用)错误?从浏览器它的工作正常.
更新1: 这似乎是网络的一个问题.我ping了域名,它说"请求超时".但是通过HTTP工作.看起来像防火墙的问题.
我正在研究基本的小费计算器并遇到以下程序崩溃.崩溃的日志是:
06-24 01:03:43.602: E/AndroidRuntime(27213): FATAL EXCEPTION: main
06-24 01:03:43.602: E/AndroidRuntime(27213): java.lang.NumberFormatException: Invalid double: "android.widget.EditText@41634f08"
06-24 01:03:43.602: E/AndroidRuntime(27213): at java.lang.StringToReal.invalidReal(StringToReal.java:63)
06-24 01:03:43.602: E/AndroidRuntime(27213): at java.lang.StringToReal.initialParse(StringToReal.java:114)
06-24 01:03:43.602: E/AndroidRuntime(27213): at java.lang.StringToReal.parseDouble(StringToReal.java:263)
06-24 01:03:43.602: E/AndroidRuntime(27213): at java.lang.Double.parseDouble(Double.java:295)
06-24 01:03:43.602: E/AndroidRuntime(27213): at mkelleyjr.example.tippycalc.MainActivity$1.onClick(MainActivity.java:30)
06-24 01:03:43.602: E/AndroidRuntime(27213): at android.view.View.performClick(View.java:3540)
06-24 01:03:43.602: E/AndroidRuntime(27213): at android.view.View$PerformClick.run(View.java:14167)
06-24 01:03:43.602: E/AndroidRuntime(27213): at android.os.Handler.handleCallback(Handler.java:605)
06-24 01:03:43.602: E/AndroidRuntime(27213): at android.os.Handler.dispatchMessage(Handler.java:92)
06-24 01:03:43.602: E/AndroidRuntime(27213): at android.os.Looper.loop(Looper.java:137)
06-24 01:03:43.602: E/AndroidRuntime(27213): at android.app.ActivityThread.main(ActivityThread.java:4558)
06-24 01:03:43.602: E/AndroidRuntime(27213): at java.lang.reflect.Method.invokeNative(Native Method)
06-24 01:03:43.602: E/AndroidRuntime(27213): at java.lang.reflect.Method.invoke(Method.java:511) …
Run Code Online (Sandbox Code Playgroud) android ×5
java ×5
brightcove ×1
calendar ×1
date ×1
dayofweek ×1
double ×1
listview ×1
log4j ×1
logging ×1
media-player ×1
networking ×1