0
所以,我做了一個檢查器,如果一個id在數據庫中,id是數字字符串,數據庫中的類型是char(6)。只有在編輯文本中輸入字母字符串時強制關閉
所以這是我的代碼
public class input extends Activity{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.input);
final EditText edittext = (EditText)findViewById(R.id.editText1);
Button button = (Button)findViewById(R.id.button1);
button.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
String nopel = edittext.getText().toString();
if(nopel.length() == 0){
Toast.makeText(getApplicationContext(), "error", Toast.LENGTH_SHORT).show();
}else{
List<NameValuePair> pairs = new ArrayList<NameValuePair>();
pairs.add(new BasicNameValuePair("nopel", nopel));
JSON json_dp = new JSON();
JSONObject jobj_dp = json_dp.getJSON("http://10.0.2.2/KP/pdam/nopel.php", pairs);
try {
if(jobj_dp.getInt("row") == 0){
Toast.makeText(getApplicationContext(), "error", Toast.LENGTH_SHORT).show();
}else{
String snopel = jobj_dp.getString("nopel");
String snama = jobj_dp.getString("nama");
String salamat = jobj_dp.getString("alamat");
String sgolongan = jobj_dp.getString("golongan");
Intent i = new Intent(input.this, list.class);
i.putExtra("nopel", snopel);
i.putExtra("nama", snama);
i.putExtra("alamat", salamat);
i.putExtra("golongan", sgolongan);
startActivity(i);
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
});
}
}
第一次檢查是檢查如果輸入爲空,它會適合現在,第二次檢查是檢查數據庫中的ID,並且它的問題。當我嘗試一些像「0001」或「02013」這樣的數值的id時,它可以運行。但是當我只需要「放棄」時就會迫近。有人知道我爲什麼得到這個?
這是list.class
public class list extends Activity{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list);
Intent i = getIntent();
String nopel = i.getStringExtra("nopel");
String nama = i.getStringExtra("nama");
String alamat = i.getStringExtra("alamat");
String golongan = i.getStringExtra("golongan");
TextView t1 = (TextView)findViewById(R.id.textView1);
TextView t2= (TextView)findViewById(R.id.textView2);
TextView t3 = (TextView)findViewById(R.id.textView3);
TextView t4 = (TextView)findViewById(R.id.textView4);
t1.setText(nopel);
t2.setText(nama);
t3.setText(alamat);
t4.setText(golongan);
}
}
,這是什麼,是那裏的logcat
06-28 16:14:18.244: W/KeyCharacterMap(253): No keyboard for id 0
06-28 16:14:18.254: W/KeyCharacterMap(253): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
06-28 16:14:22.394: D/AndroidRuntime(253): Shutting down VM
06-28 16:14:22.404: W/dalvikvm(253): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
06-28 16:14:22.404: E/AndroidRuntime(253): Uncaught handler: thread main exiting due to uncaught exception
06-28 16:14:22.414: E/AndroidRuntime(253): java.lang.NullPointerException
06-28 16:14:22.414: E/AndroidRuntime(253): at pdam.tirta.raharja.input$1.onClick(input.java:47)
06-28 16:14:22.414: E/AndroidRuntime(253): at android.view.View.performClick(View.java:2364)
06-28 16:14:22.414: E/AndroidRuntime(253): at android.view.View.onTouchEvent(View.java:4179)
06-28 16:14:22.414: E/AndroidRuntime(253): at android.widget.TextView.onTouchEvent(TextView.java:6541)
06-28 16:14:22.414: E/AndroidRuntime(253): at android.view.View.dispatchTouchEvent(View.java:3709)
06-28 16:14:22.414: E/AndroidRuntime(253): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
06-28 16:14:22.414: E/AndroidRuntime(253): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
06-28 16:14:22.414: E/AndroidRuntime(253): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
06-28 16:14:22.414: E/AndroidRuntime(253): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
06-28 16:14:22.414: E/AndroidRuntime(253): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
06-28 16:14:22.414: E/AndroidRuntime(253): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
06-28 16:14:22.414: E/AndroidRuntime(253): at android.app.Activity.dispatchTouchEvent(Activity.java:2061)
06-28 16:14:22.414: E/AndroidRuntime(253): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
06-28 16:14:22.414: E/AndroidRuntime(253): at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
06-28 16:14:22.414: E/AndroidRuntime(253): at android.os.Handler.dispatchMessage(Handler.java:99)
06-28 16:14:22.414: E/AndroidRuntime(253): at android.os.Looper.loop(Looper.java:123)
06-28 16:14:22.414: E/AndroidRuntime(253): at android.app.ActivityThread.main(ActivityThread.java:4363)
06-28 16:14:22.414: E/AndroidRuntime(253): at java.lang.reflect.Method.invokeNative(Native Method)
06-28 16:14:22.414: E/AndroidRuntime(253): at java.lang.reflect.Method.invoke(Method.java:521)
06-28 16:14:22.414: E/AndroidRuntime(253): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
06-28 16:14:22.414: E/AndroidRuntime(253): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
06-28 16:14:22.414: E/AndroidRuntime(253): at dalvik.system.NativeStart.main(Native Method)
06-28 16:14:22.424: I/dalvikvm(253): threadid=7: reacting to signal 3
06-28 16:14:22.424: E/dalvikvm(253): Unable to open stack trace file '/data/anr/traces.txt': Permission denied
請從mlogcat中添加堆棧跟蹤 –
我們是否可以通過此代碼來建議解決方案?你的問題和這段代碼根本沒有關係! –
可能是因爲無效的數字「abushd」你得到的jobj_dp null和jobj_dp.getInt(「行」)會拋出錯誤,然後..可以嘗試與if(null!= jobj_dp)剛剛嘗試... –