项目问题解决积累

java.lang.IllegalArgumentException: the bind value at index 1 is null

本质上还是由于调用的时候userID给了空值

String query = "select regdate,shousuo,shuzhang,maibo from xueya2 where userid = "+userID;
Cursor cursor = db.query("xueya2", new String[]{"regdate,shousuo,shuzhang,maibo"},"userid=?", new String[]{userID}, null, null, null);

 

这个提示是,你的表中有外键,你就不可以添加随意添加外键值,必须参考表中有对应的外键值。

这个错误犯了很多次:数据往服务器转存时也出现了类似的错误,从本地数据库取数据的时候加了userID,因为本地列表显示不需要userID,想当然的复用了

以前的方法,导致往服务器存数据的时候丢了userID。

 

  BloodPre bloodpre = new BloodPre();
               List<BloodPre> list= (List<BloodPre>) GeneralDbHelper.getInstance(MyApplication.getContext()).getBeanList(bloodpre,userid,temp);
               LogUtil.i("list.size",list.size()+list.get(0).toString());
               
               
               for(int i = list.size(); i>0; i--){
                   new NetTool().uploadData(list.get(i-1));
               }
               
                Editor editor = sharedPreferences.edit();
                editor.putInt("unSavedBP", 0);
                editor.commit(); 
                MyApplication.unSavedBP = 0;

 

public List<?> getBeanList(HealthData obj,String userID,int num) {
                openDatabase();
                if(obj instanceof BloodPre){                                     
                     String query = "select regdate,shousuo,shuzhang,maibo from xueya2 order by id desc limit (0,"+num+") where userid = "+userID;
                     Cursor cursor = db.query("xueya2", new String[]{"regdate,shousuo,shuzhang,maibo"},"userid=?", new String[]{userID}, null, null, null);
                     List<BloodPre> list = new ArrayList<BloodPre>();
                     cursor.moveToLast();
                     for(int i=0; i<num; i++) {
                         BloodPre bloodpre = new BloodPre();
                         bloodpre.setTime(cursor.getString(cursor.getColumnIndex("regdate")));
                         bloodpre.setHighp(cursor.getInt(cursor.getColumnIndex("shousuo")));
                         bloodpre.setLowp(cursor.getInt(cursor.getColumnIndex("shuzhang")));
                         bloodpre.setPulse(cursor.getInt(cursor.getColumnIndex("maibo")));                                    
                         list.add(bloodpre);
                         cursor.moveToPrevious();
                     }            
                    return list;
                }else if(obj instanceof BloodOx){
                     String query = "select regdate,xueyang,maibo from xueyang2 where userid = "+userID;
                     Cursor cursor = db.query("xueyang2", new String[]{"regdate,xueyang,maibo"},"userid=?", new String[]{userID}, null, null, null);
                     List<BloodOx> list = new ArrayList<BloodOx>();                 
                     while (cursor.moveToNext()) {                     
                         BloodOx bloodox = new BloodOx();
                         bloodox.setTime(cursor.getString(cursor.getColumnIndex("regdate")));
                         bloodox.setOx(cursor.getInt(cursor.getColumnIndex("xueyang")));
                         bloodox.setPulse(cursor.getInt(cursor.getColumnIndex("maibo")));
                                    
                         list.add(bloodox);                      
                    }
                    return list;
                }
                else {
                    return null;
                }

            }

 

 

另外注意,字符串匹配时,要使用like:

主键值没法设置成自动递增,报1602错误,是因为数据库中已经有数据啦,需要将数据库清空再设置。

表中有自动递增的数字时,最安全的操作是:

Statement statement = con.createStatement();
            String  str = "INSERT INTO xueya2(userid,regdate,shousuo,shuzhang,maibo) VALUES("+bloodpre.toString()+")";
            statement.execute(str);
String  str = "INSERT INTO xueya2 VALUES("+null+","+bloodpre.toString()+")";

 

为了便于MySQL数据库操作,Bean类可以重写tostring方法:

@Override
        public String toString() {
            // TODO Auto-generated method stub
//            return "BloodPre [userid=" + userid + ", time=" + time + ", highp=" + highp + ", lowp=" + lowp + ", pulse=" + pulse + "]";
            return "\'"+userid+"\',\'"+time+"\',\'"+highp+"\',\'"+lowp+"\',\'"+pulse+"\'";
        }

 

服务器端bug:

把方法封装一下就出错,封装的时候有全局变量的问题,直接传值没问题,但传静态变量就出问题,呵呵其实不是这个问题,重启程序时这个变量跳过登录界面所以没有值

NameValuePair pair1 = new BasicNameValuePair("zhongduan_id","11223344");  没问题

NameValuePair pair1 = new BasicNameValuePair("zhongduan_id",MyApplication.zhongduan_id); 出问题

这个错误应该是主线程不能更新UI

ListVIew刷新数据:

使用Listview的时候: 当要动态显示更改后的数据(例如数据库改动), 很多人应该都用过notifyDataSetChanged();这个方法来刷新Listview,显示改后的数据.

这时候就要注意了:
                 ......
                 private ArrayList<HashMap<String, Object>> usersList;
                 ......
                 usersList= query(......);     //根据查询函数获取一个ArrayList并赋值给绑定到Adapter的数据源usersList
                 sAdapter.notifyDataSetChanged();
                 ......

           如果你也是:   上面这种形式去刷新ListView的数据的话, 是不可以更新的. 必须改成如下形式:

                 ......
                //usersList= query(......);   
                 usersList.clear(); 
                 usersList.addAll(query(......));
                 sAdapter.notifyDataSetChanged();

///

         原因是:    sAdapter会通过usersList获取List中的内容。但是实际上可能(也应该)是,在调用super(MyActivity.this, R.layout.item, usersList)时sAdapter保存了usersList指向原List(假设为List a)的引用,在调用query函数之后,usersList指向了一个新的List(List b)。但是在调用notifyDataSetChanged()时,sAdapter会跟据保存的引用(即指向List a的引用)去更新,因此当然还是原来的结果,不会进行更新。
如果大家也出现这种情况可以使用后者去刷新ListView, 应该就没问题了 

listView getView方法不执行:

原布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:android1="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#eee"
    android:orientation="horizontal" >
    
     
    <LinearLayout 
       android:id="@+id/detailfragment2"
       android:layout_width="0dp"
       android:layout_height="wrap_content"
       android:layout_weight="6" 
       android:orientation="vertical"
       >  
        <LinearLayout 
           android:id="@+id/list_title"
           android:layout_width="match_parent"
           android:layout_height="match_parent" 
           android:visibility="gone" 
           android:background="@color/common_top_bar_blue2"  
           android:orientation="horizontal"
           >         
             <TextView     
                android:layout_height="wrap_content"
                android:layout_width="0dp"
                android:textSize="25sp"
                android:layout_marginLeft="10dp"
                android:layout_weight="3"
                android:text="日期 时间"
                />
            <TextView 
              
                android:layout_height="wrap_content"
                 android:layout_width="0dp"
                 android:textSize="25sp"
                android:layout_weight="2"
                android:text="高压/低压"
                />
            <TextView  
                android:layout_height="wrap_content"
                android:layout_width="0dp"
                android:textSize="25sp"
                android:layout_marginRight="10dp"
                android:layout_weight="1"
                 android:text="脉搏"
                />
       
              </LinearLayout> 
       <ListView 
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/data_list"
            android:divider="#FFF"
            android:background="@color/common_top_bar_blue2"
            android:dividerHeight="1px"
            android:visibility="gone" 
           ></ListView>        
    </LinearLayout>
  <LinearLayout
       android:layout_width="0dp"
       android:layout_height="wrap_content"
       android:gravity="right"
       android:layout_weight="1"
       android:orientation="vertical">
         <TextView
            android1:id="@+id/tvxian"
            android1:layout_width="wrap_content"
            android1:layout_height="wrap_content"
            android1:layout_marginTop="5dp"
            android1:layout_gravity = "center"
            android1:text="视图" />   
       
       <RadioGroup
            android1:id="@+id/radioGroup1"
            android1:layout_width="wrap_content"
            android1:layout_marginTop="5dp"
            android1:layout_height="wrap_content" >
    
            <RadioButton
                android1:id="@+id/radio0"
                android1:layout_width="wrap_content"
                android1:layout_height="wrap_content"
                android1:checked="true"
                android1:text="周" />
    
            <RadioButton
                android1:id="@+id/radio1"
                android1:layout_width="wrap_content"
                android1:layout_height="wrap_content"
                android1:text="月" />

            <RadioButton
                android1:id="@+id/radio3"
                android1:layout_width="wrap_content"
                android1:layout_height="wrap_content"
                android1:text="全部" />
            <ImageView   
            android1:layout_marginTop="20dp"
            android:layout_width="match_parent"  
            android:layout_height="1dp"  
            android:background="#ffffff"  
            /> 
             <RadioButton
                android1:id="@+id/radio4"
                android1:layout_marginTop="20dp"
                android1:layout_width="wrap_content"
                android1:layout_height="wrap_content"
                android1:text="列表" />
        </RadioGroup>

   </LinearLayout>
</LinearLayout>
View Code

在平板上,下方和listview是左右布局的

 

改动后的布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:android1="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#eee"
    android:orientation="vertical" >

    <LinearLayout
        android:id="@+id/detailfragment2"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="6"
        android:orientation="vertical" >

        <LinearLayout
            android:id="@+id/list_title"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/common_top_bar_blue2"
            android:orientation="horizontal"
            android:visibility="gone" >

            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:textSize="20sp"
                android:layout_weight="3"
                android:text="日期 时间" />

            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:textSize="20sp"
                android:layout_weight="2"
                android:text="高压/低压" />

            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginRight="10dp"
                android:textSize="20sp"
                android:layout_weight="1"
                android:text="脉搏" />
        </LinearLayout>

        <ListView
            android:id="@+id/data_list"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/common_top_bar_blue2"
            android:divider="#FFF"
            android:dividerHeight="1px"
            android:visibility="gone" >
        </ListView>
    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:gravity="center_vertical"
        android:orientation="horizontal" >

        <TextView
            android1:id="@+id/tvxian"
            android1:layout_marginLeft="20dp"
            android1:layout_width="wrap_content"
            android1:layout_height="wrap_content"
            android1:layout_marginTop="5dp"
            android1:text="视图" />

        <RadioGroup
            android1:id="@+id/radioGroup1"
            android1:layout_width="wrap_content"
            android1:layout_height="wrap_content"
            android:orientation="horizontal"

            android1:layout_marginTop="5dp" >

            <RadioButton
                android1:id="@+id/radio0"
                android1:layout_width="wrap_content"
                android1:layout_height="wrap_content"
                android1:checked="true"
                android1:text="周" />

            <RadioButton
                android1:id="@+id/radio1"
                android1:layout_width="wrap_content"
                android1:layout_height="wrap_content"
                android1:text="月" />

            <RadioButton
                android1:id="@+id/radio3"
                android1:layout_width="wrap_content"
                android1:layout_height="wrap_content"
                android1:text="全部" />

            <ImageView
                android:layout_width="1dp"
                android:layout_height="match_parent"
                android1:layout_marginLeft="20dp"
                android:background="#ffffff" />

            <RadioButton
                android1:id="@+id/radio4"
                android1:layout_width="wrap_content"
                android1:layout_height="wrap_content"
                android1:layout_marginLeft="20dp"
                android1:text="列表" />
        </RadioGroup>
    </LinearLayout>

</LinearLayout>
View Code

 

 根本原因是父布局的高度设置为零啦

 

 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:android1="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout
        android:id="@+id/list_title"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:layout_alignParentTop="true" >

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_weight="3"
            android:text="日期 时间"
            android:textSize="20sp" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="2"
            android:text="高压/低压"
            android:textSize="20sp" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginRight="10dp"
            android:layout_weight="1"
            android:text="脉搏"
            android:textSize="20sp" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/detailfragment2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@id/bottom"
        android:layout_below="@id/list_title" >

        <ListView
            android:id="@+id/data_list"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/common_top_bar_blue2"
            android:divider="#FFF"
            android:dividerHeight="1px"
            android:visibility="gone" >
        </ListView>
    </LinearLayout>

    <LinearLayout
        android:id="@+id/bottom"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:layout_alignParentBottom="true"
        android:gravity="center"
        android:orientation="horizontal" >

        <TextView
            android1:id="@+id/tvxian"
            android1:layout_width="wrap_content"
            android1:layout_height="wrap_content"
            android1:layout_marginLeft="20dp"
            android1:layout_marginTop="5dp"
            android1:text="视图" />

        <RadioGroup
            android1:id="@+id/radioGroup1"
            android1:layout_width="wrap_content"
            android1:layout_height="wrap_content"
            android1:layout_marginTop="5dp"
            android:orientation="horizontal" >

            <RadioButton
                android1:id="@+id/radio0"
                android1:layout_width="wrap_content"
                android1:layout_height="wrap_content"
                android1:checked="true"
                android1:text="周" />

            <RadioButton
                android1:id="@+id/radio1"
                android1:layout_width="wrap_content"
                android1:layout_height="wrap_content"
                android1:text="月" />

            <RadioButton
                android1:id="@+id/radio3"
                android1:layout_width="wrap_content"
                android1:layout_height="wrap_content"
                android1:text="全部" />

            <ImageView
                android:layout_width="1dp"
                android:layout_height="match_parent"
                android1:layout_marginLeft="20dp"
                android:background="#ffffff" />

            <RadioButton
                android1:id="@+id/radio4"
                android1:layout_width="wrap_content"
                android1:layout_height="wrap_content"
                android1:layout_marginLeft="20dp"
                android1:text="列表" />
        </RadioGroup>
    </LinearLayout>

</RelativeLayout>
View Code

 

                                               app.zhongduan_id = login_number.getText().toString().trim();
                                                //只要登录成功,以后就不再进入登录界面啦
                                                SharedPreferences sharedPreferences = MyApplication.getContext().getSharedPreferences("runInfo", MODE_PRIVATE);    
                                                Editor editor = sharedPreferences.edit();
                                                editor.putBoolean("isFirstRun", false);

由于登录之后,登录界面就不再出现,所以下一次重新运行程序时app.zhongduan_id就不会被赋值。所以必须把app.zhongduan_id的内容本地保存

 

.sql文件转入数据库方法:

 >mysql -uroot -psu273035;

mysql>use yourdatabasename;
mysql>set names utf8;
mysql>source /tmp/database.sql;

最后,记得将database.sql删除。

数据库查询时等号和like的问题:

select shenfennum from user2 where shenfennum =412728199005233676;和等号后面有没有空格没有关系

select shenfennum from user2 where shenfennum  = '412728199005233676';

select shenfennum from user2 where shenfennum  = '412728199005233676';

转载于:https://www.cnblogs.com/hixin/p/4489761.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值