小编r0b*_*077的帖子

getLastKnownLocation返回NULL

我刚刚开始工作,但是当我关闭我的Wifi以确定我是否可以使用我的GPS获得更准确的位置时,它现在给我带来了一个NullPointer错误,我看不出原因.

首先调用下面的代码;

 public void onConnected(Bundle dataBundle) {
        connected = true;
        //Request an update from the location client to get current Location details
        mLocationClient.requestLocationUpdates(mLocationRequest,this);
        Toast.makeText(this, "Connected", Toast.LENGTH_SHORT).show();
    }
Run Code Online (Sandbox Code Playgroud)

然后需要调用此方法

public void onLocationChanged(android.location.Location location) {
        // Report to the UI that the location was updated
        String msg = "Updated Location: " +
                Double.toString(location.getLatitude()) + "," +
                Double.toString(location.getLongitude());
        if(tmp != location.getLatitude())
        {
            Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
        }
        tmp = location.getLatitude();
    }
Run Code Online (Sandbox Code Playgroud)

你可以看到我在那里有两个吐司,他们用实际的GPS坐标回来了,但是当我调用下面的代码时,它会在新的位置线上崩溃 getLastKnownLocation

public String getLocation()
    {
        // Get the location manager …
Run Code Online (Sandbox Code Playgroud)

gps android

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

Cos(90) 返回一个非常接近 0 的值,但我需要 0?

temp_x_btm_left = 0 & temp_y_btm_left=1 的值;

angle = 90;

//Moving the bottom left coordinates
_btm_left.real() = (temp_x_btm_left * cos(angle*PI/180)) 
                   - (temp_y_btm_left * sin(angle*PI/180));
_btm_left.imag() = (temp_x_btm_left * sin(angle*PI/180)) 
                   + (temp_y_btm_left * cos(angle*PI/180));
Run Code Online (Sandbox Code Playgroud)

该代码应该将对象逆时针旋转 90 度,它确实做到了,但_btm_left.imag()返回的值非常接近 0 = 1.437949e-009,而我确实需要它为 0。

我已经尝试过setprecision()setw()但似乎没有任何效果。有没有类似的方法或者我需要创建自己的方法来解决这个问题?

c++

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

在C#中打开路径中有空格的Word文档

我有这条路;

path = Cash Report\\30-03-2012 01-11-07 Cash Flow Report.Docx
Run Code Online (Sandbox Code Playgroud)

当我使用下面的代码打开文件时,它会尝试打开每个单词。所以它会尝试打开 cash.doc,然后打开 Report.doc 等等;

//Open the newly created file
        ProcessStartInfo startInfo = new ProcessStartInfo();
        startInfo.FileName = "WINWORD.EXE";
        startInfo.Arguments = path;
        Process.Start(startInfo);
Run Code Online (Sandbox Code Playgroud)

有没有办法忽略空格?

c#

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

AddDays()在while循环中不起作用

是否有任何东西可以阻止DateTime AddDays()在while循环中不运行的方法.我有这么简单的代码;

DateTime last_day = monthCalendar2.SelectionRange.End;
DateTime first_day = new DateTime(year, month, day);

//Insert dates into vector
while (first_day != last_day)
{
  dates.Add(first_day);
  first_day.AddDays(1);
}
Run Code Online (Sandbox Code Playgroud)

我逐步完成程序,first_day永远不会改变,任何人都知道为什么?!

c#

2
推荐指数
2
解决办法
3131
查看次数

"包含"方法似乎没有按照它应该的方式工作

我试图看看当用户输入一些文本时,它会在数组中搜索任何匹配项,并且从数组中删除任何不匹配的内容;

string search = textBox1.Text;
for (int i = 0; i < staffUsers.Count; i++)
{
    if (!(staffUsers[i].staff_name.Contains(search)))
    {
        staffUsers.Remove(staffUsers[i]);
    }
}
Run Code Online (Sandbox Code Playgroud)

我的阵列中有一些垃圾名称'Rob Dob','Joe Bloggs','h h','ghg hgh',如果搜索变量最终成为'R',Joe Bloggs会被删除但是'hh'和'ghg hgh'留在那里,但那里根本没有R参与?任何理由>?!

c# contains

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

switch语句中的if语句?

我很难理解为什么一种方式有效而方式无效.

我有;

switch (key)
        {
            //If Game over Label is visible, enable the m and e buttons
            if(mGameOverLabel->GetVisible())
            {
                case 'm': case 'M':
                    ResetScreen();
                    break;

                case 'e': case 'E':
                //  //Exit the game
                    Stop();
                    break;
            } else {

                case ' ':
                    mSpaceship->Shoot();
                    break;

                default:
                    break;
            }
Run Code Online (Sandbox Code Playgroud)

对于m和e的情况,即使mGameOverLabel在当前时间设置为false,我仍然可以按M和E,这些将根据方法做出反应,但是如果我将其更改为M,那么它只会我需要的时候工作.我在这里错过了什么吗?!

switch (key)
        {
            //If Game over Label is visible, enable the m and e buttons

            case 'm': case 'M':
                if(mGameOverLabel->GetVisible()) ResetScreen();
                break;
            }   
Run Code Online (Sandbox Code Playgroud)

c++ visual-studio-2010 visual-studio

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

尝试在C#中写入文本文件时出现UnauthorizedAccessException

我正在尝试写一个空白文本文件,它包含在我的安装程序中,但是我收到以下错误;

System.UnauthorizedAccessException: Access to the path 'C:\Program Files (x86)\Hex Technologies\wamplocation.txt' is denied.
Run Code Online (Sandbox Code Playgroud)

一旦通过我的安装程序安装,它似乎是文件的权限,但是如果文件安装完成后如何将文件设置为完全可修改?!这可以通过C#完成吗?!

EDITTED;

           wamp_url = openFileDialog1.FileName.ToString();
           String EnviromentPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
           StreamWriter outfile = new StreamWriter(EnviromentPath + @"\Hex Technologies\wamplocation.txt");
           outfile.Write(wamp_url);
           outfile.Close();
Run Code Online (Sandbox Code Playgroud)

c# streamwriter

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