【问题标题】:Package has already posted 50 toasts. Not showing morePackage 已经发布了 50 个祝酒词。没有显示更多
【发布时间】:2017-04-20 23:26:15
【问题描述】:

您好,我正在开发一个应用程序,其中有一次我需要从用户那里获取输入并将其存储在数据库中,然后获取该数据并将其放在不同的 TextView 上。问题是我确实将数据存储在数据库中,当我尝试获取它时我的应用程序显示一个弹出窗口,即:应用程序没有响应并且 logcat 显示: Package 已经发布了 50 个祝酒词。没有显示更多。 在此 pullAccStt 之前我已经使用了 6 次数据库操作,这可能是个问题。

数据库适配器

public long updateAccSettTable(String loactionName, String hospitalname, String PatientId, String FirstName, String MiddleName, String LastName, String DOB,
                               String Gender, String Weight, String Height, String MobNo, String emailId, String Ethinicity, String patientConcentStatus, String DevicePatientId,
                               String CoSensorId, String DeviceId, String VideoId){
    SQLiteDatabase db= helper.getWritableDatabase();
    ContentValues contentValuesAccSett= new ContentValues();
    contentValuesAccSett.put(DatabaseHelper.PatientId,PatientId);
    contentValuesAccSett.put(DatabaseHelper.LocationName,loactionName);
    contentValuesAccSett.put(DatabaseHelper.HospitalName,hospitalname);

    contentValuesAccSett.put(DatabaseHelper.FirstName,FirstName);
    contentValuesAccSett.put(DatabaseHelper.MiddleName,MiddleName);
    contentValuesAccSett.put(DatabaseHelper.LastName,LastName);
    contentValuesAccSett.put(DatabaseHelper.DateOfBirth,DOB);
    contentValuesAccSett.put(DatabaseHelper.Gender,Gender);
    contentValuesAccSett.put(DatabaseHelper.Weight,Weight);
    contentValuesAccSett.put(DatabaseHelper.Height,Height);
    contentValuesAccSett.put(DatabaseHelper.MobileNo,MobNo);
    contentValuesAccSett.put(DatabaseHelper.EmailId,emailId);
    contentValuesAccSett.put(DatabaseHelper.Ethnicity,Ethinicity);
    contentValuesAccSett.put(DatabaseHelper.P_ConsentStatus,patientConcentStatus);
    contentValuesAccSett.put(DatabaseHelper.DevicePId,DevicePatientId);
    contentValuesAccSett.put(DatabaseHelper.DeviceId,DeviceId);
    contentValuesAccSett.put(DatabaseHelper.CoSensorId,CoSensorId);
    contentValuesAccSett.put(DatabaseHelper.VideoId,VideoId);

    long id1= db.insert(DatabaseHelper.Accoun_setting_Table,null,contentValuesAccSett);
    if (id1<0){
        Message.message(helper.context,"Unsuccessfull");

    }else {
        Message.message(helper.context,"Account setting Updated");

    }

    db.close();
    return id1;


}
public String pullAccSett(){
    String patientId = null;
    Message.message(helper.context,"patient id is: ");
    SQLiteDatabase db=helper.getWritableDatabase();
    String query="Select * From "+DatabaseHelper.Accoun_setting_Table+" ;";
    Cursor AccCursor=db.rawQuery(query,null);
    Message.message(helper.context,"query "+query);
    while(AccCursor.moveToFirst()) {

        int index1 = AccCursor.getColumnIndex(DatabaseHelper.PatientId);
         patientId=AccCursor.getString(index1);


    }

    AccCursor.close();
    db.close();
    return patientId ;
}

Activity 类调用它

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;


/**
 * A simple {@link Fragment} subclass.
 */
public class AccountSettingFragment extends Fragment {
    FloatingActionButton fabEdit;
    DatabaseAdaptor databaseAdaptor=null;
    TextView PatientId;
    private Context context;


    public AccountSettingFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view=inflater.inflate(R.layout.fragment_account_setting, container, false);

        fabEdit=(FloatingActionButton)view.findViewById(R.id.btnFabEdit);
        PatientId=(TextView)view.findViewById(R.id.patientId);
        context=getActivity();
        databaseAdaptor=new DatabaseAdaptor(context);
       databaseAdaptor.pullAccSett();
        fabEdit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), AccountsSettingEdit.class);
                getActivity().startActivity(intent);
            }
        });


        return view;
    }


}

消息类

import android.content.Context;
import android.widget.Toast;

/**
 * Created by frnds on 3/2/2016.
 */
public class Message {
    public static void message(Context context,String message){
        Toast.makeText(context,message,Toast.LENGTH_LONG).show();
    }
}

当我调用这个 pullAccSett();我的应用程序挂起并没有响应。 并且 log cat 显示消息: Package 已经发布了 50 个祝酒词。没有显示更多。 这背后的原因是什么。

【问题讨论】:

  • 去掉toast代码,检查一次。
  • 我已经这样做了,但还是一样
  • 您在 while 循环中使用 toast,将其删除,如果需要信息,请使用 Log.i("","");在 logcat 中打印信息
  • 我删除了 toast,但在调用该特定选项卡时它仍然挂起。日志猫现在说:输入调度超时(等待发送非键事件,因为触摸的窗口还没有完成处理某些输入事件,这些事件在 500.0 毫秒前传递给它。等待队列长度:17。等待队列头年龄:5931.6女士)
  • 你想在 pullAccSett() 方法中做什么?

标签: android android-sqlite


【解决方案1】:

我认为您的 while 循环将运行无限时间。因为每次它都是真的,你没有 break 语句。 所以像这样改变你的代码。

try {
    if (AccCursor.moveToFirst()) {
        while (AccCursor.moveToNext()) {
        //code for fetch data from cursor
        }
    }

    AccCursor.close();
}catch (Exception e) {
    Log.e("Getdata", e.getMessage(), e);
}  

【讨论】:

    【解决方案2】:

    上面的代码有一些增强。如果光标位于 -1 位置,AccCursor.moveToNext 会将其移动到位置 0,因此您可以更好地执行以下操作:

    try {
        while(AccCursor.moveToNext()) {
            //Execute code
        }
        AccCursor.close();
    }catch(final Exception lException) {
        Log.e("Getdata", "Exception looping Cursor: " + lException.getMessage());
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多