0

它是在第一个活动 main.java 上创建的。我想在另一个名为 arclist.java 的活动emailid中得到这个。password如何?这是我从表 Temp 中获取数据的代码,但它给出了一个错误:

public class MainScreen extends Activity

{

//protected static final String Temp1 = null;
//protected static final String Temp1 =null;
ImageButton imgScanButton,imgMyOffersButton;
SQLiteDatabase db;
DatabaseHelper dbHelper;
protected String emailid;
protected String[] columns;

@Override
protected void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.mainscreen);
     db=dbHelper.getWritableDatabase();
    //db = dbHelper.getReadableDatabase();
    try{
          //db=openOrCreateDatabase("baab",SQLiteDatabase.CREATE_IF_NECESSARY,null);
          //db.openDatabase();
         // db.execSQL("Create Table Temp1(emailid integer,Password integer)");
          }catch(SQLException e)
          {
              e.getMessage();
          }
    imgScanButton = (ImageButton) findViewById(R.id.imgbtnScan);
    imgMyOffersButton = (ImageButton) findViewById(R.id.imgbtnMyOffers);

    CursorFactory factory;
    try {

    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    imgScanButton.setOnClickListener(new OnClickListener()
    {



         public void onClick(View arg0) 
                {

             Cursor c=db.query("Temp01", columns, null, null, null, null, null);
            // Cursor cursor = db.query("Temp4", columns,
                     // null, null, null, null, null);
                    TextView tv = (TextView) findViewById(R.id.textView1);
                    tv.setText(c.getString(0));
                    c.moveToFirst();
                }
            });

        db.close(); 

        }

Logcat 及其力关闭:

    10-19 13:12:06.992:E/AndroidRuntime(24732):致命异常:主要
 10-19 13:12:06.992: E/AndroidRuntime(24732): java.lang.RuntimeException: 无法启动活动 ComponentInfo{com.example.checkinfo/com.example.checkinfo.MainScreen}: java.lang.NullPointerException
 10-19 13:12:06.992: E/AndroidRuntime(24732): 在 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
 10-19 13:12:06.992: E/AndroidRuntime(24732): 在 android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
 10-19 13:12:06.992: E/AndroidRuntime(24732): 在 android.app.ActivityThread.access$2300(ActivityThread.java:125)
 10-19 13:12:06.992: E/AndroidRuntime(24732): 在 android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
 10-19 13:12:06.992: E/AndroidRuntime(24732): 在 android.os.Handler.dispatchMessage(Handler.java:99)
 10-19 13:12:06.992: E/AndroidRuntime(24732): 在 android.os.Looper.loop(Looper.java:123)
 10-19 13:12:06.992: E/AndroidRuntime(24732): 在 android.app.ActivityThread.main(ActivityThread.java:4627)
 10-19 13:12:06.992: E/AndroidRuntime(24732): 在 java.lang.reflect.Method.invokeNative(Native Method)
 10-19 13:12:06.992: E/AndroidRuntime(24732): 在 java.lang.reflect.Method.invoke(Method.java:521)
 10-19 13:12:06.992: E/AndroidRuntime(24732): 在 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
 10-19 13:12:06.992: E/AndroidRuntime(24732): 在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
 10-19 13:12:06.992: E/AndroidRuntime(24732): at dalvik.system.NativeStart.main(Native Method)
 10-19 13:12:06.992:E/AndroidRuntime(24732):引起:java.lang.NullPointerException
 10-19 13:12:06.992: E/AndroidRuntime(24732): 在 com.example.checkinfo.MainScreen.onCreate(MainScreen.java:38)
 10-19 13:12:06.992: E/AndroidRuntime(24732): 在 android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
 10-19 13:12:06.992: E/AndroidRuntime(24732): 在 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
4

1 回答 1

1

设置db=dbHelper.getWritableDatabase();并且不会有空指针异常。并且之后

Cursor c=db.query(Temp, columns, null, null, null, null, null);

使用c.moveToFirst();

Cursor c=db.query("Temp01", columns, null, null, null, null, null);
 c.moveToFirst();

            // Cursor cursor = db.query("Temp4", columns,
                     // null, null, null, null, null);
                    TextView tv = (TextView) findViewById(R.id.textView1);
                    tv.setText(c.getString(0));
于 2012-10-19T07:56:00.193 回答