我正在做的是在我的活动开始时初始化布局。每当单击该布局上的按钮时,都会在同一活动中初始化另一个布局。每当我单击正在做一些有关插入数据库记录的工作时。即使忽略数据库部分,我也会在 logcat 中获取 java 空指针异常。请看一下并指导我
package com.example.emp_management;
import android.app.Activity;
import android.content.ContentValues;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.provider.SyncStateContract.Columns;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.example.emp_management.DatabaseHelper;
public class Administrator_Work extends Activity{
@Override
protected void onCreate(Bundle adminkakaam) {
// TODO Auto-generated method stub
super.onCreate(adminkakaam);
setContentView(R.layout.administrator);
Toast.makeText(this, "Logged in as Administrator!",Toast.LENGTH_LONG).show();
final EditText new_user = (EditText) findViewById(R.id.editText1);
final EditText new_pass = (EditText) findViewById(R.id.textView2);
Button add_emp = (Button)findViewById(R.id.addemployee);
final Button create_acc = (Button) findViewById(R.id.creat_acc);
add_emp.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
setContentView(R.layout.add_employee);
create_acc.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
//DatabaseHelper accessing_db = new DatabaseHelper(Administrator_Work.this);
//accessing_db.insert_new_user(new_user.getText().toString(), new_pass.getText().toString());
//Toast.makeText(getApplicationContext(), "New User Has Been Created!!", Toast.LENGTH_SHORT).show();
}
});
}
});
}
}