错误:无法打开片段 DBHelper.SelectAllDataView(java.lang.String,java.lang.String)'上 null对象引用 com.example.venkateshbm.myapplication.OpeningStockFragment.onCreateView(OpeningStockFragment.java:38) 在 android.support.v4.app.Fragment.performCreateView(Fragment.java:2354) 在 android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1419) 在 android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1740) 在 android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1809)
片段代码:
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.EditText;
public class OpeningStockFragment extends Fragment {
DBHelper mydb;
Button btnlsubmit;
EditText fret_expdate,fretbatchno;
AutoCompleteTextView fracproductname;
public static OpeningStockFragment newInstance(){
return new OpeningStockFragment();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_opening_stock,container,false);
fracproductname = (AutoCompleteTextView) v.findViewById(R.id.ac_productname);
fret_expdate = (EditText) v.findViewById(R.id.fr_et_expdate);
fretbatchno = (EditText)v.findViewById(R.id.fr_ac_batchno);
Context c = getActivity().getApplicationContext();
final String[] myproductname = mydb.SelectAllDataView(DBHelper.ITEM_TABLE, DBHelper.ITEM_NAME);
ArrayAdapter<String> aaproductname = new ArrayAdapter<String>(c, android.R.layout.simple_dropdown_item_1line, myproductname);
fracproductname.setAdapter(aaproductname);
fracproductname.setThreshold(1);
fret_expdate.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean b) {
if ( b) {
Datedialog datedialog= new Datedialog(view);
FragmentManager fm = getFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
datedialog.show(getActivity().getFragmentManager(),"DatePicker");
}
}
});
return v;
}
}
DBHelper Class:
package com.example.venkateshbm.myapplication;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.DatabaseUtils;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.net.wifi.aware.PublishConfig;
import android.util.Log;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
/**
* Created by venkatesh on 10/10/17.
*/
public class DBHelper extends SQLiteOpenHelper {
/** Item Master Table FIELDS DEFINE */
public SQLiteDatabase sqliteDBInstance =null;
public static final String DATABASE_NAME = "pharmacy.db";
public static final String ITEM_TABLE = "item_mst";
public static final String ITEM_CODE = "item_code";
public static final String ITEM_NAME = "item_name";
public static final String ITEM_PACK = "item_pack";
public static final String ITEM_PACK_CONV = "item_pack_conv";
public static final String BAR_CODE = "bar_code";
public static final String MANF_CODE = "manf_code";
public static final String CATG_CODE = "catg_code";
public static final String CONT_CODE = "cont_code";
public static final String ITEM_DISC = "item_disc";
public static final String GST_PERCE = "gst_perce";
public static final String ITEM_RACK = "item_rack";
public static final String ITEM_SHELF = "item_shelf";
public static final String ITEM_DATE = "item_date";
public static final String TIME_STAMP = "item_stamp";
public static final String ITEM_LBNO = "item_lbno";
public static final String ITEM_LMRP = "item_lmrp";
public static final String ITEM_MINLVL = "item_minlvl";
public static final String ITEM_MAXLVL = "item_maxlvl";
public static final String SCHE_DRUG = "sche_drug";
public static final String HSN_CODE = "hsn_code";
public static final String ITEM_FLAG = "item_flag";
/** Manufacture Master Tabble Fields DEFINE */
public static final String MANF_TABLE_NAME = "manufacture_mst";
public static final String C_CODE = "c_code";
public static final String C_NAME = "c_name";
public static final String C_ADD1 = "c_add1";
public static final String C_ADD2 = "c_add2";
public static final String C_ADD3 = "c_add3";
public static final String C_CITY = "c_city";
public static final String C_PIN = "c_pin";
public static final String C_PH1 = "c_ph1";
public static final String C_PH2 = "c_ph2";
public static final String C_CONTACT = "c_contact";
public static final String C_DL1 = "c_dl1";
public static final String C_DL2 = "c_dl2";
public static final String C_GSTNO = "c_gstno";
public static final String C_SHORT = "c_short";
public static final String C_LOCK = "c_lock";
public static final String C_USER = "c_user";
public static final String C_C_DATE = "c_c_date";
public static final String C_M_DATE = "c_m_date";
// TAX MASTER TABLE FIELDS DEFINE
public static final String TAX_TABLE = "tax_master";
public static final String TAX_CODE = "tax_code";
public static final String TAX_NAME = "tax_name";
public static final String TAX_CGST = "tax_cgst";
public static final String TAX_SGST = "tax_sgst";
public static final String TAX_IGST = "tax_igst";
public static final String TAX_ON_SCH = "tax_on_sch";
public static final String TAX_ON_MRP = "tax_on_mrp";
// PRODUCT CATOGERY TABLE FIELDS DEFINE
public static final String CATG_MASTER = "catg_master";
public static final String CATG_CODE1 = "cat_code";
public static final String CATG_NAME = "catg_name";
// CONTENT MASTER TABLE FIELDS DEFINE
public static final String CONT_MASTER = "cont_master";
public static final String CONT_CODE1 = "cont_code";
public static final String CONT_NAME = "cont_name";
public static final String CONT_SHORT = "cont_short";
// PACKING MASTER TABLE FIELDS DEFINE
public static final String PACK_MASTER = "pack_master";
public static final String PACK_CODE = "pack_code";
public static final String PACK_NAME = "pack_name";
public static final String PACK_CONV = "pack_conv";
// SCHEDULED TABLE FIELD DEFINE
public static final String SCHEDULE_MASTER = "schedule_master";
public static final String S_CODE = "s_code";
public static final String S_NAME = "s_name";
public static final String S_MSG = "s_msg";
// USER TABLE FIELD DEFINE
public static final String TABLE_USER = "user_mst";
public static final String USER_ID = "user_id";
public static final String USER_NAME = "user_name";
public static final String USER_PWD = "user_pwd";
public static final String USER_TYPE = "user_type";
public static final String USER_CREATE_DATE = "user_create_date";
public static final String USER_ROLES = "user_roles";
public static final String USER_EDIT_DATE = "user_edit_date";
// OPENING STOCK TABLE FIELD DEFINE
public static final String OPENING_STOCK_MST = "opening_stock_mst";
public static final String OPEN_STK_CODE = "open_stk_code";
public static final String OPEN_BATCH_ID = "open_batch_id";
public static final String OPEN_USER_ID = "open_user_id";
public static final String OPEN_STK_DATE = "open_stk_date";
public static final String OPEN_EDIT_DATE = "open_edit_date";
public static final String OPEN_STK_QTY = "open_stk_qty";
public static final String OPEN_STK_MRP = "open_stk_mrp";
public static final String OPEN_STK_PTR = "open_stk_ptr";
public static final String OPEN_SUP_CODE = "open_sup_code";
// STOCK MASTER TABLE FIELD DEFINE
public static final String TABLE_STOCK = "stock";
public static final String STOCK_ID = "stock_id";
public static final String STK_ITEM_CODE = "stk_item_code";
public static final String STK_BATCH_ID = "stk_batch_id";
public static final String OPENING_STOCK = "opening_stock";
public static final String STOCK_MRP = "stock_mrp";
public static final String STOCK_PTR = "stock_ptr";
public static final String STOCK_EXPIRY = "stock_expiry";
public static final String STOCK_MONTH = "stock_month";
public static final String SALES_QTY = "sales_qty";
public static final String SALES_FQTY = "sales_fqty";
public static final String ADJT_QTY = "adju_qty";
public static final String BALC_QTY = "balc_qty";
public static final String STOCK_GST = "stock_gst";
public static final String EDIT_DATE = "edit_date";
public static final String STOCK_USER_ID = "stock_user_id";
public static final String STK_SUP_CODE = "stk_sup_code";
// BATCH MASTER TABLE FIELD DEFINE
public static final String TABLE_BATCH = "batch_mst";
public static final String BATCH_ID = "batch_id";
public static final String BAT_ITEM_CODE = "bat_item_code";
public static final String BATCH_NO = "batch_no";
public static final String MANF_DATE = "manf_date";
public static final String EXPI_DATE = "expi_date";
public static final String TRANS_TYPE = "trans_type";
public static final String RECV_QTY = "recv_qty";
public static final String RECV_FQTY = "recv_fqty";
public static final String RECV_DATE = "recv_date";
public static final String SUP_CODE = "sup_code";
public static final String BATCH_MRP = "batch_mrp";
public static final String BATCH_PTR = "batch_ptr";
public static final String BATCH_DISC = "batch_disc";
public static final String BATCH_GST = "batch_gst";
public static final String BATCH_USER_ID = "batch_user_id";
private static DBHelper instance;
public static synchronized DBHelper getHelper(Context context) {
if(instance == null) {
instance = new DBHelper(context);
}
return instance;
}
public DBHelper(Context context) {
super(context, DATABASE_NAME, null, 1);
SQLiteDatabase sqLiteDatabase = this.getWritableDatabase();
}
public void onOpen(SQLiteDatabase db) {
super.onOpen(db);
if(!db.isReadOnly()) {
db.execSQL("PRAGMA foreign_keys = 'ON' ;");
}
}
@Override
public void onCreate(SQLiteDatabase sqLiteDatabase) {
sqLiteDatabase.execSQL( " create table " + TABLE_BATCH
+ " ( "
+ BATCH_ID + " INTEGER PRIMARY KEY AUTOINCREMENT ,"
+ BATCH_NO + " VARCHAR2(20) ,"
+ BAT_ITEM_CODE + " INTEGER ,"
+ MANF_DATE + " DATE ,"
+ EXPI_DATE + " DATE ,"
+ TRANS_TYPE + " VARCHAR2(5) ,"
+ RECV_DATE + " DATE ,"
+ RECV_QTY + " INTEGER ,"
+ RECV_FQTY + " INTEGER ,"
+ SUP_CODE + " VARCHAR(10) ,"
+ BATCH_MRP + " NUMERIC(7,2) ,"
+ BATCH_PTR + " NUMERIC(7,2) ,"
+ BATCH_DISC + " NUMERIC(5,2) ,"
+ BATCH_GST + " INTEGER ,"
+ BATCH_USER_ID + " INTEGER )" );
sqLiteDatabase.execSQL(" create table " + TABLE_STOCK
+ " ( "
+ STOCK_ID + " INTEGER PRIMARY KEY AUTOINCREMENT ,"
+ STK_ITEM_CODE + " INTEGER ,"
+ STK_BATCH_ID + " INTEGER ,"
+ OPENING_STOCK + " INTEGER ,"
+ STOCK_MRP + " NUMERIC(7,2) ,"
+ STOCK_PTR + " NUMERIC(7,2) ,"
+ STOCK_EXPIRY + " DATE ,"
+ STOCK_MONTH + " VARCHAR2(15) ,"
+ SALES_QTY + " INTEGER ,"
+ SALES_FQTY + " INTEGER ,"
+ ADJT_QTY + " INTEGER ,"
+ BALC_QTY + " INTEGER ,"
+ STOCK_GST + " INTEGER ,"
+ EDIT_DATE + " DATE ,"
+ STOCK_USER_ID + " INTEGER ,"
+ STK_SUP_CODE + " VARCHAR2(10) )" );
sqLiteDatabase.execSQL(" create table " + OPENING_STOCK_MST
+ " ( "
+ OPEN_STK_CODE + " INTEGER PRIMARY KEY AUTOINCREMENT ,"
+ OPEN_BATCH_ID + " VARCHAR2(15) ,"
+ OPEN_USER_ID + " INTEGER ,"
+ OPEN_STK_DATE + " DATE ,"
+ OPEN_EDIT_DATE + " DATE ,"
+ OPEN_STK_QTY + " INTEGER ,"
+ OPEN_STK_MRP + " NUMERIC(7,2) ,"
+ OPEN_STK_PTR + " NUMERIC(7,2) ,"
+ OPEN_SUP_CODE + " VARCHAR2(10) )"
);
sqLiteDatabase.execSQL(" create table " + TABLE_USER
+ "( "
+ USER_ID + " INTEGER PRIMARY KEY AUTOINCREMENT ,"
+ USER_NAME + " VARCHAR2(30) ,"
+ USER_PWD + " VARCHAR2(50) ,"
+ USER_TYPE + " VARCHAR2(30) ,"
+ USER_CREATE_DATE + " DATE ,"
+ USER_ROLES + " INTEGER ,"
+ USER_EDIT_DATE + " DATE )"
);
sqLiteDatabase.execSQL(" create table " + MANF_TABLE_NAME
+ " ( "
+ C_CODE + " VARCHAR(10) PRIMARY KEY ,"
+ C_NAME + " VARCHAR(100) ,"
+ C_ADD1 + " VARCHAR(60) ,"
+ C_ADD2 + " VARCHAR(60) ,"
+ C_ADD3 + " VARCHAR(60) ,"
+ C_CITY + " VARCHAR(30) ,"
+ C_PIN + " INTEGER ,"
+ C_PH1 + " NUMBER (10) ,"
+ C_PH2 + " NUMBER (10) ,"
+ C_CONTACT + " VARCHAR(25) ,"
+ C_DL1 + " VARCHAR(40) ,"
+ C_DL2 + " VARCHAR(40) ,"
+ C_GSTNO + " VARCHAR(15) ,"
+ C_SHORT + " VARCHAR(6) ,"
+ C_LOCK + " CHAR(1) ,"
+ C_USER + " VARCHAR(15) ,"
+ C_C_DATE + " DATE ,"
+ C_M_DATE + " DATE );" );
sqLiteDatabase.execSQL( " create table " + ITEM_TABLE
+ " ( "
+ ITEM_CODE + " varchar(10) primary key , "
+ ITEM_NAME + " varchar(50) ,"
+ ITEM_PACK + " varchar(10) ,"
+ ITEM_PACK_CONV + " INTEGER ,"
+ BAR_CODE + " varchar(20) ,"
+ MANF_CODE + " VARCHAR(10) ,"
+ CATG_CODE + " VARCHAR(6) ,"
+ CONT_CODE + " VARCHAR(10) ,"
+ ITEM_DISC + " NUMERIC(5,2) ,"
+ GST_PERCE + " INTEGER ,"
+ ITEM_RACK + " varchar(5) ,"
+ ITEM_SHELF + " varchar(5) ,"
+ TIME_STAMP + " text , "
+ ITEM_LBNO + " varchar(15) ,"
+ ITEM_LMRP + " NUMERIC(12,2) ,"
+ ITEM_MINLVL + " INTEGER ,"
+ ITEM_MAXLVL + " INTEGER ,"
+ SCHE_DRUG + " varchar(6) ,"
+ HSN_CODE + " varchar(10) ,"
+ ITEM_FLAG + " char(1) );" );
// TAX MASTER TABLE CREATION
sqLiteDatabase.execSQL( "create table " + TAX_TABLE + "("
+ TAX_CODE + " INTEGER PRIMARY KEY AUTOINCREMENT ,"
+ TAX_NAME + " VARCHAR(10) ,"
+ TAX_CGST + " NUMERIC(5,2) ,"
+ TAX_SGST + " NUMERIC(5,2) ,"
+ TAX_IGST + " NUMERIC(5,2) ,"
+ TAX_ON_SCH + " CHAR(1) ,"
+ TAX_ON_MRP + " CHAR(1) )" );
Log.d( " TAX TABLE CREATION" , "Successfully Tax Table Created ");
// PRODUCT CATOGERY TABLE CREATION
sqLiteDatabase.execSQL( "create table " + CATG_MASTER + " ( "
+ CATG_CODE1 + " VARCHAR(6) PRIMARY KEY ,"
+ CATG_NAME + " VARCHAR(30) )" );
// CONTENT MASTER TABLE CREATION
sqLiteDatabase.execSQL( "create table " + CONT_MASTER + " ( "
+ CONT_CODE1 + " VARCHAR(10) PRIMARY KEY ,"
+ CONT_NAME + " VARCHAR2(128) ,"
+ CONT_SHORT + " VARCHAR2(4) )"
);
// PACKING MASTER TABLE CREATEION
sqLiteDatabase.execSQL(" create table " + PACK_MASTER + "("
+ PACK_CODE + " INTEGER PRIMARY KEY AUTOINCREMENT ,"
+ PACK_NAME + " VARCHAR2(10) ,"
+ PACK_CONV + " INTEGER )" );
sqLiteDatabase.execSQL(" create table " + SCHEDULE_MASTER + " ("
+ S_CODE + " varchar(5) primary key ,"
+ S_NAME + " varchar(30) ,"
+ S_MSG + " varchar(60))"
);
}
// sqLiteDatabase.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
// onCreate(sqLiteDatabase);
@Override
public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {
sqLiteDatabase.execSQL("Drop table if exists " + ITEM_TABLE);
sqLiteDatabase.execSQL("drop table if exists " + MANF_TABLE_NAME);
sqLiteDatabase.execSQL("drop table if exists " + TAX_TABLE);
sqLiteDatabase.execSQL("drop table if exists " + CATG_MASTER);
sqLiteDatabase.execSQL("drop table if exists " + CONT_MASTER);
sqLiteDatabase.execSQL("drop table if exists " + PACK_MASTER);
sqLiteDatabase.execSQL("drop table if exists " + SCHEDULE_MASTER);
onCreate(sqLiteDatabase);
Log.d("Database Created", " Created table successfull" + ITEM_TABLE + " " + MANF_TABLE_NAME);
}
public boolean insert_data(Integer itemcode, String itemname, String itempack, Integer itempackconv, String barcode, String manfcode,
String catgcode, String contcode, Double itemdisc, int gstperce, String itemrack, String itemshelf,
String timestamp, String itemlbno, Double itemlmrp, Integer itemminlvl, Integer itemmaxlvl, String schedrug,
String hsncode, String itemflag) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(ITEM_CODE,itemcode);
contentValues.put(ITEM_NAME,itemname);
contentValues.put(ITEM_PACK,itempack);
contentValues.put(ITEM_PACK_CONV,itempackconv);
contentValues.put(BAR_CODE,barcode);
contentValues.put(MANF_CODE,manfcode);
contentValues.put(CATG_CODE,catgcode);
contentValues.put(CONT_CODE,contcode);
contentValues.put(ITEM_DISC,itemdisc);
contentValues.put(GST_PERCE,gstperce);
contentValues.put(ITEM_RACK,itemrack);
contentValues.put(ITEM_SHELF,itemshelf);
contentValues.put(TIME_STAMP,timestamp);
contentValues.put(ITEM_LBNO,itemlbno);
contentValues.put(ITEM_LMRP,itemlmrp);
contentValues.put(ITEM_MINLVL,itemminlvl);
contentValues.put(ITEM_MAXLVL,itemmaxlvl);
contentValues.put(SCHE_DRUG, schedrug);
contentValues.put(HSN_CODE,hsncode);
contentValues.put(ITEM_FLAG,itemflag);
db.insert(ITEM_TABLE,null,contentValues);
return true;
}
public Cursor getData(String itemcode) {
SQLiteDatabase db = this.getReadableDatabase();
Cursor resu = db.rawQuery("select * from ITem_MST where item_code = " + itemcode + "",null);
return resu;
}
public String[] SelectAllData(String TABLE_NAME , String ITEMNAME, String ITEMCODE){
SQLiteDatabase db = this.getReadableDatabase();
// Cursor cursor =db.query(TABLE_NAME,null, null,null,null,null,null);
Cursor cursor = db.query(TABLE_NAME, new String[]{ITEMNAME,ITEMCODE},null,null,null,null,null);
Log.i("DataBase Count","Total Records" + cursor.getCount());
if ( cursor.getCount() >0 )
{
String[] arrData = new String[cursor.getCount()];
int i = 0 ;
while (cursor.moveToNext())
{
arrData[i]=cursor.getString(cursor.getColumnIndex(ITEMNAME)) + " CODE: " +cursor.getString(cursor.getColumnIndex(ITEMCODE)) ;
i++;
}
return arrData;
}
else
{
return new String[] {};
}
}
public String[] SelectAllDataView(String TABLE_NAME , String ITEMNAME){
SQLiteDatabase db=this.getReadableDatabase();
// Cursor cursor =db.query(TABLE_NAME,null, null,null,null,null,null);
Cursor cursor = db.query(TABLE_NAME, new String[]{ITEMNAME},null,null,null,null,null);
Log.i("DataBase Count","Total Records" + cursor.getCount());
if ( cursor.getCount() >0 )
{
String[] arrData = new String[cursor.getCount()];
int i = 0 ;
while (cursor.moveToNext())
{
arrData[i]=cursor.getString(cursor.getColumnIndex(ITEMNAME)) ;
i++;
}
return arrData;
}
else
{
return new String[] {};
}
}
public int numberOfRows (){
SQLiteDatabase db=this.getReadableDatabase();
int numbrows = (int) DatabaseUtils.queryNumEntries(db,ITEM_TABLE);
return numbrows;
}
public int getLastRow( ){
int id = 0;
SQLiteDatabase db=this.getReadableDatabase();
Cursor cursor = db.query(ITEM_TABLE, new String[] {DBHelper.ITEM_CODE},null,null,null,null,null);
if (cursor.moveToLast()) {
id = cursor.getInt(0);
}
cursor.close();
db.close();
return id;
}
public int getLastId(){
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor =db.rawQuery("Select max(item_code) from " + ITEM_TABLE + "", null );
cursor.moveToLast();
cursor.getInt(0);
return cursor.getInt(0);
}
public boolean update_item_mst(String itemcode, String itemname, String itempack, Integer itempackconv, String barcode, String manfcode,
String catgcode, String contcode, Double itemdisc, int gstperce, String itemrack, String itemshelf,
String timestamp, String itemlbno, Double itemlmrp, Integer itemminlvl, Integer itemmaxlvl, String schedrug,
String hsncode){
SQLiteDatabase db =this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(ITEM_NAME,itemname);
contentValues.put(ITEM_PACK,itempack);
contentValues.put(MANF_CODE,manfcode);
contentValues.put(CATG_CODE,catgcode);
contentValues.put(CONT_CODE,contcode);
contentValues.put(ITEM_DISC,itemdisc);
contentValues.put(GST_PERCE,gstperce);
contentValues.put(ITEM_RACK,itemrack);
contentValues.put(ITEM_SHELF,itemshelf);
contentValues.put(TIME_STAMP,timestamp);
contentValues.put(ITEM_LBNO,itemlbno);
contentValues.put(ITEM_LMRP,itemlmrp);
contentValues.put(ITEM_MINLVL,itemminlvl);
contentValues.put(ITEM_MAXLVL,itemmaxlvl);
db.update(ITEM_TABLE,contentValues," ITEM_CODE " + " = " + itemcode , null );
return true;
}
public void DeleteRecords(String itemcode) {
SQLiteDatabase db =this.getWritableDatabase();
db.delete(ITEM_TABLE,"ITEM_CODE like" + itemcode,null);
}
public boolean CheckDuplicateRecords(String FIELD_NAME) {
SQLiteDatabase db = this.getReadableDatabase();
String str = "select item_name from " + ITEM_TABLE + " where item_name like '" + FIELD_NAME + "'";
Cursor cursor = db.rawQuery(str, null);
if (cursor.getCount() > 0) {
return true;
} else {
return false;
}
}
}
Main Activity :
private void loadFragment(OpeningStockFragment fragment) {
// create a FragmentManager
FragmentManager fm = getSupportFragmentManager();
// create a FragmentTransaction to begin the transaction and replace the Fragment
FragmentTransaction fragmentTransaction = fm.beginTransaction();
// replace the FrameLayout with new Fragment
fragmentTransaction.add(R.id.frameOpeningStock,fragment);
fragmentTransaction.commit(); // save the changes
}
btn_openstock.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// FragmentManager fm = getSupportFragmentManager();
// FragmentTransaction fragmentTransaction = fm.beginTransaction();
// fragmentTransaction.add(R.id.frameOpeningStock,new OpeningStockFragment());
// fragmentTransaction.commit(); // save the changes
loadFragment(new OpeningStockFragment());
}
});
答案 0 :(得分:0)
mydb
为null,因此您无法调用其方法。根据您的需要,您需要确保执行以下一项或多项操作: