我只想使用 GPS 获取位置。我不想在这个应用程序中使用互联网和 GPRS。我的代码如下;告诉我我哪里错了。
代码:
package com.getlocation;
import android.app.Activity;
import android.content.Context;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
public class UseGps extends Activity {
/** Called when the activity is first created. */
private String provider;
LocationManager locationManager;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main); /*
* Use the LocationManager class to
* obtain GPS locations
*/
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
LocationListener mlocListener = new MyLocationListener();
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_COARSE); …Run Code Online (Sandbox Code Playgroud) 在这里,我想知道strcpy() and strcat()缺点
我想了解嵌入式域/环境中的这些功能危险区域.
有人告诉我,我们从不使用strcpy,strcat and strlen嵌入式域中的函数,因为它以null结尾,有时我们处理加密数据和null字符,所以我们无法获得实际结果,因为这些函数停止在null字符上.
所以我想知道这些功能的所有东西和其他替代品.我们如何使用其他替代功能
在这里,我想为字符串制作regx,仅包含0到6个数字.此字符串包含0到6个这样的数字.
Example-1 : "010002030405" Valid String
Run Code Online (Sandbox Code Playgroud)
这个字符串只包含0到6个数字所以我在这里使用了这个regx "[0-6]*".但是我想在这个字符串中验证还有一件事,我想在奇数位置只需要0,而不是奇数位置.0可以放在奇数和偶数两个,但1-6将只放置偶数位置.
在这里,我给了你一些有效和无效的字符串示例
Valid : 000102000004
invalid : 0023015006
Run Code Online (Sandbox Code Playgroud)
在这里,我使用此代码请建议我或告诉我我必须在我的regx中更改以满足以下验证
1) String contains only 0-6 numbers nothing else.
2) 1-6 would be only even positions only they would not be at odd position ever, 0 would be odd and even position.
Run Code Online (Sandbox Code Playgroud)
代码:
public boolean isOptions(String input) {
String patternString = "[0-6]*";
Pattern pattern = Pattern.compile(patternString);
return pattern.matcher(input).matches();
}
Run Code Online (Sandbox Code Playgroud) String quote = "Now is the time for all good "+
"men to come to the aid of their country.";
Run Code Online (Sandbox Code Playgroud)
我想在运行时检测断线,当我点击按钮我想知道新线来..因为在TEXTVIEW我想输出相同像这样的字符串没有变化..所以告诉我一些想法或逻辑或源代码....
嗨朋友们,我希望获得两个地理点之间的距离.但在这里,我的申请中有一个问题.当我进入海上位置的一个地理位置和任何一个城市之一,所以我得到kml文件中kml文件nodata的响应...我想使用谷歌地图找到两个城市之间的距离..
我想知道json如何工作以及我们如何获得响应表单url然后我想解析这个响应.
这里我有一个字符串表示字符数组.此数组也包含分隔符.现在我想只取出没有这个分隔符的字符串.
我正在使用strtok功能.
我想用这个分隔符分隔我的所有单词.
但是这里我在这段代码中遇到了一些问题.
请让我知道,如果我做错了或告诉我以不同的方式实现这个简单易行的方法,也要考虑内存风险.
这条线pch = strtok (str,&sep);没什么.问题只在这里.
码
/* strtok example */
#include <stdio.h>
#include <string.h>
#define SEPRATOR 0x03
int main ()
{
char str[1024];
int count = 0;
char sep;
memset(str,0,1024);
sep = SEPRATOR;
memcpy(str,"1",strlen("1"));
count = count + strlen("1");
str[count++] = sep;
memcpy(str+count,"0",strlen("0"));
count = count + strlen("0");
str[count++] = sep;
memcpy(str+count,"2",strlen("2"));
count = count + strlen("2");
str[count++] = sep;
memcpy(str+count,"abc_1.0.xyz",strlen("abc_1.0.xyz"));
count = count + strlen("abc_1.0.xyz");
str[count++] = sep;
memcpy(str+count,"3",strlen("3"));
count = …Run Code Online (Sandbox Code Playgroud) 我有一个字符串喜欢"01030920316".当我要转换这个字符串时,然后转换为字节,然后给出下面的输出为java
output in java : Tag in bytes : 0, 0, 0, 0, 61, 114, -104, 124
Run Code Online (Sandbox Code Playgroud)
当我得到这个输出时,我在C中做同样的事情
output in C : Tag in bytes : 124,152,114,61,0,0,0,0
Run Code Online (Sandbox Code Playgroud)
在这里,我理解-104 and 152因为有符号和无符号之间的不同,但是为什么在java和C中最初为0.对于这种行为,当我的这个字节进入C程序端进行验证时,我遇到了问题.
请解释我发生问题的地方.
Java程序:
final byte[] tagBytes = ByteBuffer.allocate(8)
.putLong(Long.parseLong("01030920316")).array();
System.out.println("Tag in bytes >> " + Arrays.toString(tagBytes));
Run Code Online (Sandbox Code Playgroud)
C程序:
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
/** To access long long values as a byte array*/
typedef union uInt64ToByte__
{
uint64_t m_Value;
unsigned char m_ByteArray[8];
}uInt64ToByte;
int main()
{
uInt64ToByte …Run Code Online (Sandbox Code Playgroud) XML文件"&&"在节点的属性值中包含时无法解析.
XML文件:
<?xml version="1.0" encoding="UTF-8" ?>
<test version="0.0.3" >
<SFTP ipaddress="12.12.12.12" port="22" uname="abc" pwd="abc&&" path="/testdev" />
</test>
Run Code Online (Sandbox Code Playgroud)
什么时候使用pwd ="abc &&"那时它给我这样的错误,如果我不会使用特殊字符而不是它的工作正常.
错误:
At line 3, column 62: not well-formed (invalid token)
org.apache.harmony.xml.ExpatParser$ParseException: At line 3, column 62: not well-formed (invalid token)
at org.apache.harmony.xml.ExpatParser.parseFragment(ExpatParser.java:515)
at org.apache.harmony.xml.ExpatParser.parseDocument(ExpatParser.java:474)
at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:321)
at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:279)
at com.test.bl.ConfigurationParser.parseFile(ConfigurationParser.java:61)
at com.test.ui.LoginActivity$ConfigurationXMLParseOperation.doInBackground(LoginActivity.java:209)
at com.test.ui.LoginActivity$ConfigurationXMLParseOperation.doInBackground(LoginActivity.java:1)
at android.os.AsyncTask$2.call(AsyncTask.java:287)
at java.util.concurrent.FutureTask.run(FutureTask.java:234)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
at java.lang.Thread.run(Thread.java:856)
Run Code Online (Sandbox Code Playgroud)
代码:
public void parseFile(final InputStream inputStream) throws ParserConfigurationException,
SAXException, IOException …Run Code Online (Sandbox Code Playgroud) 这里我有这种类型的字符串,我想将此字符串拆分为每个元素,并希望为数字创建一个arraylist(整数)或一个整数数组.
我有这样的字符串作为一个例子: 123|00,124|01,125|00,126|01
我想先在一个包含的列表中分隔所有元素
123|00
124|01
125|00
126|01
Run Code Online (Sandbox Code Playgroud)
之后我想制作一个只有的整数数组列表或整数数组
123
124
125
126
Run Code Online (Sandbox Code Playgroud)
请任何人都可以建议我怎么做
谢谢
码:
List<Integer> numberList = new ArrayList<Integer>();
HashMap<Integer, Integer> statusMap = new HashMap<Integer, Integer>();
for (String tripnumber : tripNumbers) {
int number = Integer.parseInt(tripnumber.split("[|]")[0]);
Logger.d(TAG, "Trip number in Status Message = "+number);
int flag = Integer.parseInt(tripnumber.split("[|]")[1]);
Logger.d(TAG, "TM flag = "+flag);
if (number > 0) {
statusMap.put(number, flag);
numberList.add(number);
}
}
Run Code Online (Sandbox Code Playgroud) android ×8
java ×5
c ×3
string ×2
byte ×1
embedded ×1
long-integer ×1
regex ×1
sax ×1
strtok ×1
validation ×1
xml-parsing ×1