小编Ant*_*neG的帖子

亚行突然不再检测到我的设备了

[更新1]在以下尝试使这个东西工作期间,我重新启动了几次.然而今天早上我打开我的电脑,现在列出了设备...但是我会保持我的问题开放几天,看看这种奇怪的行为是否会回来.[/ update 1]

adb在Arch Linux(32位)下突然停止报告我的手机,它通常会这样做.我尝试了以下所有命令作为sudo和普通用户,同样缺乏结果.

[antoine@amadeus /home/antoine/]$ sudo gvim /etc/udev/rules.d/51-android.rules  
Run Code Online (Sandbox Code Playgroud)

我在其中写道:

SUBSYSTEM=="usb", ATTR{idVendor}=="0bb4", ATTR{idProduct}=="0ccf", MODE="0666", OWNER="antoine"
Run Code Online (Sandbox Code Playgroud)

然后我做了:

[antoine@amadeus /home/antoine/]$ sudo udevadm control --reload-rules
Run Code Online (Sandbox Code Playgroud)

该设备在那里:

[antoine@amadeus /home/antoine/]$ lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation …
Run Code Online (Sandbox Code Playgroud)

linux android adb

9
推荐指数
1
解决办法
8788
查看次数

多对多关系中的外键关键

上下文

我们正在建立一个介绍博客.到数据库课程项目.

在我们的博客中,我们希望能够Labels开启Posts.它Labels本身不存在,只有与a相关时才会存在Posts.这样,Labels任何不使用的都不Posts应该留在数据库中.

不止一个Label可以属于单个Post,而且多个Post可以使用一个Label.

我们正在使用SQLite3(本地/测试)和PostgreSQL(部署).

履行

下面是我们用来创建这两个表的SQL(SQLite3风格)以及关系表:

帖子

CREATE TABLE IF NOT EXISTS Posts(
   id INTEGER PRIMARY KEY AUTOINCREMENT,
   authorId INTEGER,
   title VARCHAR(255),
   content TEXT,
   imageURL VARCHAR(255),
   date DATETIME,
   FOREIGN KEY (authorId) REFERENCES Authors(id) ON DELETE SET NULL
)
Run Code Online (Sandbox Code Playgroud)

标签

CREATE TABLE IF NOT EXISTS Labels(
   id INTEGER PRIMARY KEY AUTOINCREMENT,
   name VARCHAR(255) UNIQUE,
   -- This is not working:
   FOREIGN …
Run Code Online (Sandbox Code Playgroud)

sql sqlite postgresql database-design many-to-many

9
推荐指数
1
解决办法
2万
查看次数

Java - 获取/设置接收和返回"null"的方法

我是Java的初学者.为了训练目的,我正在尝试为自己建立一个国际象棋游戏应用程序.在我的类Case中,将用于实现我的所有64个板块的情况,我编写get/set方法来查找案例实例中是否存在Piece占用者.

我读到返回"null"是一种不好的做法,所以我抛出异常来表示案件是免费的.但是,我想知道如何将占用者的指针设置为"null"; 我可以简单地将"null"作为参数调用此方法吗?

此外,可以采取/返回"null"是一个可接受/良好的做法?

public Piece getOccupant(){
    if (this.occupant == null)
        throw new IllegalArgumentException(this.occupant + " is Empty");
    return this.occupant;
}
public void setOccupant(Piece newOccupant){
    this.occupant = newOccupant;
}
Run Code Online (Sandbox Code Playgroud)

谢谢!

[更新]

感谢您的所有意见,想法,更正和建议.以下是此部分代码的更新版本,我对此感到满意,因为它有助于实现其目的(通过实践增加我的理解).

/*
 * Modifiers of Occupant
 */
/**
 * Used to find if a Piece is located in this Cell
 * @return a Piece reference to the occupant.  Will send a 
 * null pointer if cell is empty
 */
public Piece getOccupant(){
    return this.occupant;
}
/**
 * Used to …
Run Code Online (Sandbox Code Playgroud)

java null get set

8
推荐指数
2
解决办法
1万
查看次数

哈希位图的廉价/快速方法?

我有一个应用程序,需要一个图片库(所有在Jpeg),并给出每个可能的对之间的相似性分数.在每个时间点,只能选择一对,并显示其相似性得分.

比较两个图像的算法具有一定的性能成本,因此比较一对需要几秒钟.

选择两张照片时:

  1. 如果从未对比对,则得分显示"尚未得分".用户可以单击"得分"按钮,该对将被发送到对要计算的分数进行排队的线程.示例:http://db.tt/gb1Yk6yx
  2. 如果该对当前处于要计算的队列中,则得分字段显示"计算...".示例:http://db.tt/OvS1qGP3
  3. 如果已经比较了该对,则显示该对附加的分数.示例:http://db.tt/m2OQGybW

示例(执行批处理时):http://db.tt/iD67SdCp

如果从未计算过分数,并且用户单击"分数",则该字段将切换为"计算...",然后将在计算完成时显示分数.

在分数字段中显示任何内容之前,当选择两对时,它们附加的位图将被发送到HashMap,以验证这两个位图是否已经有附加分数,在这种情况下它只是返回它.如果没有得分,则将作业发送到队列中.

要知道缓存中是否存在分数,我需要找到一种方法来对该对进行散列,以便我可以使用生成的密钥来查找缓存.这就是我的问题所在.有意义的是,两个Bitmap的散列应该很快.否则,我只是添加另一层计算.但是,我到目前为止散列两个Bitmap的方法是将它们发送到一个字节数组并获得它们的MD5校验和.像这样:

private Long getHashKey(Bitmap first, Bitmap second){

    // TODO this IS costly, it render useless the cache optimization.
    // also, it doesn't detect that comp(A,B) is the same as comp(B,A).
    // much work to do here.

    if(D) Profiling.start(TAG, "getHashKey");

    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    first.compress(Bitmap.CompressFormat.JPEG, 100, stream);

    byte[] firstArray = stream.toByteArray();
    second.compress(Bitmap.CompressFormat.JPEG, 100, stream);

    byte[] secondArray = stream.toByteArray();
    byte[] …
Run Code Online (Sandbox Code Playgroud)

java android caching

8
推荐指数
1
解决办法
3480
查看次数

Android中的自定义动态图表

[更新] 为了结束这个问题,我使用以下两种方法实现了我的图形(见下文). drawCurve()接收一个Canvas和一个数组float.数组已正确填充(时间戳由数组中的值索引假定)并且从0.0到1.0不等.数组被发送到一个循环方式的prepareWindowArray()位置windowStartfor windowSize-values 中取一个数组的块.

GraphView和数据提供者(蓝牙设备)使用的阵列是相同的.中间的类确保GraphView不读取蓝牙设备正在写入的数据.由于GraphView始终循环通过数组并在每次迭代时重绘它,它将根据蓝牙设备写入的数据进行更新,并通过强制蓝牙设备的写入频率到图表的刷新频率,我获得了平滑动画我的信号.

所述GraphViewinvalidate()方法是由所谓的Activity,其运行Timer来刷新图形在每x毫秒.刷新图形的频率是动态设置的,以便它适应来自蓝牙设备的数据流(它在其数据包的标题中指定其信号的频率).

GraphView在下面我写的答案中找到我的完整代码(在答案部分).如果您发现错误或优化方法,请告诉我们; 这将不胜感激!

/**
 * Read a buffer array of size greater than "windowSize" and create a window array out of it.
 * A curve is then drawn from this array using "windowSize" points, from left
 * to right.
 * @param canvas is a Canvas object on which the curve will be drawn. …
Run Code Online (Sandbox Code Playgroud)

android graph android-custom-view android-animation

7
推荐指数
1
解决办法
8314
查看次数

Android中不安全的蓝牙连接

我被一位教授挑战在Android上开发一个小型蓝牙演示应用程序.直到两周前,当他给我这个挑战时,我对Android的开发一无所知.我对Java编程也很陌生,所以我从远处开始.但无论如何...

所以我做了大部分的教程,我读到了Android中的蓝牙,查看了蓝牙聊天示例代码,我现在正在尝试做我的小应用程序.因此,对于我的演示,我将尝试在我的真实手机和蓝牙鼠标之间建立连接.我想在我的手机屏幕上移动一个形状以响应我的鼠标移动.

我遇到很多问题,但到目前为止我的主要问题是用不安全的鼠标打开一个插座.当我尝试使用该方法时listenUsingRfcommWithServiceRecord,它会将UUID作为参数.但是我的鼠标很可能没有UUID来响应,所以我猜这种方法并不好.

当我阅读有关此方法的文档时,它说要使用像鼠标这样的设备打开不安全的服务器套接字,我必须使用该listenUsingInsecureRfcommWithServiceRecord方法.但是当我调用它时,这个方法是不可用的,它以红色加下划线,而Eclipse表示它对于BluetoothAdapter类型是未定义的.

private BluetoothServerSocket connectDevice(BluetoothAdapter adapter, BluetoothDevice device){
    BluetoothServerSocket socket = null;
    try{
        socket = adapter.listenUsingInsecureRfcommWithServiceRecord(device.getName(), UUID.randomUUID());
    }
    catch(IOException e){
        Toast.makeText(this, "Connection failed.\n" + e.getMessage(), Toast.LENGTH_SHORT);
    }

    return socket;
}
Run Code Online (Sandbox Code Playgroud)

如果我做错了,请不要激怒我,这是我的第一个问题,我开始使用Java编程.

java android bluetooth serversocket

6
推荐指数
1
解决办法
6927
查看次数

传递指向成员函数的指针

我有一个具有实例函数(或方法?)的类.在一个实例中,我尝试将指向这些函数的指针传递给库.该库需要静态函数.

当我将指针传递给回调函数时,编译器会抱怨我的函数不是静态的.我试图将它们设为静态,但如果我这样做,那么我就无法从函数中访问实例字段.

我怎么能绕过这个?

类似的问题是:使用C++类成员函数作为C回调函数,他们建议将方法设置为静态.但是我做不到,或者我不知道我怎么做.

GlutController::GlutController (int argc, char **argv) {

   // stuff ..

   // Register callbacks
   glutSpecialFunc( OnSpecialKeys );  // Error, need static functions
   glutReshapeFunc( OnChangeSize );   // Error...
   glutDisplayFunc( OnRenderScene );  // Error...

   // stuff ..
}

GlutController::~GlutController() {

}

void GlutController::OnChangeSize(int aNewWidth, int aNewHeight){

   glViewport(0,0,aNewWidth, aNewHeight);
   mViewFrustrum.SetPerspective( APP_CAMERA_FOV,             // If this function is 
            float( aNewWidth ) / float( aNewHeight ),        // static, this won't 
            APP_CAMERA_NEAR,                                 // work
            APP_CAMERA_FAR );
   mProjectionMatrixStack.LoadMatrix(                        // Same here
            mViewFrustrum.GetProjectionMatrix() ); …
Run Code Online (Sandbox Code Playgroud)

c++ glut member-function-pointers function-pointers freeglut

5
推荐指数
1
解决办法
1311
查看次数

一种指定和初始化地图值类型的方法?

我想计算一行文字中的所有单词.我正在使用地图来执行此操作,其中包含键和值的整数.我不知道如何告诉Ruby所有的值都是整数.它迫使我在迭代器块中放置一个丑陋的分支:

# in the constructor
@individual_words = {}

def count_words_from( text_line )
  text_line.each do |line|
    line.scan(/\p{Word}+/)
    .reject{ |string| string =~ /\d/ }
    .each do |word|
      if @individual_words[ word ] == nil then   # This is ugly
        @individual_words[ word ] = 1            # This is ugly as well
      else
        @individual_words[ word ] += 1
      end
    end
  end
end
Run Code Online (Sandbox Code Playgroud)

简单来说,我想做类似这样的Java行:

Map<String, Integer> individualWords;
Run Code Online (Sandbox Code Playgroud)

以避免必须从改变一个字的第一次出现的类型NilInteger.

ruby initialization map

1
推荐指数
1
解决办法
558
查看次数

去奇怪的行为 - 变量没有正确递增

我有以下代码,如果它不存在,则向切片添加新元素.如果它确实存在,那么qty属性应该增加现有元素而不是添加新元素:

package main

import (
    "fmt"
)

type BoxItem struct {
    Id int
    Qty int
}

type Box struct {
    BoxItems []BoxItem
}

func (box *Box) AddBoxItem(boxItem BoxItem) BoxItem {

    // If the item exists already then increment its qty
    for _, item := range box.BoxItems {
        if item.Id == boxItem.Id {
             item.Qty++
             return item
        }
    }

    // New item so append
    box.BoxItems = append(box.BoxItems, boxItem)
    return boxItem
}


func main() {

    boxItems := []BoxItem{}
    box := Box{boxItems}

    boxItem := …
Run Code Online (Sandbox Code Playgroud)

go

1
推荐指数
1
解决办法
133
查看次数

基类具有不完整的类型

我有一个Point我继承的基类Point3D.但是,由于某种原因,类Point必须始终返回Point3D操作add,因此我将其包含在我的包含中.

这是我的班级Point:

#ifndef POINT_H
#define POINT_H

#include "Point3D.hpp"

class Point{

  public:
    Point(double, double, double);

    void print() const;
    Point3D add( const Point& );

  protected:
    double mX;
    double mY;
    double mZ;

};

#endif
Run Code Online (Sandbox Code Playgroud)

在我的班上Point3D,我知道我还没有遇到过Point我第一次被调用的定义(因为Point3D它包含在Point标题中),所以我定义class Point;,然后我定义我将使用的部分Point:

#ifndef POINT3D_H
#define POINT3D_H

#include <iostream>
#include "Point.hpp"  // leads to the same error if ommitted

class Point;    

class Point3D : public Point …
Run Code Online (Sandbox Code Playgroud)

c++ inheritance

0
推荐指数
1
解决办法
6725
查看次数