问题列表 - 第29563页

阅读和写入内部存储android时遇到问题

我正在为自己编写一个简单的预算应用程序,而且我无法弄清楚如何写入内部存储.我似乎没有正确地写入文件,我找不到比developer.android.com上的数据存储文章更深入的示例

基本上,我正在尝试将测试浮点数写入MyBalance文件,然后将其读取到平衡状态.在我的实际代码中,我在文件输入/输出操作中使用try/catch语句,但我跳过它们以使代码更具可读性.

float test = 55;
float balance;
byte[] buffer = null;
FileOutputStream fos = openFileOutput( "MyBalance", Context.MODE_PRIVATE );
fos.write(Float.floatToRawIntBits(balance));
fis.read(buffer); //null pointer
ByteBuffer b = ByteBuffer.wrap(buffer);
balance=b.getFloat();
Run Code Online (Sandbox Code Playgroud)

这是它的要点,任何人都能看到我做错了什么?

编辑:感谢您的回复,我继续按照您的建议转换为/从String,但我仍然认为文件没有被创建.我有一个if语句,如果它存在于onResume()中并且它没有被运行,则从中读取它.Lemme发布了我的一些代码.

这是我写文件的方式,(setbal是一个EditText,而balanceview是一个TextView):

 balance = Float.valueOf(setbal.getText().toString());
 balanceview.setText(setbal.getText());
 balstring = String.valueOf(balance);
 for (int i = 0; i < balstring.length(); ++i)
     try {
     fos.write((byte)balstring.charAt(i));
     } catch (IOException e) {
         e.printStackTrace();
     }
Run Code Online (Sandbox Code Playgroud)

我检查文件是否存在于onResume()中,如下所示:

File file = new File("data/data/com.v1nsai.mibudget/balance.txt");
Run Code Online (Sandbox Code Playgroud)

是存储该上下文的内部文件的位置吗?

file-io android

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

Google App Engine:upload_data失败,因为"目标计算机主动拒绝它"在devserver上

我正在尝试使用devserver将数据从CSV上传到我的应用:

appcfg.py upload_data --config_file="DataLoader.py" --filename="data.csv" --kind=Foo --url=http://localhost:8083/remote_api "path/to/app"
Run Code Online (Sandbox Code Playgroud)

结果:

Application: appname; version: 1.
Uploading data records.
[INFO    ] Logging to bulkloader-log-20100626.181045
[INFO    ] Throttling transfers:
[INFO    ] Bandwidth: 250000 bytes/second
[INFO    ] HTTP connections: 8/second
[INFO    ] Entities inserted/fetched/modified: 20/second
[INFO    ] Batch Size: 10
[INFO    ] Opening database: bulkloader-progress-20100626.181045.sql3
Please enter login credentials for localhost
Email: email@domain.com
Password for email@domain.com:
[INFO    ] Connecting to localhost:8083/remote_api
[INFO    ] Starting import; maximum 10 entities per post
Google\google_appengine\google\appengine\api\datastore_types.py:673: DeprecationWarning: object.__init__() takes no …
Run Code Online (Sandbox Code Playgroud)

python google-app-engine urlopen

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

开源商业网站

我正在建立一个"软件即服务"网站,每月向用户收取少量费用.我正在考虑将Github存储库从Private更改为Public.基本上是开源的.这是自杀吗?我希望社区能够从代码中受益.我不太可能接受任何推送请求,因此我不会在这方面获得任何收益.它是基于社区的,所以我认为大部分价值都会被自己托管的人丢失.这是一个非常小众的观众,所以我怀疑别人会开始竞争主机.我真的希望代码是公开的,但不要以牺牲我的想法为代价.其他人对此感觉怎么样?什么是常见做法?

结论,我暂时关闭它.不过,我可能会在发布后的某个时候寻找开源.

language-agnostic open-source

10
推荐指数
3
解决办法
246
查看次数

用于IP到位置API的PHP Regex

我如何使用Regex获取有关IP到Location API的信息

这是API

http://ipinfodb.com/ip_query.php?ip=74.125.45.100

我需要获得国家名称,地区/州和城市.

我试过这个:

$ip = $_SERVER["REMOTE_ADDR"];
$contents = @file_get_contents('http://ipinfodb.com/ip_query.php?ip=' . $ip . '');
$pattern = "/<CountryName>(.*)<CountryName>/";
preg_match($pattern, $contents, $regex);
$regex = !empty($regex[1]) ? $regex[1] : "FAIL";
echo $regex;
Run Code Online (Sandbox Code Playgroud)

当我回复$ regex时,我总是得到失败怎么能解决这个问题

php regex xml api geoip

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

按钮Clickevent上的uiBinder

我正在尝试使用uiBinder.我按照谷歌提供的教程,但我不知道为什么clickevent不起作用?我想计算点击次数并在跨度中显示它,它不起作用,我也放了window.alert但似乎根本没有调用事件处理程序!谁能帮我?这是几个小时我正在努力但却找不到问题!

非常感谢

PS下面是我的代码


<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
   xmlns:g="urn:import:com.google.gwt.user.client.ui">
   <ui:style>
   </ui:style>
   <g:HTMLPanel>
    <table>
        <tr>
            <td><img ui:field='imgPrd'/></td>
            <td>
               <span ui:field='lblNum'></span>
                <g:Button ui:field='btnAdd'></g:Button>
            </td>
        </tr>
    </table>
   </g:HTMLPanel>
Run Code Online (Sandbox Code Playgroud)


public class uiProductList extends Composite {

@UiField Button btnAdd;
@UiField ImageElement imgPrd;
@UiField SpanElement lblNum;

int count;
private static uiProductListUiBinder uiBinder =
GWT.create(uiProductListUiBinder.class);

interface uiProductListUiBinder extends UiBinder<Widget,
uiProductList> {
}

public uiProductList() {
   initWidget(uiBinder.createAndBindUi(this));
}


@UiHandler("btnAdd")
void handleClick(ClickEvent e) {
  Window.alert("test");
  count++;       
  lblNum.setInnerText(Integer.toString(count));
 }

}
Run Code Online (Sandbox Code Playgroud)

gwt uibutton uibinder

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

什么是最好的PHP输入清理功能?

我正在尝试提出一个函数,我可以通过我的所有字符串来消毒.因此,从中输出的字符串对于数据库插入是安全的.但是那里有很多过滤功能我不知道应该使用/需要哪些功能.

请帮我填空:

function filterThis($string) {
    $string = mysql_real_escape_string($string);
    $string = htmlentities($string);
    etc...
    return $string;
}
Run Code Online (Sandbox Code Playgroud)

php sanitization filter

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

在latex中存储文本字符串,然后向其中添加其他文本(连接)

我首先定义一个命令来存储字符串"Hello":

\newcommand{\textstring}{Hello}
Run Code Online (Sandbox Code Playgroud)

我想追加字符串"world"但不幸的是这段代码会导致错误:

\renewcommand{\textstring}{\textstring world}
Run Code Online (Sandbox Code Playgroud)

string latex

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

如何防止Wix在卸载时删除注册表项?

 <RegistryKey Id="MyServerRegInstallDir" Root="HKLM" Key="Software\MyApp\Server" Action="create">
     <RegistryValue Name="InstallDir" Type="string" Value="[INSTALLDIR]" />
     <RegistryValue Name="DataDirectory" Type="string" Value="[MYAPPDATADIR]" />
  </RegistryKey>
Run Code Online (Sandbox Code Playgroud)

卸载时删除子项InstallDir和DataDirectory.我该如何预防呢?

理想情况下,Action ="create"必须这样做.

windows wix wix3.5

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

Django管理员有条件内联?

我试图找出一种方法,只有当Person.is_member为True时才显示以下RelativeInline.

目前的admin.py:

class RelativeInline(admin.TabularInline):
    model = Relative
    fk_name = 'member'

class PersonAdmin(admin.ModelAdmin):
    inlines = [RelativeInline,]
    ordering = ('first_name',)
    list_filter = ('is_member',)
    search_fields = ('first_name', 'last_name',)
    date_hierarchy = 'member_date'
    list_display = ('first_name', 'last_name', 'is_member', 'member_date', 'photo')

admin.site.register(Person, PersonAdmin)
Run Code Online (Sandbox Code Playgroud)

我能找到的唯一提示是我可以覆盖get_formset,但我找不到一个好例子,所以我的微弱尝试不起作用.

这是我失败的尝试:

class RelativeInline(admin.TabularInline):
    model = Relative
    fk_name = 'member'

class PersonAdmin(admin.ModelAdmin):
    ordering = ('first_name',)
    list_filter = ('is_member',)
    search_fields = ('first_name', 'last_name',)
    date_hierarchy = 'member_date'
    list_display = ('first_name', 'last_name', 'is_member', 'member_date', 'photo')

    def get_formset(self, request, obj=None, **kwargs):
        if obj.is_member:
            inlines = [RelativeInline,]
        return …
Run Code Online (Sandbox Code Playgroud)

django conditional inline django-admin

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

在 C# 中创建自定义 ODBC/OLE 驱动程序

有谁知道如何最好在 C# 中创建 ODBC 或 OLE 驱动程序?

我想要做的是创建一个可以在 Excel 和 Access 中使用的自定义数据源。或者想出另一种方法来做到这一点?

预先感谢您的回复!

c# oledb excel odbc driver

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