我已经创建了一个client类型MqttClient,如下面的代码所示,我创建了一个客户端并且它是它的Asynchronous callback.问题是,
1 - 当我运行程序时,System.out.println("Client is Connected");出现了,但是我没有收到onSuccess来自o的响应onFailure,为什么?我在代码中做错了.
2-i实现了static IMqttAsyncClient asynchClientCB = new IMqttAsyncClient()接口,但由于我有一个类型的客户端MqttClient,我不能使用这个IMqttAsyncClient接口.我尝试使用mqttAsynchClien但是因为我为java编程而不是因为Android我无法使用它.如何使用IMqttAsyncClient界面.?
Update_1
在下面的代码"Updated_code_1",我稍微修改了的代码,但我期望每个i成功地连接到时间broker在消息onSuccess要被打印同步回调,并且在消息onFailure中onnection的情况下,要被打印同步callbck终止如当我故意断开网络.但是在我连接到的时候broker,既没有onSuccess也没有onFailur任何事情.那么,它们的设计目的是什么?
*Update_2_17_Dec_2014
我有一个询问可能会引导我们找到解决方案,也就是说,如果我通过有线/无线网络连接到代理,这有关系吗?会改变同步和异步监听器的行为吗?
Updated_1_code:
MqttConnectOptions opts = getClientOptions();
client = MQTTClientFactory.newClient(broker, port, clientID);
if (client != null) {
System.out.println("Client is not Null");
client.setCallback(AsynchCallBack);
if (opts != null) {
iMQTTToken …Run Code Online (Sandbox Code Playgroud) 由于指定clienID仅在类的特征MqttAndroidClient,和使用类时不能指定IMqttClient和IMqttAsynchClient.
连接客户端的唯一目的是ID什么?
在我正在开发的应用程序中,当我触摸设备的屏幕时,我连接到服务器,我使用AsyncTask显示忙碌的指示器,在这一步我没有问题.但是当我连接并按下home buttom"应用程序进入onPause"并且我将应用程序再次显示为"onResume"并触摸屏幕再次连接到服务器,我收到以下发布的logCat错误.
注意:在onPause我urnRegister WiFi接收器,我断开与服务器的连接.logCat输出显示AsyncTask的调用回调序列
我不知道为什么我收到IllegalArgumentException,我读了一些关于它的postes,我测试了名为"client"的对象,它永远不会为null
LogCat:
03-09 14:26:13.413: D/MainActivity(17065): @MQTTAsynchTask(): constructor called
03-09 14:26:13.413: D/MainActivity(17065): @MQTTAsynchTask(): client is not null
03-09 14:26:13.413: D/MainActivity(17065): @MQTTAsynchTask(): onPreExecute().
03-09 14:26:13.422: D/MainActivity(17065): @MQTTAsynchTask(): doInBackground().
03-09 14:26:13.433: E/AndroidRuntime(17065): FATAL EXCEPTION: pool-1-thread-1
03-09 14:26:13.433: E/AndroidRuntime(17065): Process: com.example.mqtt_designlayout_02, PID: 17065
03-09 14:26:13.433: E/AndroidRuntime(17065): java.lang.IllegalArgumentException: Invalid ClientHandle
03-09 14:26:13.433: E/AndroidRuntime(17065): at org.eclipse.paho.android.service.MqttService.getConnection(MqttService.java:552)
03-09 14:26:13.433: E/AndroidRuntime(17065): at org.eclipse.paho.android.service.MqttService.connect(MqttService.java:318)
03-09 14:26:13.433: E/AndroidRuntime(17065): at org.eclipse.paho.android.service.MqttAndroidClient.doConnect(MqttAndroidClient.java:427)
03-09 14:26:13.433: E/AndroidRuntime(17065): at org.eclipse.paho.android.service.MqttAndroidClient.access$2(MqttAndroidClient.java:417)
03-09 14:26:13.433: E/AndroidRuntime(17065): at org.eclipse.paho.android.service.MqttAndroidClient$1.run(MqttAndroidClient.java:395)
03-09 14:26:13.433: E/AndroidRuntime(17065): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) …Run Code Online (Sandbox Code Playgroud) 我正在尝试ListView使用自定义布局创建.listView应该看起来像item.xml下面发布的每个项目.
在代码中,我用过
adapter = new ArrayAdapter<T>(getApplicationContext(), R.layout.listi_tems_layout, topicsList);
Run Code Online (Sandbox Code Playgroud)
但它不起作用,因为ArrayAdapter<T>接受第二个参数的构造函数int就像
android.R.layout.simple_list_item_1
,在我的情况下,它是自定义布局
R.layout.listi_tems_layout
Run Code Online (Sandbox Code Playgroud)
我应该使用哪个适配器或如何解决这个问题.谢谢
项目:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="3">
<TextView
android:id="@+id/tvlist_topic"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<ImageView
android:id="@+id/ivList_delete"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:clickable="true"
android:src="@drawable/delete_icon"
android:contentDescription="icon to delete item from the Listview"
android:layout_weight="1"/>
<CheckBox
android:id="@+id/cbList_hook"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:checked="false"
android:layout_weight="1"/>
Run Code Online (Sandbox Code Playgroud)
主要布局:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="${relativePackage}.${activityClass}" >
....
....
....
<ListView
android:id="@+id/lvEco_topics"
android:layout_width="match_parent"
android:layout_height="470dp"
android:layout_below="@id/tvEco_topic"
android:layout_marginTop="30dp"
android:scrollbars="vertical"
android:divider="@android:drawable/alert_light_frame"></ListView>
<Button …Run Code Online (Sandbox Code Playgroud) 我想在应用程序进入 onPause 时保存 textView 的值。所以我实现了onSaveInstanceState和onRestoreInstanceState。但如下面的 logcat 输出所示,onRestoreInstanceState 从未被调用。
我知道 onRestoreInstanceState 和 onSaveInstanceState 都不属于应用程序生命周期的一部分,那么为什么 onSaveInstanceState 会被调用,而 onRestoreInstanceState 不会被调用呢?以及如何调用onRestoreInstanceState?
代码:
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
Log.w(TAG, LogAnd.i("onResume", ""));
btAdapter = BluetoothAdapter.getDefaultAdapter();
if (btAdapter == null) {
tvStatus.setText("[" + SysUtils.getDeviceName() + "] no Bluetooth installed.");
} else {
tvStatus.setText("[" + SysUtils.getDeviceName() + "] Bluetooth installed.");
}
}
@Override
protected void onSaveInstanceState(Bundle outState) {
// TODO Auto-generated method stub
super.onSaveInstanceState(outState);
Log.w(TAG, LogAnd.i("onSaveInstanceState", ""));
outState.putString("statusText", tvStatus.getText().toString());
}
@Override …Run Code Online (Sandbox Code Playgroud) 我编写了下面的代码,如您所见,在构造函数中,我调用了一些方法来执行某些操作.现在我要问的是,从构造函数中调用这些方法是一个好习惯还是将这些方法声明为public并从类info中实例化一个对象,让对象调用这些方法?这有什么好的做法?
class Info {
public RoadInfo(String cityName, double lat, double lng) throws FileNotFoundException, SAXException, IOException, XPathExpressionException {
// TODO Auto-generated constructor stub
this.cityname = cityName;
this.lat = lat;
this.lng = lng;
this.path = "c:"+File.separatorChar+this.cityname+".xml";
System.out.println(path);
this.initXPath();
this.method1()
this.method2()
..
this.expr = "//node[@lat='"+this.lat+"'"+"]/following-sibling::tag[1]/@v";
this.xPath.compile(this.expr);
String s = (String) this.xPath.evaluate(this.expr, this.document, XPathConstants.STRING);
System.out.println(s);
}
Run Code Online (Sandbox Code Playgroud) 我想用超过5亿行填充数据库表,我有以下insert方法:
public void insertRecord(Record rec) throws SQLException, ClassNotFoundException {
if (this.isTableExists(this.TABLE_NAME)) {
Connection conn = this.getConnection();
conn.setAutoCommit(true);
PreparedStatement ps = conn.prepareStatement("insert into "+this.TABLE_NAME+" ("+this.NODE_ID_COL+", "+this.LAT_COL+", "+this.LNG_COL+", "+this.XML_PATH_COL+") values (?, ?, ?, ?)");
ps.setString(1, rec.getNodeID());
ps.setString(2, rec.getLat());
ps.setString(3, rec.getLng());
ps.setString(4, rec.getPath());
ps.addBatch();
ps.executeBatch();
ps.close();
conn.close();
} else {
Log.e(TAG, "insertRecord", "table: ["+this.TABLE_NAME+"] does not exist");
}
}
Run Code Online (Sandbox Code Playgroud)
我的问题是,因为我将插入大量的行:
我有一个名为的班级matFactory().在其中,有一个名为的方法lastAddedObj(..).
后一种方法接收ArrayList一个参数作为参数,并返回此列表中最后添加的对象.
我的问题是:我有两个类型的列表,ArrayList<Mat>和ArrayList<MatOfKeyPoint>我想的方法lastAddedObject是适用于这两种类型.正如您在下面看到的方法签名:
public Mat lastAddedObj(ArrayList<Mat> list) {
....
....
return list.get(size -1);
}
Run Code Online (Sandbox Code Playgroud)
我希望这种方法能够两个ArrayList<Mat>和ArrayList<MatOfKeyPoint>,因为当你看到上面的,如果我通过ArrayList<Mat>它将返回Mat对象,如果将通过ArrayList<MatOfKeyPoint>将返回MatOfKeyPoint对象.
如何解决这个问题?
在下面的代码中,我正在读取图像并显示它具有的通道数量及其深度.
结果是通道:3和深度:0
据我所知,深度应代表每个通道的位数.
深度为零意味着什么?
代码:
public static void main(String[] args) {
System.loadLibrary(org.opencv.core.Core.NATIVE_LIBRARY_NAME);
Mat imgSrc = new Mat();
imgSrc = Highgui.imread(PATH);
if (imgSrc.empty()) {
System.out.println("image is empty");
return;
}
System.out.println("channels: " + imgSrc.channels());
System.out.println("depth: " + imgSrc.depth());
}
Run Code Online (Sandbox Code Playgroud)
}
我在 java JDBC 中使用 sqlite,我创建了下表:
private final String sqlTableNode = "CREATE TABLE "+this.TABLE_NODE+
" ( "+this.NODE_TABLE_ID_COL+" INTEGER, " +
this.NODE_TABLE_NODE_ID_COL+" TEXT NOT NULL, " +
this.NODE_TABLE_LAT_COL+" TEXT NOT NULL, " +
this.NODE_TABLE_LNG_COL+" TEXT NOT NULL, " +
"PRIMARY KEY ("+this.NODE_TABLE_LAT_COL+", "+this.NODE_TABLE_LNG_COL+") );";
Run Code Online (Sandbox Code Playgroud)
我的问题是,如何使第一列“this.NODE_TABLE_PK_COL”在它不是主键时自动递增?
我有一个填充了DMatch对象的列表,该对象包含属性"distance".
我想要做的是根据"距离"按升序或降序对该列表进行排序.
在下面的代码中,我使用了Comparator类并逐级排序,但是索引的输出(8,9,10,11)排序不好.
请让我知道我做错了什么以及如何解决这个错误
代码:
Collections.sort(list_RawMatchesMatDMatch, ascOrder);
for (int i = 0; i < list_RawMatchesMatDMatch.size(); i++) {
Log.D(TAG, "main", "rawMatDMatchLiat(" + i + ").distance: " + list_RawMatchesMatDMatch.get(i).distance);
}
static Comparator<DMatch> ascOrder = new Comparator<DMatch>() {
public int compare(DMatch arg0, DMatch arg1) {
// TODO Auto-generated method stub
return (int) (arg1.distance - arg0.distance);
}
};
Run Code Online (Sandbox Code Playgroud)
输出:
Debug: MainClass -> main: rawMatDMatchLiat(0).distance: 454.26645
Debug: MainClass -> main: rawMatDMatchLiat(1).distance: 447.3835
Debug: MainClass -> main: rawMatDMatchLiat(2).distance: 442.294
Debug: MainClass -> main: rawMatDMatchLiat(3).distance: …Run Code Online (Sandbox Code Playgroud) 我不知道为什么我得到平均值= 0.下面的代码显示了我如何计算它,下面张贴的图像显示了我得到的输出
码
float avg = (goodMatchesList.size()/rawMatchesListSorted.size()) * 100;
Log.D(TAG, "descMatcher", "avg: " + avg);
Log.D(TAG, "descMatcher", "min: " + minDist);
Log.D(TAG, "descMatcher", "max: " + maxDist);
Log.D(TAG, "descMatcher", "objComputedDescExt.rows: " + matFactory.getComputedDescExtMatAt(0).rows());
Log.D(TAG, "descMatcher", "rawMatchesListSorted.size: " + rawMatchesListSorted.size());
Log.D(TAG, "descMatcher", "goodMatchesList.size: " + goodMatchesList.size());
Run Code Online (Sandbox Code Playgroud)
