小编Moh*_*nde的帖子

提交SharedPreferences时发生StackOverFlowException

public class SettingsActivity extends SherlockPreferenceActivity implements OnSharedPreferenceChangeListener, OnPreferenceChangeListener {
    @SuppressWarnings("deprecation")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.settings);

        getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);

        ListPreference theme = (ListPreference) getPreferenceScreen().findPreference("theme");
        theme.setSummary(theme.getValue().toString());
        theme.setOnPreferenceChangeListener(this);

        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
        getSupportActionBar().setTitle(R.string.menu_preferences);
    }

    @SuppressWarnings("deprecation")
    public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
        String key) {
        if (key.equals("theme")) {
            SharedPreferences.Editor editor = sharedPreferences.edit();
            ListPreference theme = (ListPreference) getPreferenceScreen().findPreference("theme");
            theme.setSummary(theme.getEntry());
            editor.putString("theme", theme.getEntry().toString());
            editor.commit();
        }
    }

    public boolean onPreferenceChange(Preference preference, Object newValue) {
        ListPreference theme = (ListPreference) preference;
        theme.setSummary(theme.getEntry());
        return true;
    }
}
Run Code Online (Sandbox Code Playgroud)

我明白了:

07-03 09:46:22.563: E/AndroidRuntime(421): java.lang.StackOverflowError
07-03 09:46:22.563: …
Run Code Online (Sandbox Code Playgroud)

stack-overflow android commit sharedpreferences

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

编写许多if语句的替代方法?

这是我的方法:

private void ConvertValues()  
{  
    txtResult.Text = angles[cmbUnits1.SelectedIndex];  
    double value1 = Convert.ToDouble(txtValue1.Text);  
    double value2 = Convert.ToDouble(txtValue2.Text);  
    int unit1 = cmbUnits1.SelectedIndex;  
}
Run Code Online (Sandbox Code Playgroud)

我想要的方法是获取所选的ComboBox并测试值.但我想知道是否有替代方案:

if( angles[cmbUnits1.SelectedIndex].Equals("Degrees") && 
    angles[cmbUnits2.SelectedIndex].Equals("Radians")) {  
    ...  
}
Run Code Online (Sandbox Code Playgroud)

顺便说一句,我正在制作一种单位转换器,所以我将有除角度以外的部分.所以我想要一些我可以实现的枚举,接口,抽象类或类.也许是一个名为Unit的班级?所以我可以创建像Unit degrees = new Unit(Units.Angle)Units这样的新对象作为枚举.还是只是Unit sqrMillimeters = new Unit("Area");

c# combobox winforms

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

如何告诉我的应用程序发送电子邮件?

我如何告诉我的应用程序向订阅者发送电子邮件?从推出应用程序开始,我将如何每周发送一次.

c# email wpf

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

如何使用Win32图标

如何使用Win32图标,如打开图标,新文件图标和保存图标.我必须将它们下载为图像吗?或者是dll中的图像?也许System.Windows.Shell

c# winapi

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

"/"字符十六进制值0x2F的XmlException不能包含在名称中

如何解决生成的异常?

        public static string[] getKeywords(string filename)  
        {  
            var xmlFile = new XElement(filename);  
            string[] keywords = xmlFile.Elements("Keyword")
                                       .Attributes("name")
                                       .Select(n => n.Value).ToArray();  
            return keywords;  
        } 
Run Code Online (Sandbox Code Playgroud)

这会生成此异常:

System.Xml.XmlException未处理Message ='/'字符,十六进制值0x2F,不能包含在名称中.来源=的System.Xml

c# xmlexception

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

数据存储数据的替代方案?

我在我的应用程序中使用SQL Server Compact Edition(本地数据库).但是当我使用实体框架时,我一直遇到一个非常烦人的UpdateException.我的数据库只有两个小表,外键关系将它们连接在一起.所以我问是否有数据库的替代品?或者这是唯一的选择吗?
更新:
是EDMX地图.
以下是System.Windows.Markup.XamlParseException was unhandled Message=Cannot create instance of 'MainWindow' defined in assembly 'AssignmentOrganizer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. Exception has been thrown by the target of an invocation. Error in markup file 'AssignmentOrganizer;component/MainWindow.xaml' Line 1 Position 9. Source=PresentationFramework LineNumber=1 LinePosition=9 StackTrace: at System.Windows.Markup.XamlParseException.ThrowException(String message, Exception innerException, Int32 lineNumber, Int32 linePosition, Uri baseUri, XamlObjectIds currentXamlObjectIds, XamlObjectIds contextXamlObjectIds, Type objectType) at System.Windows.Markup.XamlParseException.ThrowException(ParserContext parserContext, Int32 lineNumber, Int32 linePosition, String message, Exception innerException) at System.Windows.Markup.BamlRecordReader.ThrowExceptionWithLine(String message, Exception innerException) at …

c# database

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

可以运行Visual Studio 2010 RC和Visual C#2008吗?

我已经安装了Visual Studio 2010 RC.我想安装Visual C#2008,因为XNA Game Studio需要安装它.我可以并排运行它们吗?

visual-studio visual-studio-2010-rc

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

直接调用与C中的间接调用

我是C的新手,我正在阅读指针如何"指向"另一个变量的地址.所以我尝试了间接调用和直接调用,并收到了相同的结果(正如任何C/C++开发人员所预测的那样).这就是我做的:

int cost;
int *cost_ptr;

int main()
{
    cost_ptr = &cost;                          //assign pointer to cost
    cost = 100;                                //intialize cost with a value
    printf("\nDirect Access: %d", cost);
    cost = 0;                                  //reset the value
    *cost_ptr = 100;
    printf("\nIndirect Access: %d", *cost_ptr);
    //some code here

    return 0;                                  //1
}
Run Code Online (Sandbox Code Playgroud)

所以我想知道使用指针的间接调用是否比直接调用有任何优势,反之亦然?一些优点/缺点可能包括速度,执行操作所消耗的内存量(很可能相同,但我只想把它放在那里),安全性(如悬挂指针),良好的编程习惯等
.1有趣的是,我是使用GNU C编译器(gcc),它仍然编译没有return语句,一切都按预期.也许是因为如果你忘了,C++编译器会自动插入return语句.

c comparison pointers indirection invocation

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

未知的URL内容:未知的URL内容:\ com.mohit.provider.FormulaProvider\formula

每当我尝试使用我的内容提供程序插入URI时,我都会收到此错误.这是方法:

private void sample() {
    ContentValues values;

    values = new ContentValues();
    values.put(Formulas.TITLE, "Formula1");
    values.put(Formulas.FORMULA, "someformula");
    getContentResolver().insert(getIntent().getData(), values);

    values = new ContentValues();
    values.put(Formulas.TITLE, "Formula2");
    values.put(Formulas.FORMULA, "someformula");
    getContentResolver().insert(getIntent().getData(), values);

    values = new ContentValues();
    values.put(Formulas.TITLE, "Formula3");
    values.put(Formulas.FORMULA, "someformula");
    getContentResolver().insert(getIntent().getData(), values);
}
Run Code Online (Sandbox Code Playgroud)

以前我在这里设置Intent数据:

Intent intent = getIntent();
if (intent.getData() == null)
    intent.setData(Formulas.CONTENT_URI);
Run Code Online (Sandbox Code Playgroud)

这是我的内容URI和权限:

public static final String AUTHORITY = "com.mohit.provider.FormulaProvider";
public static final Uri CONTENT_URI = Uri.parse("content:\\" + AUTHORITY + "\formulas");
Run Code Online (Sandbox Code Playgroud)

这是提供者标签:

<provider android:name="com.mohit.provider.FormulaProvider" 
        android:authorities="com.mohit.provider.FormulaProvider" />
Run Code Online (Sandbox Code Playgroud)

最后是Logcat日志:

08-22 14:42:07.362: ERROR/AndroidRuntime(338): FATAL EXCEPTION: main
08-22 …
Run Code Online (Sandbox Code Playgroud)

java android uri android-contentprovider

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

Var arg list in main

我想使用我的程序:

./program -I /usr/include/ /usr/bin/ /usr/local/include/ ...
Run Code Online (Sandbox Code Playgroud)

交换机可以像var args列表一样继续运行.我怎么能在C99那样做?最好得到一个类似char **args_listchar *args_list[]包含所有喜欢的东西/usr/include/usr/bin/.

c c99 variadic-functions

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