对不起我的英语!我对BigDecimal有问题。我已经创建了一个SQLiteDatabase。现在我想使用搜索视图进行搜索。
private void showResults(String query) {
Cursor cursor = mDbHelper.searchCustomer((query != null ? query.toString() : "@@@@.@@"));
if (cursor == null) {
//
} else {
// Specify the columns we want to display in the result
String[] from = new String[] {
ItemDbAdapter.KEY_1,
ItemDbAdapter.KEY_2,
ItemDbAdapter.KEY_3,
ItemDbAdapter.KEY_4,
ItemDbAdapter.KEY_5,
ItemDbAdapter.KEY_6,
ItemDbAdapter.KEY_7,
ItemDbAdapter.KEY_8};
// Specify the Corresponding layout elements where we want the
// columns to go
int[] to = new int[] {
R.id.result_1,
R.id.result_2,
R.id.result_3,
R.id.result_4,
R.id.result_5,
R.id.result_6,
R.id.result_7,
R.id.result_8};
SimpleCursorAdapter customers = new SimpleCursorAdapter(this,
R.layout.customresult, cursor, from, to);
mListView.setAdapter(customers);
mListView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
np.setValue(100); //Numberpicker
Cursor cursor = (Cursor) mListView.getItemAtPosition(position);
String 1 = cursor.getString(cursor.getColumnIndexOrThrow("1"));
String 2 = cursor.getString(cursor.getColumnIndexOrThrow("2"));
String 3 = cursor.getString(cursor.getColumnIndexOrThrow("3"));
String 4 = cursor.getString(cursor.getColumnIndexOrThrow("4"));
String 5 = cursor.getString(cursor.getColumnIndexOrThrow("5"));
String 6 = cursor.getString(cursor.getColumnIndexOrThrow("6"));
String 7 = cursor.getString(cursor.getColumnIndexOrThrow("7"));
String 8 = cursor.getString(cursor.getColumnIndexOrThrow("8"));
RelativeLayout customerLayout = (RelativeLayout) findViewById(R.id.custominfoLayout);
if (customerLayout == null) {
// Inflate the Customer Information View
RelativeLayout leftLayout = (RelativeLayout) findViewById(R.id.rightLayout);
View customerInfo = getLayoutInflater().inflate(
R.layout.custominfo, leftLayout, false);
leftLayout.addView(customerInfo);
}
Tv1 = (TextView) findViewById(R.id.info_i);
Tv2 = (TextView) findViewById(R.id.info_a);
Tv3 = (TextView) findViewById(R.id.info_k);
Tv4 = (TextView) findViewById(R.id.info_B);
Tv5 = (TextView) findViewById(R.id.info_k);
Tv6 = (TextView) findViewById(R.id.info_k2);
Tv7 = (TextView) findViewById(R.id.info_P);
Tv8 = (TextView) findViewById(R.id.info_F);
Tv1.setText(1);
Tv2.setText(2);
Tv3.setText(3);
Tv4.setText(4);
Tv5.setText(5);
Tv6.setText(6);
Tv7.setText(7);
Tv8.setText(8);
searchView.setQuery("", true);
在此之前,它运行良好。我所寻求的东西被展示出来了。
如果我想存储值在BigDecimal中,我收到以下错误消息:
10-05 17:58:51.759:E/AndroidRuntime(28053):致命异常:main10-05 17:58:51.759:E/AndroidRuntime(28053):进程:com.XXX.XXX,PID:2805310-05 17:58:51.759:E/AndroidRuntime(28053):java.lang.NumberFormatException:无效的长:"0,3"10-05 17:58:51.759:E/AndroidRuntime(28053):在java.lang.Long.invalidLong(Long.java:124)10-05 17:58:51.759:E/AndroidRuntime(28053):在java.lang.Long.parse(Long.java:361)10-05 17:58:51.759:E/AndroidRuntime(28053):在java.lang.Long.parseLong(Long.java:352)10-05 17:58:51.759:E/AndroidRuntime(28053):在java.lang.Long.parseLong(Long.java:318)10-05 17:58:51.759:E/AndroidRuntime(28053):在java.math.BigDecimal.(BigDecimal.java:344)10-05 17:58:51.759:E/AndroidRuntime(28053):在java.math.BigDecimal.(BigDecimal.java:425)10-05 17:58:51.759:E/AndroidRuntime(28053):在com.XXX.XXX.ListActivity$1.OItemClick(ListActivity.java:288)
10-05 17:58:51.759:E/AndroidRuntime(28053):在android.widget.AdapterView.performItemClick(AdapterView.java:299)10-05 17:58:51.759:E/AndroidRuntime(28053):在android.widget.AbsListView.performItemClick(AbsListView.java:1113)10-05 17:58:51.759:E/AndroidRuntime(28053):在android.widget.AbsListView$PerformClick.run(AbsListView.java:2911)10-05 17:58:51.759:E/AndroidRuntime(28053):在android.widget.AbsListView$3.run(AbsListView.java:3645)10-05 17:58:51.759:E/AndroidRuntime(28053):在android.os.Handler.handleCallback(Handler.java:733)10-05 17:58:51.759:E/AndroidRuntime(28053):在android.os.Handler.dispatchMessage(Handler.java:95)10-05 17:58:51.759:E/AndroidRuntime(28053):在android.os.Looper.loop(Looper.java:136)10-05 17:58:51.759:E/AndroidRuntime(28053):在android.app.ActivityThread.main(ActivityThreads.java:5001)10-05 17:58:51.759:E/AndroidRuntime(28053):在java.lang.reflect.Method.invokeNative(Native Method)10-05 17:58:51.759:E/AndroidRuntime(28053):在java.lang.reflect.Method.ioke(Method.java:515)10-05 17:58:51.759:E/AndroidRuntime(28053):在com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteIndit.java:785)10-05 17:58:51.759:E/AndroidRuntime(28053):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)10-05 17:58:51.759:E/AndroidRuntime(28053):在dalvik.system.NativeStart.main(Native Method)
我的流程为:
Sa = String.valueOf(Tv1.getText());
Sb = String.valueOf(Tv2.getText());
Sc = String.valueOf(Tv3.getText());
Sd = String.valueOf(Tv4.getText());
Se = String.valueOf(Tv5.getText());
Sf = String.valueOf(Tv6.getText());
Sg = String.valueOf(Tv7.getText());
Big1 = new BigDecimal(Sa);
Big2 = new BigDecimal(Sb);
Big3 = new BigDecimal(Sc);
Big4 = new BigDecimal(Sd);
Big5 = new BigDecimal(Se);
Big6 = new BigDecimal(Sf);
Big7 = new BigDecimal(Sg);
我不明白为什么会出现这个错误。
我只使用String和BigDecimal,但错误是float。
String 1 = cursor.getString(cursor.getColumnIndexOrThrow("1"));
String 2 = cursor.getString(cursor.getColumnIndexOrThrow("2"));
....
稍后您设置
Tv1.setText(1);
Tv2.setText(2);
该构建本应向您发出警告。
我想知道变量1, 2, 3, 4, 5, ...
的名称是否是有效的变量名称。我建议使用像firstColumnText
或ArrayList
这样的变量名。因此,您所经历的错误可能会受到此影响。
您还声称显示的错误是float
,但它绝对不是!0,3
可能是BigDecimals
的逗号分隔列表或其他内容!
根据您提供的信息,我无法对这个问题提出任何建议,但可以通过使用带有默认安卓风格配置的checkstyle等工具来避免类似的问题。