2012-08-06 10 views
2

널 포인터 예외로 애플리케이션을 실행할 때 강제 종료해야합니다. 내 생각에 올바른 양식으로 데이터베이스를 관리 할 수 ​​없습니다.Android에서 강제 종료

package sarah.android; 

import android.R.integer; 
import android.app.Activity; 
import android.content.Intent; 
import android.database.Cursor; 
import android.database.sqlite.SQLiteDatabase; 
import android.os.Bundle; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.Button; 
import android.widget.EditText; 
import android.widget.Toast; 

public class SelesMeter2Activity extends Activity implements OnClickListener { 
    EditText ed1; 
    EditText ed2; 
    Button b1; 
    Button b2; 
    Intent in; 
    signup obj=new signup(); 

    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     ed1=(EditText) findViewById(R.id.ed1); 
     ed2=(EditText) findViewById(R.id.ed2); 
     b1= (Button) findViewById(R.id.bt1); 
     b2= (Button) findViewById(R.id.bt2); 
     b1.setOnClickListener(this); 
     b2.setOnClickListener(this); 
    } 

    @Override 
    public void onClick(View arg0) { 
     // TODO Auto-generated method stub 
     //log in 
     if (arg0.getId() == R.id.bt1) 
     { 
      String name=ed1.getText().toString(); 
      int pass = Integer.parseInt(ed2.getText().toString()); 
      if (obj.c.getString(0) == name&&obj.c.getInt(1) == pass) 
      { 
       in = new Intent(this,secondview.class); 
       startActivity(in); 
      } 
      else 
      { 
       Toast.makeText(this, "please sing up first", 1000).show(); 
      } 
     } 
     else 
      if (arg0.getId()==R.id.bt2) 
      { 
       in=new Intent(this,signup.class); 
       startActivity(in); 
      } 
    } 
} 

새로운 사용자를 등록하는 데 사용 내 데이터베이스에 자신의 정보를 넣어 두 번째 활동

package sarah.android; 

import android.app.Activity; 
import android.content.Intent; 
import android.database.Cursor; 
import android.database.sqlite.SQLiteDatabase; 
import android.os.Bundle; 
import android.widget.Toast; 

public class signup extends Activity { 
    SQLiteDatabase sql; 
    Cursor c; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     // TODO Auto-generated method stub 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.singupx); 
     Intent in = getIntent(); 
     Bundle b = in.getExtras(); 
     String n = b.getString("x"); 
     int p = Integer.valueOf(b.getString("y")); 

     sql = openOrCreateDatabase("db",0, null); 
     sql.execSQL("CREATE TABLE if not exists employee " + 
        " (name text NOT NULL UNIQUE" + 
        ",password integer NOT NULL UNIQUE)"); 
     sql.execSQL("insert into employee(name) values(" + 
        "'"+n+"') "); 
     Toast.makeText(this,"Data inserted", 1000).show(); 
    } 
} 
+0

logcat 오류 –

+2

게시하기 Logcat 오류 보고서가 도움이 될 것입니다. logcat을 복사하여 붙여 넣으십시오! –

+0

나는 홀 코드를 불행하게 바꿀 것이다. 그리고 나는 너의 도움이 다시 필요하다 :) 너의 시간을 위해 대단한 감사 – Syamic

답변

3

그것은 ... 아주 간단합니다. 첫 번째 활동에서는 "x" 또는 "y"을 입력하지 않았습니다. 그리고 두 번째 활동에서, 당신은 그것들을 얻으려고했습니다.

... 
Bundle b=in.getExtras(); // perhaps this is null 
String n=b.getString("x"); // or this one 
int p=Integer.valueOf(b.getString("y")); // or this one 
+0

네가 실제로 내 코드를 여러 번 변경했기 때문에 실제로 이것이 끝났다. – Syamic