小编gho*_*der的帖子

将原始资源设置为铃声

我已经阅读了这2个帖子link1和这个link2,但是代码似乎对我不起作用。

这是我的代码:

File newSoundFile = new File("/sdcard/media/ringtone", "myringtone.oog");
            Uri mUri = Uri.parse("android.resource://com.pack.android.myapp/R.raw.song1");
            ContentResolver mCr = Main.this.getContentResolver();
            AssetFileDescriptor soundFile;
            try {
                   soundFile= mCr.openAssetFileDescriptor(mUri, "r");
               } catch (FileNotFoundException e) {
                   soundFile=null;   
               }

               try {
                  byte[] readData = new byte[1024];
                  FileInputStream fis = soundFile.createInputStream();
                  FileOutputStream fos = new FileOutputStream(newSoundFile);
                  int i = fis.read(readData);

                  while (i != -1) {
                    fos.write(readData, 0, i);
                    i = fis.read(readData);
                  }

                  fos.close();
               } catch (IOException io) {
               }
               ContentValues values = new ContentValues();
               values.put(MediaStore.MediaColumns.DATA, newSoundFile.getAbsolutePath()); …
Run Code Online (Sandbox Code Playgroud)

android ringtone

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

时间vs日期vs日历java

那么在我的应用我想获得当前的日期和月份abnd地方时(currentTimeZone小时),并根据其值显示一些东西.

我已阅读了几个解决方案,并使用了以下内容:

Calendar c = Calendar.getInstance(); 
            int day=c.get(Calendar.DATE);
            int month=c.get(Calendar.MONTH);
Run Code Online (Sandbox Code Playgroud)

或这个

Time today = new Time(Time.getCurrentTimezone());
            today.setToNow();
            int day2=today.monthDay;
            int month2=today.month;
Run Code Online (Sandbox Code Playgroud)

我的问题是:

1)考虑到他们的结果,哪一个更"稳定"?我的意思是它没有任何问题.

2)此外,他们是否都考虑了TimeZone?我认为第二个确实如此,但日历呢?

3)我尝试了这个代码,我找到了:

SimpleDateFormat s = new SimpleDateFormat("ddMMyyyyhhmmss");
            String format = s.format(new Date());
Run Code Online (Sandbox Code Playgroud)

我得到Date()必须有一个参数的错误.很奇怪,因为在每个答案中他们都这样使用它.

怎么了?

4)你建议我用什么?我唯一想要的是在当前月份,日期,小时与一些存储在内存中的简单比较.(例如,如果是1月29日,则显示该事件.如果是19.00 am发送通知,依此类推.)

java time android calendar date

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

通过串行Arduino和XBee读取数据

我有以下内容:

两个Arduinos和两个XBees.我想将数据从一个发送到另一个.XBees进行通信,因为我有建议测试(将一个XBee与Arduino连接,另一个连接到PC,从一个写入,在另一个终端中观察另一个).

现在我想将数据从一个发送到另一个:

这是我的两个脚本:

对于发送(在以前发送所有字母的测试中测试):

#include <SoftwareSerial.h>

SoftwareSerial xbee(2, 3); // RX, TX
char c = 'A';
int  pingPong = 1;

void setup()
{
    Serial.begin(9600);

    Serial.println( "Arduino started sending bytes via XBee" );

    //Set the data rate for the SoftwareSerial port
    xbee.begin(9600);
}

void loop() {
    // Send character via XBee to other XBee connected to Mac
    // via USB cable.
    xbee.write( c );

    //--- Display the character just sent on console. ---
    Serial.println( c ); …
Run Code Online (Sandbox Code Playgroud)

arduino

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

NSNull isEqualToString:ObjC上无法识别的选择器

好吧,我的代码是这样的:

我有两个字符串,place and date.我正在使用它们:

cell.datePlace.text= [NSString stringWithFormat:@"%@, %@",date,place];
Run Code Online (Sandbox Code Playgroud)

在某些条目中,输出如下:

"21/10/2012, <null>"
"21/11/2012, None"
"21/12/2013, London"
Run Code Online (Sandbox Code Playgroud)

我的应用程序没有崩溃,但我希望这个地方只有在不为空且不等于无时才可见.

所以我尝试了这个:

 NSString * place=[photo objectForKey:@"place"];


if ([place isEqualToString:@"None"]) {
                cell.datePlace.text= [NSString stringWithFormat:@"%@",date];
            } else {
                cell.datePlace.text= [NSString stringWithFormat:@"%@, %@",date,place];
            }
Run Code Online (Sandbox Code Playgroud)

问题是当<null>我的应用程序崩溃的地方,我得到了这个错误:

[NSNull isEqualToString:] unrecognized selector send to instance
Run Code Online (Sandbox Code Playgroud)

所以,我试过这个:

if (place) {
            if ([place isEqualToString:@"None"]) {
                cell.datePlace.text= [NSString stringWithFormat:@"%@",date];
            } else {
                cell.datePlace.text= [NSString stringWithFormat:@"%@, %@",date,place];
            }
        } else {
            cell.datePlace.text= [NSString stringWithFormat:@"%@",date];
        }
Run Code Online (Sandbox Code Playgroud)

但问题仍然存在.

string objective-c ios

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

无法获得GoLang oracle包

我对GoLang来说是全新的,所以我很有可能搞砸了我的设置.

这是我有的:

echo $GOPATH
/Users/name/Documents/Developer/Go_Workspace
Run Code Online (Sandbox Code Playgroud)

这个工作.

name$ go get -v golang.org/x/tools/cmd/oracle
Run Code Online (Sandbox Code Playgroud)

它在Go_Workspace中创建了2个子文件夹 - > src,bin,pkg.

然后,当我尝试:

go get -u golang.org/x/tools/cmd/oracle
package golang.org/x/tools/cmd/oracle: cannot find package "golang.org/x/tools/cmd/oracle" in any of:
    /usr/local/go/src/golang.org/x/tools/cmd/oracle (from $GOROOT)
    /Users/name/Documents/Developer/Go_Workspace/src/golang.org/x/tools/cmd/oracle (from $GOPATH)
Run Code Online (Sandbox Code Playgroud)

启用后,-v我看到:

Fetching https://golang.org/x/tools/cmd/oracle?go-get=1
Parsing meta tags from https://golang.org/x/tools/cmd/oracle?go-get=1 (status code 200)
get "golang.org/x/tools/cmd/oracle": found meta tag main.metaImport{Prefix:"golang.org/x/tools", VCS:"git", RepoRoot:"https://go.googlesource.com/tools"} at https://golang.org/x/tools/cmd/oracle?go-get=1
get "golang.org/x/tools/cmd/oracle": verifying non-authoritative meta tag
Fetching https://golang.org/x/tools?go-get=1
Parsing meta tags from https://golang.org/x/tools?go-get=1 (status code 200)
golang.org/x/tools (download)
package golang.org/x/tools/cmd/oracle: cannot find …
Run Code Online (Sandbox Code Playgroud)

macos go go-guru

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

无法更新到php 5.4 - AWS ec2

我的实例上有php5.3和httpd2.2.现在我需要升级到php 5.4.

我遵循这些指示:

http://codingsteps.com/install-apache-2-4-php-5-4-php-apc-on-amazon-ec2-with-amazon-linux/
Run Code Online (Sandbox Code Playgroud)

我有sudo yum remove所有的冲突,现在剩下的两个是:

Error: httpd24-tools conflicts with httpd-tools-2.2.29-1.4.amzn1.x86_64
Error: httpd24 conflicts with httpd-2.2.29-1.4.amzn1.x86_64
Run Code Online (Sandbox Code Playgroud)

但如果我跑了例如:

[ec2-user@ip-172-31-44-86 ~]$ sudo yum install -y httpd24 php54
...
--> Finished Dependency Resolution
Error: httpd24-tools conflicts with httpd-tools-2.2.29-1.4.amzn1.x86_64
Error: httpd24 conflicts with httpd-2.2.29-1.4.amzn1.x86_64
 You could try using --skip-broken to work around the problem
 You could try running: rpm -Va --nofiles --nodigest
[ec2-user@ip-172-31-44-86 ~]$
Run Code Online (Sandbox Code Playgroud)

编辑:我想删除它们:

sudo yum remove httpd-tools-2.2.29-1.4.amzn1.x86_64
Run Code Online (Sandbox Code Playgroud)

但我明白了:

Loaded plugins: priorities, update-motd, upgrade-helper
No Match for argument: httpd-tools-2.2.29-1.4.amzn1.x86_64
No …
Run Code Online (Sandbox Code Playgroud)

php apache amazon-web-services

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

pytest:无法模拟我的班级的 __init__

我有一个自定义Db类,它具有基本操作。我正在尝试围绕它编写测试 - 在__init__我的班级中,我正在连接到我想避免的实际数据库(因为我只是编写单元测试,不需要连接到实际数据库)。

这是我的代码:

@mock.patch( 'mydb.Db' )
@pytest.mark.parametrize( "input,expected", [
    (
        {
            'key'   : "x" ,
            'value' : 5   ,
        } , 
        [  "x = 5" ]
    ) ,
    ])
def test_where_statement( mock_db, input, expected):
    mock_db.__init__.return_value = None
    assert expected == mock_db.where( input[ "key"] , input[ "value" ] )._condition_list
Run Code Online (Sandbox Code Playgroud)

它在我将 return_value 设置为 None 的行上失败 - 问题是:

    def test_where_statement( mock_db, input, expected):
>       mock_db.__init__.return_value = None
E       AttributeError: 'instancemethod' object has no attribute 'return_value'
Run Code Online (Sandbox Code Playgroud)

我只想模拟 init 函数,然后能够运行 …

python unit-testing pytest

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

getIntent.getExtras.getString()中的null值

这是我第一次活动中的代码:

Intent i = new Intent(this, OtherScreen.class);
    i.putExtra("id1", "first");
    i.putExtra("id2", "second");
    startActivity(i);
Run Code Online (Sandbox Code Playgroud)

第一个,第二个是我想要传递的值.在我的另一堂课上我有这个:

Intent i = getIntent();
        Bundle extras = i.getExtras();
        String result = extras.getString("id1");
        System.out.println("yeah"+result);
Run Code Online (Sandbox Code Playgroud)

但是在我运行之后,我的结果是空的.你能帮助我吗?如果我以这种方式编写我的getString,我会收到语法错误.

String result = extras.getString(id1); //id1 cannot be resolved to a variable
String result = extras.getString("id1","default value"); // remove argument
Run Code Online (Sandbox Code Playgroud)

android android-intent

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

在每个列表视图行上设置不同的颜色

我已经看到了相关的答案,我不知道哪一个适合我.我有一个listView,每行都有一个textview.我想给出一些条件,每一行得到不同的颜色.(想象一下,我从数据库获取数据,并给出我得到的值,我希望文本设置为不同的颜色)我的代码如下所示:

public class TrailsConditionScreen extends ListActivity {
 public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        seeTrails();
    }
 private void seeTrails() {
    String[] help=new String[] {"foo","bar"};
    ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,R.layout.row,R.id.text1,help);
    setListAdapter(adapter);
 }
Run Code Online (Sandbox Code Playgroud)

到目前为止,此代码只是将它们打印在列表中.

现在我想从db中检索值时,给定值,我会在每一行上设置不同的颜色.想象我的代码在读取第一行时从我想要的表中检索数据,给定数字在listview的第一行设置适当的颜色.然后转到第二个单独的数据库,为列表的第二行设置颜色,依此类推..我已经成功实现了数据库中的读数,但我不知道如何在特定行上设置颜色.在伪代码中它看起来像这样.

 for i=0 to number of lines in db{
   read_data();
   if key_value=0 then color_of_line(i)=red;
  else color_of_line_i)=green;
}
Run Code Online (Sandbox Code Playgroud)

对此有何帮助?

android listview

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

C ++ 11和类构造函数中的可变参数模板

一般而言,我刚接触C ++模板,遇到过可变参数模板,并且想知道是否可能适合我的需求。

我有此代码,并且工作正常:

template< typename T, typename X1, typename X2 >
class MyClass
{
    public :

    MyClass( std::shared_ptr< T > track ,
             std::shared_ptr< X1 > x1   ,
             std::shared_ptr< X2 > x2   ) ;
}

template< typename T, typename X1, typename X2 >
MyClass < T,X1,X2 >::MyClass( std::shared_ptr< T > track ,
                              std::shared_ptr< X1 > x1   ,
                              std::shared_ptr< X2 > x2   ) : d_track( track ) , d_x1( x1), d_x2( x2 )
Run Code Online (Sandbox Code Playgroud)

但是,假设我想使其更通用-意味着X1,X2可以是随机数-例如,我可以拥有X3和X4。我想避免为我可能遇到的所有不同情况重复构造函数,因为到目前为止还不知道它们-可变参数模板是否可以解决此问题?

在代码草案中,我的意思是这样的:

template< typename T, typename... XS >
MyClass …
Run Code Online (Sandbox Code Playgroud)

c++ templates variadic-templates

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