android RadioButton 和EditText

android RadioButton 和EditText一起使用,EditText输入总会出问题,有人遇到类似情况吗?

2个回答

什么问题?你描述下清楚

焦点问题吧,你可能需要用 setfoucus 去切换 点选按钮和 输入框的焦点

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
Error inflating class android.widget.EditText

<EditText android:id="@+id/edit_caclmac_value" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:ems="10" android:inputType="text" android:text="" android:textColor="@android:color/black" android:textSize="20sp" > </EditText> 这是自定义dialog里的EditText 在手机上弹出对话框没问题,但是在平板上就报Error inflating class android.widget.EditText错误

Android: EditText.getText().toString()不能运行

我使用下面的代码用一个 EditText 创建一个 AlertDialog: AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle("Title"); builder.setView(LayoutInflater.from(context).inflate(R.layout.dialog_view, null)); builder.setNegativeButton("Cancel", null); builder.setPositiveButton("OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { mInput = ((EditText) LayoutInflater.from(context).inflate(R.layout.dialog_view, null).findViewById(R.id.etxtDialog)).getText().toString(); } }); builder.show(); 当我运行这段代码时,出现`mInput.length() == 0`, 所以字符串是空的。 代码行`mInput = ((EditText) LayoutInflater.from(context).inflate(R.layout.dialog_view, null).findViewById(R.id.etxtDialog)).getText().toString();`虽然执行了,但是EditText 不包含任何字符。为什么这段代码没有运行出结果呢?

从asynctask动态生成的EditText,Checkbox,Radiobutton中保存数据库中的数据?

<div class="post-text" itemprop="text"> <p>i have a Android App of Digital Survey, my app get data from the server(mysql-php) and display in Activity . My doubt is how save de data to the Database because i generated dynamically the questions and answer options . </p> <p>Here is the Code of the Activity Class</p> <pre><code> public void onPostExecute(String result) { pDialog.dismiss();//ocultamos progess dialog. //paring data String id_preg; String preg; String tipopreg; String tipo_opc; String descri_op; String id_pregunta = null; String pregunta = null; String tipo_pregunta = null; String tipo_opcion = null; String descrip_opc; try{ JSONArray jArray = new JSONArray(result); JSONObject json_data=null; String[] tipopregu=new String[jArray.length()]; String[] tipopcion=new String[jArray.length()]; String[] id_preguntas=new String[jArray.length()]; String[] descripcion_opc=new String[jArray.length()]; String aux1=""; String aux2=""; String aux3=""; String aux4=""; String auxtipoopc; int cont=1; int cont2=0; //validate the values not repeteated because for(int i=0;i&lt;jArray.length();i++){ json_data = jArray.getJSONObject(i); //Get DAta id_preg =json_data.getString("ID_PREGUNTA");//IS QUESTION ID preg = json_data.getString("DESCRIPCION");//DESCRIPTION tipopreg=json_data.getString("TIPO_PREGUNTA"); //TYPE OF QUESTION tipo_opc=json_data.getString("ID_TIPOOPC");//VALUE OF ID TYPE OPTION auxtipoopc=tipo_opc; descrip_opc=json_data.getString("DESCRIP_OPC");//DESCRIPTION OF VALUES USED IN MULTIPLES VALUES if((!aux1.equals(id_preg))||(!aux2.equals(preg))||(!aux3.equals(tipopreg))||(!aux4.equals(tipo_opc)) ){ id_pregunta=id_preg; pregunta=preg; tipo_pregunta=tipopreg; tipo_opcion=tipo_opc; nameValuePairs.add(new list&lt;String, String&gt;(id_pregunta, pregunta)); id_preguntas[cont2]=id_pregunta; tipopregu[cont2]=tipo_pregunta; tipopcion[cont2]=tipo_opcion; Log.e("id_pregunta", id_pregunta); Log.e("pregunta",pregunta); Log.e("id_preg-pregunta", id_pregunta+" "+pregunta); Log.e("tipo_pregunta",tipo_pregunta); Log.e("tipo_opc",tipo_opcion); cont2=cont2+1; Log.e("contador2",String.valueOf(cont2)); } descripcion_opc[i]=descrip_opc; nameValuePairs2.add(new list&lt;String, String&gt;(auxtipoopc, descrip_opc)); Log.e("Id_tipo_opc--Opcion", auxtipoopc+" "+descrip_opc); aux1=id_preg; aux1=preg; aux3=tipopreg; aux4=tipo_opc; cont=cont+1; Log.e("contador1",String.valueOf(cont)); } List&lt;NameValuePair&gt; datos = new ArrayList&lt;NameValuePair&gt;(); datos=nameValuePairs; List&lt;EditText&gt; allEds = new ArrayList&lt;EditText&gt;(); llinear=(LinearLayout) findViewById(R.id.preg); final int N=cont2+1; final TextView[] tx = new TextView[N]; int j=0; for (NameValuePair i:nameValuePairs) { String id_preguntastr=i.getName(); String preguntastr=i.getValue(); String tipopregun=tipopregu[j]; String id_opcion=tipopcion[j]; String id_preguntaaux=id_preguntas[j]; final TextView rowTextView = new TextView(getBaseContext()); rowTextView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); rowTextView.setText(id_preguntastr+" "+preguntastr); llinear.addView(rowTextView); tx[j] = rowTextView; if(tipopregun.equals("SI-NO"))// IF QUESTION IS YES/NO { RadioGroup radiogroup1 = new RadioGroup(getBaseContext()); final RadioButton rowradiobuttsi = new RadioButton(getBaseContext()); rowradiobuttsi.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); rowradiobuttsi.setText("SI"); radiogroup1.addView(rowradiobuttsi); final RadioButton rowradiobuttno = new RadioButton(getBaseContext()); rowradiobuttno.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); rowradiobuttno.setText("NO"); radiogroup1.addView(rowradiobuttno); llinear.addView(radiogroup1) ; } if(tipopregun.equals("Verdadero-Falso"))//IF QUESTION IS TYPE TRUE/FALSE { RadioGroup radiogroup2 = new RadioGroup(getBaseContext()); final RadioButton rowradiobuttv = new RadioButton(getBaseContext()); rowradiobuttv.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); rowradiobuttv.setText("VERDADERO"); radiogroup2.addView(rowradiobuttv); final RadioButton rowradiobuttf = new RadioButton(getBaseContext()); rowradiobuttf.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); rowradiobuttf.setText("FALSO"); radiogroup2.addView(rowradiobuttf); llinear.addView(radiogroup2) ; } if(tipopregun.equals("Valor")) //IF QUESTION IS A VALUE(EDITTEXT) { //count is number of edittext fields final EditText ed = new EditText(getBaseContext()); ed.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); allEds.add(ed); llinear.addView(ed); } if(tipopregun.equals("opcionmultiple"))//MULTIPLE OPTIONS (CHECKBOXs) { for (NameValuePair k:nameValuePairs2) { String tipoopcion=k.getName(); String opcion=k.getValue(); if(tipoopcion.equalsIgnoreCase("3")){ final CheckBox checkboxoptionsm = new CheckBox(getBaseContext()); checkboxoptionsm.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); checkboxoptionsm.setText(opcion); allChbx.add(checkboxoptionsm); llinear.addView(checkboxoptionsm); } } } j=j+1; } }catch(JSONException e4){ Toast.makeText(getBaseContext(), "Preguntas no Encontrada"+e4, Toast.LENGTH_LONG).show(); Log.e("fallo", "fallo", e4); // Log.e("pairs",nameValuePairs); } catch(Exception e9){ Log.e("error", String.valueOf(e9)); } } </code></pre> <p>Sorry for my bad English</p> </div>

android应用开发详解里的一个例子

我导入的书上例子可以运行,照着书打进去的代码就不能运行,同样从例子里面复制过来的代码也不能运行,MainActivity可以显示,但是点击register后跳转的ResultActivity就不能显示,模拟器弹出has stopped字样,求解答 以下是代码 package com.amaker.test; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.CheckBox; import android.widget.EditText; import android.widget.RadioButton; import android.widget.Spinner; import android.widget.ToggleButton; public class MainActivity extends Activity { private Button register,cancel; private ToggleButton marriged; private RadioButton male,female; private EditText username,password; private Spinner position; private CheckBox reading,swimming; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); username = (EditText)findViewById(R.id.username); password = (EditText)findViewById(R.id.password); male = (RadioButton)findViewById(R.id.male); female = (RadioButton)findViewById(R.id.female); reading = (CheckBox)findViewById(R.id.reading); swimming = (CheckBox)findViewById(R.id.swimming); marriged = (ToggleButton)findViewById(R.id.marriged); position = (Spinner)findViewById(R.id.position); String[] str = {"CEO","CFO","PM"}; ArrayAdapter aa = new ArrayAdapter(this, android.R.layout.simple_spinner_dropdown_item,str); position.setAdapter(aa); register = (Button)findViewById(R.id.register); cancel = (Button)findViewById(R.id.cancel); register.setOnClickListener(new OnClickListener() { public void onClick(View v) { Bundle b = new Bundle(); b.putString("username", "用户名称:"+username.getText().toString()); b.putString("password", "用户密码:"+password.getText().toString()); if(male.isChecked()){ b.putString("gender", "性别:男"); }else{ b.putString("gender", "性别:女"); } String temp = "爱好:"; if(reading.isChecked()){ temp+="阅读"; } if(swimming.isChecked()){ temp+=" "; temp+="游泳"; } b.putString("hobby", temp); if(marriged.isChecked()){ b.putString("marriged", "婚否:已婚"); }else{ b.putString("marriged", "婚否:未婚"); } b.putString("position","职位:"+ position.getSelectedItem().toString()); Intent intent = new Intent(MainActivity.this,ResultActivity.class); intent.putExtra("data", b); startActivity(intent); } }); } } import android.widget.ArrayAdapter; import android.widget.ListView; public class ResultActivity extends Activity{ private ListView listView; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.result); listView = (ListView) findViewById(R.id.ListView01); Intent intent = this.getIntent(); Bundle b = intent.getBundleExtra("data"); System.out.println(b.getString("username")); List list = new ArrayList(); list.add(b.getString("username")); list.add(b.getString("password")); list.add(b.getString("position")); list.add(b.getString("gender")); list.add(b.getString("hobby")); list.add(b.getString("marriged")); ArrayAdapter adapter = new ArrayAdapter(this,android.R.layout.simple_list_item_1,list); listView.setAdapter(adapter); } } 布局的xml main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TableLayout android:id="@+id/TableLayout01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:stretchColumns="1" > <TableRow android:id="@+id/TableRow01" android:layout_width="wrap_content" android:layout_height="wrap_content"> <TextView android:text="用户名称" android:id="@+id/TextView01" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView> <EditText android:text="" android:id="@+id/username" android:layout_width="wrap_content" android:layout_height="wrap_content" ></EditText> </TableRow> <TableRow android:id="@+id/TableRow02" android:layout_width="wrap_content" android:layout_height="wrap_content"> <TextView android:text="用户密码" android:id="@+id/TextView02" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView> <EditText android:text="" android:id="@+id/password" android:layout_width="wrap_content" android:layout_height="wrap_content" android:password="true" ></EditText> </TableRow> <TableRow android:id="@+id/TableRow03" android:layout_width="wrap_content" android:layout_height="wrap_content"> <TextView android:text="性别" android:id="@+id/TextView03" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView> <RadioGroup android:id="@+id/gender_g" android:layout_width="wrap_content" android:layout_height="wrap_content"> <RadioButton android:text="男" android:id="@+id/male" android:layout_width="wrap_content" android:layout_height="wrap_content"></RadioButton> <RadioButton android:text="女" android:id="@+id/female" android:layout_width="wrap_content" android:layout_height="wrap_content"></RadioButton> </RadioGroup> </TableRow> <TableRow android:id="@+id/TableRow04" android:layout_width="wrap_content" android:layout_height="wrap_content"> <TextView android:text="婚否" android:id="@+id/TextView04" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView> <ToggleButton android:text="@+id/ToggleButton01" android:id="@+id/marriged" android:layout_width="wrap_content" android:layout_height="wrap_content"></ToggleButton> </TableRow> <TableRow android:id="@+id/TableRow05" android:layout_width="wrap_content" android:layout_height="wrap_content" > <TextView android:text="爱好" android:id="@+id/hobby" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView> <CheckBox android:text="阅读" android:id="@+id/reading" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_column="1" ></CheckBox> <CheckBox android:text="游泳" android:id="@+id/swimming" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_column="1" ></CheckBox> </TableRow> <TableRow android:id="@+id/TableRow06" android:layout_width="wrap_content" android:layout_height="wrap_content"> <TextView android:text="职务" android:id="@+id/TextView05" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView> <Spinner android:id="@+id/position" android:layout_width="wrap_content" android:layout_height="wrap_content"></Spinner> </TableRow> <TableRow android:id="@+id/TableRow07" android:layout_width="wrap_content" android:layout_height="wrap_content"> <Button android:text="取消" android:id="@+id/cancel" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button> <Button android:text="注册" android:id="@+id/register" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button> </TableRow> </TableLayout> </LinearLayout> result.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <ListView android:id="@+id/ListView01" android:layout_width="wrap_content" android:layout_height="wrap_content"></ListView> </LinearLayout>

listview 里面嵌套raduiogroup 选择混乱

listview 里面有姓名 radiogroup里面两个radiobuttou 实现签到功能 但是滑动时 radiobutton选择混乱 请问怎么解决 网上都是习题那种 表示看不懂

Activity跳转失败,点击跳转按钮后黑屏卡住

Activity跳转失败,点击跳转按钮后黑屏卡住,估计是otheractivity启动失败,android 小白 activity_other.xml ``` <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:layout_width="fill_parent" android:layout_height="35dp" android:text="@string/activity_other_headtext" android:gravity="center" android:background="#E0E0E0" /> <TextView android:layout_width="fill_parent" android:layout_height="35dp" android:text="@string/activity_other_meg" android:gravity="center"/> <TableLayout android:layout_width="fill_parent" android:layout_height="wrap_content"> <TableRow android:layout_width="wrap_content" android:layout_height="wrap_content"> <TextView android:layout_width="160dp" android:layout_height="wrap_content" android:gravity="right" android:padding="5dp" android:text="@string/activity_other_username" /> <TextView android:id="@+id/activity_other_username" android:layout_width="160dp" android:layout_height="wrap_content" android:padding="5dp"/> </TableRow> <TableRow android:layout_width="wrap_content" android:layout_height="wrap_content"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="right" android:text="@string/activity_other_sex" android:padding="5dp"/> <TextView android:layout_width="160dp" android:layout_height="wrap_content" android:padding="5dp" android:id="@+id/activity_other_sex" android:text="@string/activity_other_null"/> </TableRow> <TableRow android:layout_width="wrap_content" android:layout_height="wrap_content"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="right" android:text="@string/activity_other_phonenum" android:padding="5dp"/> <TextView android:layout_width="160dp" android:layout_height="wrap_content" android:padding="5dp" android:id="@+id/activity_other_phonenum" android:text="@string/activity_other_null"/> </TableRow> <TableRow android:layout_width="wrap_content" android:layout_height="wrap_content"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="right" android:text="@string/activity_other_QQ" android:padding="5dp"/> <TextView android:layout_width="160dp" android:layout_height="wrap_content" android:padding="5dp" android:id="@+id/activity_other_QQ" android:text="@string/activity_other_null"/> </TableRow> </TableLayout> <Button android:id="@+id/activity_other_Button" android:layout_width="200dp" android:layout_height="wrap_content" android:layout_gravity="center" android:text="@string/activity_other_know_button"> </Button> </LinearLayout> ``` Mainactivity.java ``` package com.example.p105092015050; import java.security.PublicKey; import android.R.string; import android.app.Activity; import android.content.Intent; import android.inputmethodservice.Keyboard.Key; import android.os.Bundle; import android.os.storage.OnObbStateChangeListener; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.CheckBox; import android.widget.EditText; import android.widget.RadioButton; import android.widget.RadioGroup; import android.widget.RadioGroup.OnCheckedChangeListener; import android.widget.TextView; import android.widget.Toast; public class MainActivity extends Activity { private EditText username_EText=null; private EditText phonenum_EText=null; private EditText QQ_EText=null; private EditText passwd_EText=null; private EditText passwd_EText_reptition=null; private CheckBox checkBox=null; private Button regist_button=null; private RadioGroup sex_radiogroup=null; public char sex; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); init(); } public void init() { username_EText=(EditText)findViewById(R.id.activity_main_EText_username); sex_radiogroup=(RadioGroup)findViewById(R.id.radiogroup); phonenum_EText=(EditText)findViewById(R.id.activity_main_EText_phonenum); QQ_EText=(EditText)findViewById(R.id.activity_main_EText_QQ); passwd_EText=(EditText)findViewById(R.id.activity_main_EText_password); passwd_EText_reptition=(EditText)findViewById(R.id.activity_main_EText_password_reptition); checkBox=(CheckBox)findViewById(R.id.activity_main_CheckBox); regist_button=(Button)findViewById(R.id.activity_main_Button_register); checkBox.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if(checkBox.isChecked()) regist_button.setEnabled(true); else regist_button.setEnabled(false); } }); sex_radiogroup.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { if(checkedId==R.id.activity_main_RadioButton_man) sex='男'; else if(checkedId==R.id.activity_main_RadioButton_woman) sex='女'; } }); regist_button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if(username_EText.getText().toString().length() == 0){ Toast.makeText(MainActivity.this,"用户名不能为空", Toast.LENGTH_SHORT).show(); } else if(passwd_EText.getText().toString().length() == 0 ||passwd_EText_reptition.getText().toString().length() == 0){ Toast.makeText(MainActivity.this,"密码不能为空", Toast.LENGTH_SHORT).show(); } else if(!passwd_EText.getText().toString().equals(passwd_EText_reptition.getText().toString())){ Toast.makeText(MainActivity.this,"密码不一致", Toast.LENGTH_SHORT).show(); } else { Intent intent=new Intent(MainActivity.this,OtherActivity.class); Bundle bundle=new Bundle(); bundle.putString("username",username_EText.getText().toString()); bundle.putChar("sex", sex); bundle.putString("phonenum",phonenum_EText.getText().toString()); bundle.putString("QQ",QQ_EText.getText().toString()); intent.putExtras(bundle); startActivity(intent); } } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } } ``` OtherActivity.java ``` import android.app.Activity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.TextView; import android.widget.Toast; public class OtherActivity extends Activity { private Button button=null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_other); button=(Button)findViewById(R.id.activity_other_Button); Bundle bundle=this.getIntent().getExtras(); TextView username=(TextView)findViewById(R.id.activity_other_username); username.setText(bundle.getString("username")); while(bundle.getString("sex") != null){ TextView phonenum=(TextView)findViewById(R.id.activity_other_sex); phonenum.setText(bundle.getString("sex")); } while(bundle.getString("phonenum") != null){ TextView phonenum=(TextView)findViewById(R.id.activity_other_phonenum); phonenum.setText(bundle.getString("phonenum")); } while(bundle.getString("QQ") != null){ TextView phonenum=(TextView)findViewById(R.id.activity_other_QQ); phonenum.setText(bundle.getString("QQ")); } button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Toast.makeText(OtherActivity.this, "注册成功,等待进入主界面", Toast.LENGTH_LONG).show(); } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.other, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } } ```

求救: android.database.sqlite.SQLiteException: no such column: 商品类型 (code 1): , while compiling: SELECT * FROM TTList WHERE

因为是复制别人的代码更改的,出现了点击查询按钮后程序闪退 错误信息: ![图片说明](https://img-ask.csdn.net/upload/202005/23/1590218391_886155.png) ![图片说明](https://img-ask.csdn.net/upload/202005/23/1590218438_52233.png) xml: ``` <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".MainActivity"> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="姓名:" android:textSize="20dp"/> <EditText android:id="@+id/name" android:layout_width="150dp" android:layout_height="wrap_content" /> </LinearLayout> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="手机号:" android:textSize="20dp"/> <EditText android:id="@+id/number" android:layout_width="150dp" android:layout_height="wrap_content" /> </LinearLayout> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="始发地:" android:textSize="20dp"/> <EditText android:id="@+id/shifadi" android:layout_width="150dp" android:layout_height="wrap_content" /> </LinearLayout> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="目的地:" android:textSize="20dp"/> <EditText android:id="@+id/mudidi" android:layout_width="150dp" android:layout_height="wrap_content" /> </LinearLayout> <RadioGroup android:id="@+id/RadioGroup1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="性别:" android:textSize="20dp"/> <RadioButton android:id="@+id/man" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="男" android:textSize="20dp"/> <RadioButton android:id="@+id/woman" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="女" android:textSize="20dp"/> </RadioGroup> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="商品类型:" android:textSize="20dp"/> <Spinner android:id="@+id/spinner" android:layout_width="wrap_content" android:layout_height="wrap_content"> </Spinner> </LinearLayout> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal"> <Button android:id="@+id/but1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="保存"/> <Button android:id="@+id/but2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="查询"/> <Button android:id="@+id/del" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="删除"/> </LinearLayout> <TextView android:id="@+id/info" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout> ``` MainActivity.java ``` package com.example.sql; import android.content.ContentValues; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.os.Bundle; import android.view.View; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.EditText; import android.widget.RadioButton; import android.widget.Spinner; import android.widget.TextView; import android.widget.Toast; import androidx.appcompat.app.AppCompatActivity; public class MainActivity extends AppCompatActivity { private MyDatabaseHelper dbHelper; private String[] spinnerItems = {"果蔬", "快递", "食品"}; String str=""; String man1=""; String woman1=""; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button putDatabase=(Button) findViewById(R.id.but1); Button outDatabase=(Button) findViewById(R.id.but2); Button delDatabase=(Button) findViewById(R.id.del); final TextView tv=(TextView)findViewById(R.id.info);//获取info所在TextView的位置,便于打印信息 final EditText et1=(EditText) findViewById(R.id.name);//获取姓名位置 final EditText et2=(EditText) findViewById(R.id.number);//获取手机号位置 final EditText et3=(EditText) findViewById(R.id.shifadi);//获取始发地 final EditText et4=(EditText) findViewById(R.id.mudidi);//获取目的地 final RadioButton sex1=(RadioButton) findViewById(R.id.man);//获取单选按钮组 final RadioButton sex2=(RadioButton) findViewById(R.id.woman);//获取单选按钮组 final Spinner spin=(Spinner) findViewById(R.id.spinner);//获取Spinner //给Spinner添加适配器 ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<>(MainActivity.this, android.R.layout.simple_list_item_1, spinnerItems); spin.setAdapter(spinnerAdapter); //创建数据库,建立表名字为TTList.db dbHelper=new MyDatabaseHelper(this,"TTList.db",null,1); dbHelper.getWritableDatabase(); //存数据 putDatabase.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { SQLiteDatabase db=dbHelper.getWritableDatabase(); ContentValues values=new ContentValues(); String na=et1.getText().toString();//获取名字信息 String num=et2.getText().toString();//获取手机号信息 String shi=et3.getText().toString();//获取始发地 String mu=et4.getText().toString();//获取目的地 values.put("姓名",na);//存学号 values.put("手机号",num);//存名字 values.put("始发地",shi);//存始发地 values.put("目的地",mu);//存目的地 if(sex1.isChecked()){ man1="男"; values.put("性别",man1); } if(sex2.isChecked()){ woman1="女"; values.put("性别",woman1);//存性别 } values.put("商品类型",spin.getSelectedItem().toString()); if(num.equals("")||na.equals("")||man1.equals("")&&woman1.equals("")||spin.getSelectedItem().toString().equals("")) { Toast.makeText(MainActivity.this, "信息不全,请补充", Toast.LENGTH_SHORT).show(); } else{ db.insert("TTList",null,values); //注意别漏掉 values.clear(); Toast.makeText(MainActivity.this, "保存成功", Toast.LENGTH_SHORT).show(); et1.setText(""); et2.setText(""); et3.setText(""); et4.setText(""); } } }); //读数据 outDatabase.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { SQLiteDatabase db=dbHelper.getWritableDatabase(); Cursor cursor=db.query("TTList",null,null,null,null,null,null); if(cursor.moveToFirst()){ do{ String number=cursor.getString(cursor.getColumnIndex("手机号"));//根据key值读取信息 String name=cursor.getString(cursor.getColumnIndex("姓名")); String sex=cursor.getString(cursor.getColumnIndex("性别")); String subject=cursor.getString(cursor.getColumnIndex("商品类型")); String shi=cursor.getString(cursor.getColumnIndex("始发地")); String mu=cursor.getString(cursor.getColumnIndex("目的地")); str+="姓名为:"+name+";"+ "手机号为:"+number+";"+ "性别为:"+sex+ ";"+ "商品类型:"+subject+"始发地:"+shi+";"+"目的地:"+mu+";"+"\n";//将数据库信息存到str中并换行 }while (cursor.moveToNext()); } cursor.close(); tv.setText(str); } }); delDatabase.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { SQLiteDatabase db=dbHelper.getWritableDatabase(); db.delete("TTList",null,null); tv.setText(""); str=""; } }); } } ``` 数据库的代码: ``` package com.example.sql; import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.widget.Toast; public class MyDatabaseHelper extends SQLiteOpenHelper { public static final String CREATE_LIST="create table TTList(" +"id integer primary key autoincrement," +"姓名 text," +"手机号 integer," +"始发地 text," +"目的地 text," +"性别 text," +"商品类型 text)"; private Context mContext; public MyDatabaseHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version){ super(context,name,factory,version); mContext=context; } @Override public void onCreate(SQLiteDatabase db) { db.execSQL(CREATE_LIST); Toast.makeText(mContext, "创建成功", Toast.LENGTH_SHORT).show(); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } } ```

Android应用:页面停止工作

<div class="post-text" itemprop="text"> <p>I am developing a simple Android app and am getting a 'App stopped working' error.</p> <p>The error seems to happen when I exit my <code>preOnExecute</code> method but if I comment that out the app falls over on next code piece anyway.</p> <p>Test: Open screen/activity, there are 5 pre filled textboxes and a button. If I click the button the code hits a class that opens a dialog in 'OnPreExecute' and it fails on execiting this method. </p> <p>Its probably something to do with the background thread not liking whats happening on UI but i dont know. </p> <p>Any idea how I can troubleshoot this?</p> <p>See below for code</p> <pre><code>package android22.app.namespace; import java.util.ArrayList; import java.util.List; import org.apache.http.NameValuePair; import org.apache.http.message.BasicNameValuePair; import org.json.JSONException; import org.json.JSONObject; import android.app.Activity; import android.app.ProgressDialog; import android.content.Intent; import android.os.AsyncTask; import android.os.Bundle; import android.util.Log; import android.view.View; import android.webkit.ConsoleMessage; import android.widget.Button; import android.widget.EditText; import android.widget.RadioButton; import android.widget.RadioGroup; import android.widget.TextView; import android22.voter.namespace.appSubmitAnswerActivity.GetQuestionDetails; import android22.voter.namespace.appSubmitAnswerActivity.SaveAnswerDetails; public class appCreateQuestionActivity extends Activity { //controls EditText editTextTitle; EditText editTextQuestionString; EditText editTextA1; EditText editTextA2; EditText editTextA3; EditText editTextA4; EditText editTextA5; Button buttonSubmitQuestion; // Progress Dialog private ProgressDialog qDialog; // JSON parser class JSONParser jsonParser = new JSONParser(); // single question url private static final String url_insert_question_details = "http://xxx.xxx.xxx.xxx/voter/Voter_Db_CreateNewQuestion.php"; // JSON Node names private static final String TAG_SUCCESS = "success"; private static final String TAG_QUESTION = "question"; private static final String TAG_QID = "Qid"; private static final String TAG_TITLE = "Title"; private static final String TAG_QUESTIONSTRING = "QuestionString"; private static final String TAG_A1 = "A1"; private static final String TAG_A2 = "A2"; private static final String TAG_A3 = "A3"; private static final String TAG_A4 = "A4"; private static final String TAG_A5 = "A5"; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.createquestion); // save button buttonSubmitQuestion = (Button) findViewById(R.id.btnCreate); /*Set Control Listeners */ buttonSubmitQuestion.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { // starting background task to update question new SaveQuestionDetails().execute(); } }); } class SaveQuestionDetails extends AsyncTask&lt;String, String, String&gt; { /** * Before starting background thread Show Progress Dialog * */ @Override protected void onPreExecute() { super.onPreExecute(); qDialog = new ProgressDialog(VoterCreateQuestionActivity.this); qDialog.setMessage("Saving ..."); qDialog.setIndeterminate(false); qDialog.setCancelable(true); qDialog.show(); } /** * Saving question * */ protected String doInBackground(String... args) { String Title = editTextTitle.getText().toString(); String Question = editTextQuestionString.getText().toString(); String A1 = editTextA1.getText().toString(); String A2 = editTextA2.getText().toString(); String A3 = editTextA3.getText().toString(); String A4 = editTextA4.getText().toString(); String A5 = editTextA5.getText().toString(); // Building Parameters List&lt;NameValuePair&gt; params = new ArrayList&lt;NameValuePair&gt;(); params.add(new BasicNameValuePair(TAG_QID, "1")); params.add(new BasicNameValuePair(TAG_TITLE, Title)); params.add(new BasicNameValuePair(TAG_QUESTION, Question)); params.add(new BasicNameValuePair(TAG_A1, A1)); params.add(new BasicNameValuePair(TAG_A2, A2)); params.add(new BasicNameValuePair(TAG_A3, A3)); params.add(new BasicNameValuePair(TAG_A4, A4)); params.add(new BasicNameValuePair(TAG_A5, A5)); // sending modified data through http request // Notice that update question url accepts POST method JSONObject json = jsonParser.makeHttpRequest(url_insert_question_details, "POST", params); // check json success tag try { int success = json.getInt(TAG_SUCCESS); if (success == 1) { // successfully updated Intent i = getIntent(); // send result code 100 to notify about question update setResult(100, i); finish(); } else { // failed to update question } } catch (JSONException e) { e.printStackTrace(); } return null; } /** * After completing background task Dismiss the progress dialog * **/ protected void onPostExecute(String file_url) { // dismiss the dialog once question updated qDialog.dismiss(); } } } </code></pre> <p>I get the following LogCat</p> <pre><code>09-20 16:03:15.703: D/gralloc_goldfish(658): Emulator without GPU emulation detected. 09-20 16:20:39.298: W/dalvikvm(658): threadid=12: thread exiting with uncaught exception (group=0x409961f8) 09-20 16:20:39.463: E/AndroidRuntime(658): FATAL EXCEPTION: AsyncTask #1 09-20 16:20:39.463: E/AndroidRuntime(658): java.lang.RuntimeException: An error occured while executing doInBackground() 09-20 16:20:39.463: E/AndroidRuntime(658): at android.os.AsyncTask$3.done(AsyncTask.java:278) 09-20 16:20:39.463: E/AndroidRuntime(658): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273) 09-20 16:20:39.463: E/AndroidRuntime(658): at java.util.concurrent.FutureTask.setException(FutureTask.java:124) 09-20 16:20:39.463: E/AndroidRuntime(658): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307) 09-20 16:20:39.463: E/AndroidRuntime(658): at java.util.concurrent.FutureTask.run(FutureTask.java:137) 09-20 16:20:39.463: E/AndroidRuntime(658): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076) 09-20 16:20:39.463: E/AndroidRuntime(658): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569) 09-20 16:20:39.463: E/AndroidRuntime(658): at java.lang.Thread.run(Thread.java:856) 09-20 16:20:39.463: E/AndroidRuntime(658): Caused by: java.lang.NullPointerException 09-20 16:20:39.463: E/AndroidRuntime(658): at android22.voter.namespace.AppCreateQuestionActivity$SaveQuestionDetails.doInBackground(VoterCreateQuestionActivity.java:109) 09-20 16:20:39.463: E/AndroidRuntime(658): at android22.voter.namespace.AppCreateQuestionActivity$SaveQuestionDetails.doInBackground(VoterCreateQuestionActivity.java:1) 09-20 16:20:39.463: E/AndroidRuntime(658): at android.os.AsyncTask$2.call(AsyncTask.java:264) 09-20 16:20:39.463: E/AndroidRuntime(658): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305) 09-20 16:20:39.463: E/AndroidRuntime(658): ... 4 more 09-20 16:20:41.493: E/WindowManager(658): Activity android22.voter.namespace.AppCreateQuestionActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@416e3798 that was originally added here 09-20 16:20:41.493: E/WindowManager(658): android.view.WindowLeaked: Activity android22.voter.namespace.AppCreateQuestionActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@416e3798 that was originally added here 09-20 16:20:41.493: E/WindowManager(658): at android.view.ViewRootImpl.&lt;init&gt;(ViewRootImpl.java:343) 09-20 16:20:41.493: E/WindowManager(658): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:245) 09-20 16:20:41.493: E/WindowManager(658): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:193) 09-20 16:20:41.493: E/WindowManager(658): at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:118) 09-20 16:20:41.493: E/WindowManager(658): at android.view.Window$LocalWindowManager.addView(Window.java:537) 09-20 16:20:41.493: E/WindowManager(658): at android.app.Dialog.show(Dialog.java:274) 09-20 16:20:41.493: E/WindowManager(658): at android22.voter.namespace.AppCreateQuestionActivity$SaveQuestionDetails.onPreExecute(VoterCreateQuestionActivity.java:101) 09-20 16:20:41.493: E/WindowManager(658): at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:561) 09-20 16:20:41.493: E/WindowManager(658): at android.os.AsyncTask.execute(AsyncTask.java:511) 09-20 16:20:41.493: E/WindowManager(658): at android22.voter.namespace.VoterCreateQuestionActivity$1.onClick(AppCreateQuestionActivity.java:81) 09-20 16:20:41.493: E/WindowManager(658): at android.view.View.performClick(View.java:3480) 09-20 16:20:41.493: E/WindowManager(658): at android.view.View$PerformClick.run(View.java:13983) 09-20 16:20:41.493: E/WindowManager(658): at android.os.Handler.handleCallback(Handler.java:605) 09-20 16:20:41.493: E/WindowManager(658): at android.os.Handler.dispatchMessage(Handler.java:92) 09-20 16:20:41.493: E/WindowManager(658): at android.os.Looper.loop(Looper.java:137) 09-20 16:20:41.493: E/WindowManager(658): at android.app.ActivityThread.main(ActivityThread.java:4340) 09-20 16:20:41.493: E/WindowManager(658): at java.lang.reflect.Method.invokeNative(Native Method) 09-20 16:20:41.493: E/WindowManager(658): at java.lang.reflect.Method.invoke(Method.java:511) 09-20 16:20:41.493: E/WindowManager(658): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) 09-20 16:20:41.493: E/WindowManager(658): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 09-20 16:20:41.493: E/WindowManager(658): at dalvik.system.NativeStart.main(Native Method) </code></pre> </div>

APP与STM32单片机通过WiFi连接,但是WiFi连接不成功,求问为什么连接不上,是我代码出问题了吗?求问到底是哪里不对啊?

APP是作为TCP服务端,WiFi是ESP8266模块,单片机是正点原子mini版STM32的,代码也写出来了但是与WiFi连接不成功,求问到底是哪里不对啊,代码运行没问题,代码如下: ``` package com.example.smxy.myapplication;import android.content.Intent; import android.os.Bundle; import android.os.Handler; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.RadioButton; import android.widget.TextView; import android.widget.Toast;import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.InetAddress; import java.net.Socket; import java.net.UnknownHostException;import butterknife.BindView; import butterknife.ButterKnife; import butterknife.OnClick;public class ControlActivity extends AppCompatActivity { @BindView(R.id.temperature) EditText temperature; @BindView(R.id.humidity) EditText humidity; @BindView(R.id.smoke) EditText smoke; @BindView(R.id.close) RadioButton close; @BindView(R.id.open) RadioButton open; @BindView(R.id.welcome) TextView welcome; @BindView(R.id.ip) TextView ip; @BindView(R.id.port) TextView port; @BindView(R.id.connect) Button connect; //开辟一个socket控件 Socket socket = null; //定义数据输出流,用于发送数据 private OutputStream outputStream = null; //定义数据输入流,用于接收数据 private InputStream inputStream = null; //定义一个逻辑便利,用于判断服务器状态 boolean isConnected = true; //定义一个逻辑变量,用于控制读数据线程是否执行 boolean read = false; //定义一个变量,判断风扇开关 int flag = 1; //1为关闭,2位开启 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_control); ButterKnife.bind(this); String str = "欢迎来到智能家居"; Intent intent = getIntent(); String name = intent.getStringExtra("username"); welcome.setText(name + "," + str); } @OnClick({R.id.temperature, R.id.humidity, R.id.smoke, R.id.close, R.id.open}) public void onViewClicked(View view) { switch (view.getId()) { case R.id.temperature: break; case R.id.humidity: break; case R.id.smoke: break; case R.id.close: flag = 1; break; case R.id.open: flag = 2; break; } } @OnClick(R.id.connect) public void onViewClicked() { //true表示连接 if (isConnected==true){ isConnected=false; connect.setText("断开连接"); //启动连接线程 Connect_Thread connectThread=new Connect_Thread(); connectThread.start(); Toast.makeText(this,"wifi连接成功",Toast.LENGTH_SHORT).show(); }else { isConnected=true; connect.setText("连接"); } } //连接线程 class Connect_Thread extends Thread{ @Override public void run() { try { if (socket==null){ //用InetAdress方法获取IP地址 InetAddress ipAdress=InetAddress.getByName(ip.getText().toString()); int portNumber = Integer.valueOf(port.getText().toString()); //创建连接地址和端口 socket=new Socket(ipAdress,portNumber); //创建完socket连接后启动接收线程 Receive_Thread receiveThread = new Receive_Thread(); receiveThread.start(); Toast.makeText(ControlActivity.this,"数据已接收",Toast.LENGTH_SHORT).show(); } }catch (UnknownHostException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } } //接收数据线程 class Receive_Thread extends Thread{ @Override public void run() { try { while (true){ //创建接收缓冲区 final byte[] buferr = new byte[256]; inputStream=socket.getInputStream(); //读取数据,并且返回数据的长度 final int len=inputStream.read(buferr); //不允许其他线程直接操作组件 runOnUiThread(new Runnable() { @Override public void run() { try { String str=""; int i=0; while (i<len){ str=str+buferr[i]; i++; } if (str=="STATUS1"){ }else { temperature.setText(new String(buferr,2,2)); humidity.setText(new String(buferr,5,2)); smoke.setText(new String(buferr,11,4)); } //发送数据 outputStream=socket.getOutputStream(); String send; if (flag==1){ send="OFF"; outputStream.write(send.getBytes()); }else{ send="ON"; outputStream.write(send.getBytes()); } } catch (IOException e) { e.printStackTrace(); } } }); } } catch (IOException e) { e.printStackTrace(); } } } } ```

binary xml file line#7:error inflating class

错误代码,然后贴上xml文件: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" > <com.example.browserstation.touchmove android:id="@+id/view1" android:layout_width="fill_parent" android:layout_height="wrap_content" /> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:text="Button" /> </RelativeLayout> view名肯定没错,路径也没错,换另一个View就没错,换这个就错了。touchmove单独可运行

Android单选按钮值无法存储在phpmysql中:“必填字段缺失”

<div class="post-text" itemprop="text"> <p>So i've created several editText fields in Android studio with each connected to the mysql through php (I'm using xampp btw). Now my problem is, **it returns a "Required Fields are Missing"**x after changing the <code>tbuyer</code> from editText view to a 2 RadioButton namely(<code>r_tb; r_ntb</code>) inside a RadioGroup.</p> <p>Now in order to get a string from those two, I declared a <code>String role=" ";</code> with condition using the RadioGroup:</p> <pre><code>if (radioGroup.getCheckedRadioButtonId() == r_tb.getId()) { role = "Trade Buyer"; } else if (radioGroup.getCheckedRadioButtonId() == r_ntb.getId()) { role = "Non Trade Buyer"; } </code></pre> <p>then pass it along the parameters that will be sent to hash map:</p> <pre><code>@Override protected Map&lt;String, String&gt; getParams() throws AuthFailureError { //put all parameters that will be sent to hash map Map&lt;String, String&gt; params = new HashMap&lt;&gt;(); params.put("cname", cname); //String is converted to final, because we'are using it in a class; refer to line 48-50 params.put("date", date); params.put("lname", lname); params.put("fname", fname); params.put("mi", mi); params.put("email", email); params.put("city", city); params.put("country", country); params.put("tbuyer", role); // check code; String created from radio button return params; } </code></pre> <p>then call a string request for json, so that we will know if the registration is successful or not. But as I said, it returns **Required fields are missing"</p> <p>These are my codes for <strong>Buyer_Registration_Activity.java</strong>:</p> <pre><code>import android.app.ProgressDialog; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.support.v7.widget.Toolbar; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.RadioButton; import android.widget.RadioGroup; import android.widget.Toast; import com.android.volley.AuthFailureError; import com.android.volley.Request; import com.android.volley.RequestQueue; import com.android.volley.Response; import com.android.volley.VolleyError; import com.android.volley.toolbox.StringRequest; import com.android.volley.toolbox.Volley; import com.example.smdojt.manilafame.R; import org.json.JSONException; import org.json.JSONObject; import java.util.HashMap; import java.util.Map; public class Buyer_Registration_Activity extends AppCompatActivity implements View.OnClickListener{ private EditText editTextCompanyName, editTextDate, editTextLastName, editTextFirstName, editTextMiddleInitial , editTextCity, editTextCountry, editTextType, editTextEmail; private Button buttonRegister; private ProgressDialog progressDialog; String role = ""; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_buyer_registration); //this.setTitle("Buyer Registration"); Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar); setSupportActionBar(myToolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); myToolbar.setNavigationIcon(R.drawable.ic_arrow_back_black_24dp); editTextCompanyName = (EditText) findViewById(R.id.editTextCompanyName); editTextDate = (EditText) findViewById(R.id.editTextDate); editTextLastName = (EditText) findViewById(R.id.editTextLastName); editTextFirstName = (EditText) findViewById(R.id.editTextFirstName); editTextMiddleInitial = (EditText) findViewById(R.id.editTextMiddleInitial); editTextCity = (EditText) findViewById(R.id.editTextCity); editTextType = (EditText) findViewById(R.id.editTextType); editTextCountry = (EditText) findViewById(R.id.editTextCountry); editTextEmail = (EditText) findViewById(R.id.editTextEmail); buttonRegister = (Button) findViewById(R.id.buttonRegister); progressDialog = new ProgressDialog(this); buttonRegister.setOnClickListener(this); } private void registerUser(){ final String cname = editTextCompanyName.getText().toString().trim(); final String date = editTextDate.getText().toString().trim(); final String lname = editTextLastName.getText().toString().trim(); final String fname = editTextFirstName.getText().toString().trim(); final String mi = editTextMiddleInitial.getText().toString().trim(); final String email = editTextEmail.getText().toString().trim(); final String city = editTextCity.getText().toString().trim(); final String country = editTextCountry.getText().toString().trim(); final String tbuyer = editTextType.getText().toString().trim(); final RadioGroup radioGroup = (RadioGroup) findViewById(R.id.radioGroup); final RadioButton r_tb = (RadioButton) findViewById(R.id.radio_tb); final RadioButton r_ntb = (RadioButton) findViewById(R.id.radio_ntb); if (radioGroup.getCheckedRadioButtonId() == r_tb.getId()) { role = "Trade Buyer"; } else if (radioGroup.getCheckedRadioButtonId() == r_ntb.getId()) { role = "Non Trade Buyer"; } progressDialog.setMessage("Registering User..."); progressDialog.show(); StringRequest stringRequest = new StringRequest(Request.Method.POST, com.example.smdojt.manilafame.sql_demo_2.Constants.URL_REGISTER, new Response.Listener&lt;String&gt;() { @Override public void onResponse(String response) {//If there are no ERROR this method will be executed progressDialog.dismiss(); //we will get the json object try { JSONObject jsonObject = new JSONObject(response); //create json object Toast.makeText(getApplicationContext(), jsonObject.getString("message"), Toast.LENGTH_LONG).show(); } catch (JSONException e) { e.printStackTrace(); } } }, new Response.ErrorListener(){ @Override public void onErrorResponse(VolleyError error) { // Else, this method will be executed progressDialog.hide(); Toast.makeText(getApplicationContext(), error.getMessage(), Toast.LENGTH_LONG).show(); } }){ @Override protected Map&lt;String, String&gt; getParams() throws AuthFailureError { //put all parameters that will be sent to hash map Map&lt;String, String&gt; params = new HashMap&lt;&gt;(); params.put("cname", cname); //String is converted to final, because we'are using it in a class; refer to line 48-50 params.put("date", date); params.put("lname", lname); params.put("fname", fname); params.put("mi", mi); params.put("email", email); params.put("city", city); params.put("country", country); params.put("tbuyer", role); // check code; String created from radio button //params.put("tbuyer", tbuyer); return params; } }; //add stringRequest (Line 55) RequestQueue requestQueue = Volley.newRequestQueue(this); requestQueue.add(stringRequest); } @Override public void onClick(View view) { if (view==buttonRegister) { registerUser(); } } } </code></pre> <p>These are my codes for <strong>DBOperations.php</strong> (Crud operations declaration)</p> <pre><code>&lt;?php //manage all php and db operations class DbOperations { private $con; function __construct() { require_once dirname(__FILE__).'/DbConnect.php'; //import dbconnect to dboperations $db = new DbConnect(); //create db connect object $this-&gt;con = $db-&gt;connect(); } //CRUD Operations below //Create----------------------------------------------------------------------------------------------- function registerBuyer($cname, $date, $lname, $fname, $mi, $email, $country, $city, $tbuyer) { //$password = md5($password); //encrypt password $stmt = $this-&gt;con-&gt;prepare("INSERT INTO `mfmis_buyers`.`buyers` (`id`, `cname`, `date`, `lname`, `fname`, `mi`, `email`, `country`, `city`, `tbuyer`) VALUES (NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?);"); //statement //find actual parameters /bind param $stmt-&gt;bind_param("sssssssss", $cname, $date, $lname, $fname, $mi, $email, $country, $city, $tbuyer); //bind to query //execute query below if ($stmt-&gt;execute()) //as soon as this line is called, data will be inserted into DB { return true; } else { return false; } } //----------------------------------------------------------------------------------------------------- } ?&gt; </code></pre> <p>and these are my codes for <strong>registerBuyer.php</strong> (where all my error statements comes from including <strong>"REQUIRED FIELDS ARE MISSING"</strong>)</p> <pre><code>&lt;?php require_once '../includes/DbOperations.php'; $response = array(); if($_SERVER['REQUEST_METHOD']=='POST') { if( isset($_POST['cname']) and isset($_POST['date']) and isset($_POST['lname']) and isset($_POST['fname']) and isset($_POST['mi']) and isset($_POST['email']) and isset($_POST['country']) and isset($_POST['city']) and isset($_POST['tbuyer'])) { //operate the data further $db = new DbOperations(); if($db-&gt;registerBuyer( $_POST['cname'], $_POST['date'], $_POST['lname'], $_POST['fname'], $_POST['mi'], $_POST['email'], $_POST['country'], $_POST['city'], $_POST['tbuyer'] )) { $response['error'] = false; $response['message'] = "Buyer Registered Successfully"; } else { $response['error'] = true; $response['message'] = "Some error occured try again"; } } else { $response['error'] = true; $response['message'] = "Required fields are missing"; } } else { $response['error'] = true; $response['message'] ="Invalid request"; } echo json_encode($response); ?&gt; </code></pre> </div>

运行自己编写的app出问题

因为第一次自己编写android,我找了老半天也没有找到问题,在AVD上运行,总是显示“Uunfotunately。。。。“ 以下是代码 xml: <?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:tools="http://schemas.android.com/tools" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_centerVertical="true"> <LinearLayout android:id="@+id/activity_main" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:orientation="vertical" tools:context="com.example.a29185.test_app.MainActivity"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/title" android:layout_marginTop="@dimen/activity_vertical_margin" android:gravity="center" android:textStyle="bold" android:textSize="20sp" android:text="QUESTION" /> <TextView style="@style/MainText" android:id="@+id/one" android:text="1. What's your name:" /> <EditText android:id="@+id/name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:inputType="textImeMultiLine" android:hint="Input your name" android:singleLine="false"/> /> <TextView style="@style/MainText" android:id="@+id/two" android:text="2. 2 + 2 = 3" /> <RadioGroup android:id="@+id/radioGroup" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal"> <RadioButton android:id="@+id/yes" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Yes" android:layout_margin="5sp" /> <RadioButton android:id="@+id/no" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="No" android:layout_margin="5sp" /> </RadioGroup> <TextView style="@style/MainText" android:id="@+id/three" android:text="3. 1 + 1 =" /> <CheckBox android:id="@+id/three0" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="0" android:padding="10sp"/> <CheckBox android:id="@+id/three1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="1" android:padding="10sp"/> <CheckBox android:id="@+id/three2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="2" android:padding="10sp"/> <TextView style="@style/MainText" android:id="@+id/four" android:text="4. What's your goal:" /> <EditText android:id="@+id/goal" android:layout_width="wrap_content" android:layout_height="wrap_content" android:hint="Please input your goal" android:singleLine="false"/> <TextView style="@style/MainText" android:id="@+id/five" android:text="5. Are you like your family ?" /> <RadioGroup android:id="@+id/radioGroup1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal"> <RadioButton android:id="@+id/yes2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Yes" android:layout_margin="5sp" /> <RadioButton android:id="@+id/no2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="No" android:layout_margin="5sp" android:padding="10sp" /> </RadioGroup> <Button android:id="@+id/submit" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="submit" android:textAllCaps="false" android:layout_gravity="center_horizontal" android:layout_marginTop="50dp" android:onClick="getscore" /> </LinearLayout> </ScrollView> java: package com.example.a29185.test_app; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.widget.CheckBox; import android.widget.EditText; import android.widget.RadioButton; import android.widget.RadioGroup; import android.widget.Toast; public class MainActivity extends AppCompatActivity { int score = 0; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void getscore (int scor){ //judge first question. EditText editText1 = (EditText)findViewById(R.id.name); int a = Integer.valueOf(editText1.getText().toString()); if (a==0) score+=1; else score +=0; //judge second question. RadioGroup sex = (RadioGroup) findViewById (R.id.radioGroup); if(sex.getCheckedRadioButtonId()==R.id.yes) score +=1; else score +=0; //judge third question. CheckBox checkThree = (CheckBox)findViewById(R.id.three2); if (checkThree.isChecked()) score+=1; else score +=0; //judge fourth question. EditText editText = (EditText)findViewById(R.id.goal); int b = Integer.valueOf(editText.getText().toString()); if (b==0) score+=1; else score +=0; //judge fifth question. RadioGroup happy = (RadioGroup) findViewById (R.id.radioGroup1); if(happy.getCheckedRadioButtonId()==R.id.yes2) score +=1; else score +=0; display(score); } public void display(int score){ Toast.makeText(MainActivity.this,"The full score is 5.\nYou get "+ score+".",Toast.LENGTH_SHORT).show(); } } 请大家帮下忙,我找了好多遍都不知道为啥,代码没问题。只要点到submit按钮,就会出现“Unfortunately什么什么的“完了退出去,本身是可以进入界面的。

安卓sqlite的问题,不能点注册按钮,点了就出错。

安卓sqlite的问题,不能点注册按钮,点了就出错。然后控制台那边提示说是such no table,网上也查找过解决办法,说是把路径定死,可惜不知道哪里写合适,或者试了也不行? 注册java的代码 import java.io.File; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.app.Activity; import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase.CursorFactory; import android.widget.Button; import android.widget.EditText; import android.widget.RadioGroup; import android.widget.Toast; import android.view.View; import android.view.View.OnClickListener; import android.widget.RadioButton; public class ZhuceActivity extends Activity { private EditText edityhm,edityhmm,edityhxm,edityhsfz,edityhdh,edityhyx; private RadioButton rdman,rdwomen; private RadioGroup rdgroup; private Button yhzhuce; private Button yhfanhui; SQLiteDatabase db; // 声明一个变量zhuceOK。布尔类型 private boolean zhuceok = false; Handler handler; @Override protected void onDestroy() { // TODO Auto-generated method stub super.onDestroy(); db.close(); //不在当前页时会注销此页面 } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.zhuce); //获取控件 edityhm = (EditText)findViewById(R.id.edityhm); edityhmm = (EditText)findViewById(R.id.edityhmm); edityhxm = (EditText)findViewById(R.id.edityhxm); edityhsfz = (EditText)findViewById(R.id.edityhsfz); edityhyx = (EditText)findViewById(R.id.edityhyx); edityhdh = (EditText)findViewById(R.id.edityhdh); rdman = (RadioButton) findViewById(R.id.rdman); rdwomen = (RadioButton) findViewById(R.id.rdwomen); rdgroup = (RadioGroup)findViewById(R.id.rdgroup); yhzhuce = (Button)findViewById(R.id.yhzhuce); yhfanhui = (Button)findViewById(R.id.yhfanhui); // 添加监听 yhzhuce.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO 自动生成的方法存根 // 获取所有的用户信息,访问网络服务器端,将信息发送给服务器端去处理。 User user = new User(); user.setName(edityhm.getText().toString()); user.setPassword(edityhmm.getText().toString()); user.setYhsfz(edityhsfz.getText().toString()); user.setYhxm(edityhxm.getText().toString()); user.setYhyx(edityhyx.getText().toString()); user.setYhdh(edityhdh.getText().toString()); if (rdman.isChecked()) user.setSex("男"); else user.setSex("女"); if (zhuce(user)) {// 调用zhuce方法,如果注册成功 // 跳转到登录界面 Intent in = new Intent(); in.setClass(ZhuceActivity.this,LoginActivity.class); startActivity(in); // 销毁当前activity ZhuceActivity.this.onDestroy(); } else {// 注册不成功 Toast.makeText(ZhuceActivity.this, "sorry!!,注册失败", Toast.LENGTH_SHORT).show(); edityhm.requestFocus(); } }}); yhfanhui.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent in1 = new Intent(); in1.setClass(ZhuceActivity.this,LoginActivity.class); ZhuceActivity.this.startActivity(in1); } }); } // 添加用户 // User user这段语句是直接 public Boolean zhuce( User user) { Boolean zhuceok = false; String str = "insert into user values(?,?,?,?,?,?,?) "; LoginActivity main = new LoginActivity(); db=SQLiteDatabase.openOrCreateDatabase(this.getFilesDir().toString() +"/test.dbs",null); main.db = db; try { db.execSQL(str, new String[] { user.getName(),user.getPassword(),user.getYhsfz(),user.getYhxm(), user.getYhyx(),user.getYhdh(),user.getSex()}); zhuceok = true; } catch (Exception e) { main.createDb(); return zhuceok; } return zhuceok; } } 登录java代码 import android.os.Bundle; import android.app.Activity; import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteException; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; public class LoginActivity extends Activity { // 声明控件变量 注意变量为null时能 private EditText login_username; private EditText login_password; private Button zhuce; private Button denglu; public static SQLiteDatabase db; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login); login_username = (EditText)findViewById(R.id.login_username); login_password = (EditText)findViewById(R.id.login_password); zhuce = (Button)findViewById(R.id.zhuce); denglu = (Button)findViewById(R.id.denglu); zhuce.setOnClickListener(new zhuceListener()); denglu.setOnClickListener(new dengluListener()); db = SQLiteDatabase.openOrCreateDatabase(LoginActivity.this.getFilesDir().toString() + "/test.dbs", null); //getFilesDir().toString()是获取存放数据库文件的路径. } //添加一个监听器 class zhuceListener implements OnClickListener{ @Override public void onClick(View arg0) { // TODO 自动生成的方法存根 //生成一个Intent对象 Intent intent = new Intent(); intent.setClass(LoginActivity.this, ZhuceActivity.class); LoginActivity.this.startActivity(intent); } } class dengluListener implements OnClickListener{ @Override public void onClick(View arg0) { // TODO 自动生成的方法存根 String name = login_username.getText().toString(); String password = login_password.getText().toString(); if (name.equals("") || password.equals("")) { // 弹出消息框 AlertDialog 通过Builder方法,然后用show()来实现 new AlertDialog.Builder(LoginActivity.this).setTitle("错误") .setMessage("帐号或密码不能空").setPositiveButton("确定", null) .show(); } else { isUserinfo(name, password); } } } // 判断输入的用户是否正确 public Boolean isUserinfo(String name, String pwd) { try{ String str="select * from user where name=? and password=?"; Cursor cursor = db.rawQuery(str, new String []{name,pwd}); //Cursor 是每行的集合。SQLite 数据库,,,,db.rawQuery执行本地SQL语句查询 if(cursor.getCount()<=0){ new AlertDialog.Builder(LoginActivity.this).setTitle("错误") .setMessage("帐号或密码错误!").setPositiveButton("确定", null) .show(); return false; }else{ new AlertDialog.Builder(LoginActivity.this).setTitle("正确") .setMessage("成功登录").setPositiveButton("确定",new DialogInterface.OnClickListener(){ //设置确定按钮点击的事件Listener,可以直接在这边设置,纠结了好久 @Override public void onClick(DialogInterface dialog, int which) { //实现你的onclick方法 Intent it = new Intent(LoginActivity.this,JiemianActivity.class); startActivity(it); }} ). show(); return true; } }catch(SQLiteException e){ createDb(); } return false; } // 创建数据库和用户表 public void createDb() { db.execSQL("create table user( name varchar(30) primary key,password varchar(30),yhsfz varchar(50)," + "yhxm varchar(30),yhyx varchar(50),yhdh varchar(50),sex varchar(20)"); } //举例如果你触发startButton按钮事件启动线程,而没有触发stopButton按钮事件停止线程,在离开该页面时onDestroy()中的停止线程功能就发挥了作用 protected void onDestroy() { // TODO Auto-generated method stub super.onDestroy(); db.close(); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.login, menu); return true; } } 还有就是声明user对象的属性 public class User { private String name; private String password; private String yhsfz; private String yhxm; private String yhyx; private String yhdh; private String sex; public String getName(){ return name; } public void setName(String name){ this.name = name; } public String getPassword(){ return name; } public void setPassword(String password){ this.password = password; } public String getYhsfz(){ return yhsfz; } public void setYhsfz(String yhsfz){ this.yhsfz = yhsfz; } public String getYhxm(){ return yhxm; } public void setYhxm(String yhxm){ this.yhxm = yhxm; } public String getYhyx(){ return yhyx; } public void setYhyx(String yhyx){ this.yhyx = yhyx; } public String getYhdh(){ return yhdh; } public void setYhdh(String yhdh){ this.yhdh = yhdh; } public String getSex(){ return sex; } public void setSex(String sex){ this.sex = sex; } 不知道该如何解决,可能是哪里的代码写错了,望各路大神能指点下,感谢!

日期未插入Android应用程序的数据库中

<div class="post-text" itemprop="text"> <p>in my insert activity date of birth is not inserted in mysql database all other other record are inserted but date of birth not inserted. following is my code: getDate Function</p> <pre><code> private void getDate() { final Calendar c = Calendar.getInstance(); mYear = c.get(Calendar.YEAR); mMonth = c.get(Calendar.MONTH); mDay = c.get(Calendar.DAY_OF_MONTH); DatePickerDialog datePickerDialog = new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { et_dob.setText(dayOfMonth + "-" + (monthOfYear + 1) + "-" + year); } }, mYear, mMonth, mDay); datePickerDialog.show(); </code></pre> <p>params </p> <pre><code> Map&lt;String,String&gt; params = new HashMap&lt;String,String&gt;(); params.put(KEY_NAME,et_first_name.getText().toString()); params.put(KEY_MIDDLE_NAME,et_middle_name.getText().toString()); params.put(KEY_LAST_NAME,et_last_name.getText().toString()); params.put(KEY_DOB,et_dob.getText().toString()); // Log.d("mytag", "dob" + et_dob.getText().toString()); params.put(KEY_CITY,et_city.getText().toString()); params.put(KEY_GENDER,gender); params.put(KEY_STATE,et_state.getText().toString()); return params; </code></pre> <p>onCreate</p> <pre><code> et_first_name = (EditText) findViewById(R.id.et_first_name); et_middle_name = (EditText) findViewById(R.id.et_middle_name); et_last_name = (EditText) findViewById(R.id.et_last_name); et_dob = (EditText) findViewById(R.id.et_dob); et_state = (EditText) findViewById(R.id.et_state); et_city = (EditText) findViewById(R.id.et_city); rdb_1= (RadioButton) findViewById(R.id.rd_male); rdb_2= (RadioButton) findViewById(R.id.rd_female); </code></pre> <p>xml for date</p> <pre><code>&lt;EditText android:layout_width="match_parent" android:hint="Choose Date" android:layout_height="wrap_content" android:id="@+id/et_dob" android:inputType="date" android:padding="20dp" android:layout_centerVertical="true" android:layout_alignLeft="@+id/etTime" android:layout_alignStart="@+id/etTime" /&gt; </code></pre> <p>insert.php</p> <pre><code>if (isset($_POST['user_first_name'])&amp;&amp;($_POST['user_middle_name'])&amp;&amp;($_POST['user_last_name']) &amp;&amp; ($_POST['user_date_of_birth'])&amp;&amp;($_POST['user_gender'])&amp;&amp; ($_POST['user_state'])&amp;&amp;($_POST['user_city'])){ </code></pre> <p>extract($_POST);</p> <pre><code>$string_query="INSERT INTO `tbl_user` (`user_first_name`,`user_middle_name`,`user_last_name`,`user_date_of_birth`,`user_gender`,`user_state`,`user_city`) VALUES ('$user_first_name','$user_middle_name','$user_last_name','$user_date_of_birth','$user_gender','$user_state','$user_city')"; </code></pre> <p>when i try to insert date <code>0000-00-00</code> this is inserted in database any suggestion is welcome.</p> </div>

ListView和adapter模拟器无法运行

我刚接触安卓,今天学列表视图编写了一个小程序代码如下: package com.example.jiemian; import android.R.string; import android.os.Bundle; import android.app.Activity; import android.app.ListActivity; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.EditText; import android.widget.ListView; import android.widget.RadioButton; import android.widget.RadioGroup; import android.widget.RadioGroup.OnCheckedChangeListener; public class MainActivity extends ListActivity { EditText et_xm,et_xh,et_csrq; Button bt_zc,bt_cz; RadioGroup rg_xb; ListView lv_xianshi; RadioButton rb; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); et_xm=(EditText) findViewById(R.id.et_xm); et_xh=(EditText) findViewById(R.id.et_xh); et_csrq=(EditText) findViewById(R.id.et_csrq); bt_zc=(Button) findViewById(R.id.bt_zc); bt_cz=(Button) findViewById(R.id.bt_cz); rg_xb=(RadioGroup) findViewById(R.id.rg_xb); rg_xb.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { // TODO Auto-generated method stub rb=(RadioButton) findViewById(checkedId); rb.getText(); } }); bt_zc.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub String xh=et_xh.getText().toString(); String xm=et_xm.getText().toString(); String xb=rb.getText().toString(); String csrq=et_csrq.getText().toString(); String type[]=new String[]{xh,xm,xb,csrq}; ArrayAdapter<String> adapter =new ArrayAdapter<String>(MainActivity.this,android.R.layout.simple_spinner_item,type); setListAdapter(adapter); } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } } 结果在模拟器中无法运行,具体错误如下: 03-27 14:26:43.649: E/AndroidRuntime(1335): FATAL EXCEPTION: main 03-27 14:26:43.649: E/AndroidRuntime(1335): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.jiemian/com.example.jiemian.MainActivity}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list' 03-27 14:26:43.649: E/AndroidRuntime(1335): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180) 03-27 14:26:43.649: E/AndroidRuntime(1335): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230) 03-27 14:26:43.649: E/AndroidRuntime(1335): at android.app.ActivityThread.access$600(ActivityThread.java:141) 03-27 14:26:43.649: E/AndroidRuntime(1335): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234) 03-27 14:26:43.649: E/AndroidRuntime(1335): at android.os.Handler.dispatchMessage(Handler.java:99) 03-27 14:26:43.649: E/AndroidRuntime(1335): at android.os.Looper.loop(Looper.java:137) 03-27 14:26:43.649: E/AndroidRuntime(1335): at android.app.ActivityThread.main(ActivityThread.java:5041) 03-27 14:26:43.649: E/AndroidRuntime(1335): at java.lang.reflect.Method.invokeNative(Native Method) 03-27 14:26:43.649: E/AndroidRuntime(1335): at java.lang.reflect.Method.invoke(Method.java:511) 03-27 14:26:43.649: E/AndroidRuntime(1335): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 03-27 14:26:43.649: E/AndroidRuntime(1335): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 03-27 14:26:43.649: E/AndroidRuntime(1335): at dalvik.system.NativeStart.main(Native Method) 03-27 14:26:43.649: E/AndroidRuntime(1335): Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list' 03-27 14:26:43.649: E/AndroidRuntime(1335): at android.app.ListActivity.onContentChanged(ListActivity.java:243) 03-27 14:26:43.649: E/AndroidRuntime(1335): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:273) 03-27 14:26:43.649: E/AndroidRuntime(1335): at android.app.Activity.setContentView(Activity.java:1881) 03-27 14:26:43.649: E/AndroidRuntime(1335): at com.example.jiemian.MainActivity.onCreate(MainActivity.java:29) 03-27 14:26:43.649: E/AndroidRuntime(1335): at android.app.Activity.performCreate(Activity.java:5104) 03-27 14:26:43.649: E/AndroidRuntime(1335): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080) 03-27 14:26:43.649: E/AndroidRuntime(1335): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144) 03-27 14:26:43.649: E/AndroidRuntime(1335): ... 11 more 求大神指点一下这个问题???

在我的代码中获取JSON Parser的错误

<div class="post-text" itemprop="text"> <p>I am creating a registration form and sending data to MySql database through json in android but whenever i do click on submit button I got the following error in my logcat.</p> <pre><code> 12-19 18:19:22.145: E/JSON Parser(2620): Error parsing data org.json.JSONException: Value &lt;!DOCTYPE of type java.lang.String cannot be converted to JSONObject 12-19 18:19:22.365: W/dalvikvm(2620): threadid=11: thread exiting with uncaught exception (group=0x40a13300) 12-19 18:19:22.865: E/AndroidRuntime(2620): FATAL EXCEPTION: AsyncTask #1 12-19 18:19:22.865: E/AndroidRuntime(2620): java.lang.RuntimeException: An error occured while executing doInBackground() 12-19 18:19:22.865: E/AndroidRuntime(2620): at android.os.AsyncTask$3.done(AsyncTask.java:299) 12-19 18:19:22.865: E/AndroidRuntime(2620): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273) 12-19 18:19:22.865: E/AndroidRuntime(2620): at java.util.concurrent.FutureTask.setException(FutureTask.java:124) 12-19 18:19:22.865: E/AndroidRuntime(2620): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307) 12-19 18:19:22.865: E/AndroidRuntime(2620): at java.util.concurrent.FutureTask.run(FutureTask.java:137) 12-19 18:19:22.865: E/AndroidRuntime(2620): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230) 12-19 18:19:22.865: E/AndroidRuntime(2620): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076) 12-19 18:19:22.865: E/AndroidRuntime(2620): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569) 12-19 18:19:22.865: E/AndroidRuntime(2620): at java.lang.Thread.run(Thread.java:856) 12-19 18:19:22.865: E/AndroidRuntime(2620): Caused by: java.lang.NullPointerException 12-19 18:19:22.865: E/AndroidRuntime(2620): at app.restaurant.Register_Activity$RegisterUser.doInBackground(Register_Activity.java:162) 12-19 18:19:22.865: E/AndroidRuntime(2620): at app.restaurant.Register_Activity$RegisterUser.doInBackground(Register_Activity.java:1) 12-19 18:19:22.865: E/AndroidRuntime(2620): at android.os.AsyncTask$2.call(AsyncTask.java:287) 12-19 18:19:22.865: E/AndroidRuntime(2620): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305) 12-19 18:19:22.865: E/AndroidRuntime(2620): ... 5 more </code></pre> <p><strong>This is my android code of registering form</strong></p> <p><strong>Register_Activity.java</strong></p> <pre><code>public class Register_Activity extends Activity { //RadioGroup rg; private ProgressDialog pDialog; // RadioButton rb; // int id; TextView nm,ad,ps,ph,em; String password; Button bnt_Submit; EditText edt_email,edt_password,edt_name,edt_phone,edt_address,edt_lastName; JSONObject json; JSONParser jsonParser = new JSONParser(); private static String url_create_product = "http://192.168.1.9/adminfoodOld/public/jsonregister"; //http://www.truzzinfotech.co.nz/admin/public/jsonregister private static final String TAG_SUCCESS = "success"; //JSONArray phn,eml,pas,add,nam; String gender ="Male"; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.register); /* nm = (TextView)findViewById(R.id.TXt_Name); em = (TextView)findViewById(R.id.TXt_Email); ph = (TextView)findViewById(R.id.TXt_Ph); ps = (TextView)findViewById(R.id.TXt_password); ad = (TextView)findViewById(R.id.TXt_Ad); */ // rg = (RadioGroup)findViewById(R.id.radioGroup1); bnt_Submit =(Button)findViewById(R.id.btnsubmit); edt_email = (EditText)findViewById(R.id.Edt_Email); edt_password = (EditText)findViewById(R.id.Edt_Password); edt_name = (EditText)findViewById(R.id.Edt_Name); edt_phone = (EditText)findViewById(R.id.Edt_Phone); edt_address = (EditText)findViewById(R.id.Edt_Address); edt_lastName = (EditText)findViewById(R.id.Edt_LastName); /* id = rg.getCheckedRadioButtonId(); rb = (RadioButton)findViewById(id);*/ bnt_Submit.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub password = edt_password.getText().toString(); if (!isValidPassword(password)) { edt_password.setError("The Passward must be at least 8 character "); } // Toast.makeText(getApplicationContext(), gender+"Selected", Toast.LENGTH_LONG).show(); new RegisterUser().execute(); } }); } private boolean isValidPassword(String pass) { if (pass != null &amp;&amp; pass.length() &gt; 7) { return true; } return false; } class RegisterUser extends AsyncTask&lt;String, String, String&gt; { @Override protected void onPreExecute() { // TODO Auto-generated method stub super.onPreExecute(); pDialog = new ProgressDialog(Register_Activity.this); pDialog.setMessage("Registering..."); pDialog.setIndeterminate(false); pDialog.setCancelable(true); pDialog.show(); } @Override protected String doInBackground(String... params) { // TODO Auto-generated method stub // gender= rb.getText().toString(); String firstname =edt_name.getText().toString(); String emails =edt_email.getText().toString(); String phone =edt_phone.getText().toString(); String address =edt_address.getText().toString(); String lastname =edt_lastName.getText().toString(); List&lt;NameValuePair&gt; params1 = new ArrayList&lt;NameValuePair&gt;(); params1.add(new BasicNameValuePair("firstname", firstname)); params1.add(new BasicNameValuePair("password", password)); params1.add(new BasicNameValuePair("email", emails)); params1.add(new BasicNameValuePair("phone", phone)); params1.add(new BasicNameValuePair("address",address)); params1.add(new BasicNameValuePair("gender", gender)); params1.add(new BasicNameValuePair("lastname", lastname)); Log.d("param",params1.toString()); json = jsonParser.makeHttpRequest(url_create_product,"POST", params1); Log.d("Create Response", json.toString()); /* Log.d("Gender", gender.toString()); Log.d("name", firstname.toString()); Log.d("pass", password.toString()); Log.d("email", emails.toString()); Log.d("lastname", lastname.toString()); Log.d("address", address.toString());*/ try { int success = json.getInt(TAG_SUCCESS); if (success == 1) { // successfully created product /* Intent i = new Intent(getApplicationContext(), AllProductsActivity.class); startActivity(i);*/ // Toast.makeText(getApplicationContext(),"ravi kujaa", Toast.LENGTH_LONG).show(); // closing this screen //finish(); } else { // failed to create product } }catch (Exception e) { // TODO: handle exception } return null; } protected void onPostExecute(String file_url) { // dismiss the dialog once done pDialog.dismiss(); /* try { JSONObject json1 = json.getJSONObject("detail"); // phn,eml,pas,add,nam; phn = json1.optJSONArray("phone"); eml = json1.optJSONArray("email"); pas = json1.optJSONArray("password"); add = json1.optJSONArray("address"); nam = json1.optJSONArray("name"); // Log.d("Else_Part", json.toString()); Log.d("Name", nam.getString(0)); Log.d("Phone", phn.getString(0)); Log.d("Email", eml.getString(0)); Log.d("Password", pas.getString(0)); Log.d("Address", add.getString(0)); //edt_email,edt_password,edt_name,edt_phone,edt_address; if(nam != null) { nm.setText(nam.getString(0)); } if(eml!= null ){ em.setText(eml.getString(0)); } if(phn!= null ){ ph.setText(phn.getString(0)); } if(pas!= null ){ ps.setText(pas.getString(0)); } if(add!= null ){ ad.setText(add.getString(0)); } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } */ } } } </code></pre> <p>This is my php code result encoded in json</p> <pre><code>{"detail":{"email":["The email field is required."],"password":["The password field is required."],"firstname":["The firstname field is required."],"lastname":["The lastname field is required."],"phone":["The phone field is required."],"address":["The address field is required."]},"success":0} </code></pre> <p><strong>This is my Php file</strong></p> <pre><code>&lt;?php class FrontUserController extends \BaseController { /** * Display a listing of the resource. * * @return Response */ public function index() { if(controllerAssignView('frontuser')) { $frontuser = frontuser::all(); return View::make('admin.registered')-&gt;with('data', $frontuser); } else { return Redirect::to('index'); } } public function jsonregister() { $inputs = Input::all(); $validator = Validator::make( array( 'email' =&gt; $inputs['email'], 'password' =&gt; $inputs['password'], 'firstname' =&gt; $inputs['firstname'], 'lastname' =&gt; $inputs['lastname'], 'phone' =&gt; $inputs['phone'], 'address' =&gt; $inputs['address'] ), array( 'email' =&gt; 'required|email|unique:frontuser', 'password' =&gt; 'required|min:8', 'firstname' =&gt; 'required', 'lastname' =&gt; 'required', 'phone' =&gt; 'required|numeric', 'address' =&gt; 'required' ) ); if ($validator-&gt;fails()) { $messages = $validator-&gt;messages(); $userDetail = array(); $userDetail['detail'] = $messages; $userDetail['success'] = 0; return $userDetail; } else { $Frontuser = new frontuser; $Frontuser-&gt;email = $inputs['email']; $Frontuser-&gt;password = Hash::make($inputs['password']); $Frontuser-&gt;firstname = $inputs['firstname']; $Frontuser-&gt;lastname = $inputs['lastname']; $Frontuser-&gt;phone = $inputs['phone']; $Frontuser-&gt;address = $inputs['address']; $Frontuser-&gt;status = $inputs['active']; $Frontuser-&gt;gender = $inputs['gender']; if($inputs['type'] != 'null'){$Frontuser-&gt;$inputs['type'] =1;} $Frontuser-&gt;save(); $user = frontuser::where('email', '=', $inputs['email'])-&gt;take(1)-&gt;get(); $userDetail = array(); $userDetail['detail']['firstname'] = $user[0]-&gt;firstname; $userDetail['detail']['lastname'] = $user[0]-&gt;lastname; $userDetail['detail']['gender'] = $user[0]-&gt;gender; $userDetail['detail']['phone'] = $user[0]-&gt;phone; $userDetail['detail']['address'] = $user[0]-&gt;address; if($user[0]-&gt;facebook == 1){$userDetail['detail']['login'] = 'registered with facebook.';} if($user[0]-&gt;twitter == 1){$userDetail['detail']['login'] = 'registered with twitter.';} if($user[0]-&gt;googleplus == 1){$userDetail['detail']['login'] = 'registered with googleplus.';} $userDetail['success'] = 1; return $userDetail; } } </code></pre> <p>?&gt;</p> </div>

Volley post只对图像和文本一起工作到mysql db

<div class="post-text" itemprop="text"> <p>I am posting 4 text and 1 image to mysql db using the Volley library. The code works only once after that i am getting only empty response when i try to post and no data is seen in the sql db as well. Added all the necessary permissions in the Android manifest as well but not able to fond what is wrong with this code.</p> <p>JAVA:</p> <pre><code>public class Main extends AppCompatActivity implements View.OnClickListener { RadioButton radioType; RadioGroup radioGroup; EditText FoodName,FoodLocation,ShopName; TextView Camera,Gallery,Post; ImageView imageView; private Bitmap bitmap; private int PICK_IMAGE_REQUEST = 1; private String UPLOAD_URL ="http://xyz.ttt.com/upload.php"; private String KEY_IMAGE = "image"; private String KEY_NAME = "FoodName"; private String KEY_LOCATION = "FoodLocation"; private String KEY_SHOP = "ShopName"; private String KEY_TYPE = "Type"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); radioGroup = (RadioGroup)findViewById(R.id.RadioGroup); FoodName = (EditText)findViewById(R.id.FoodName); FoodLocation = (EditText)findViewById(R.id.FoodLocation); ShopName = (EditText)findViewById(R.id.ShopName); Camera = (TextView)findViewById(R.id.Camera); Gallery = (TextView)findViewById(R.id.Gallery); Post = (TextView)findViewById(R.id.Post); imageView=(ImageView)findViewById(R.id.image); Camera.setOnClickListener(this); Gallery.setOnClickListener(this); Post.setOnClickListener(this); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } @Override public void onClick(View v) { if(v == Gallery){ showFileChooser(); } if(v == Post){ uploadImage(); } } private void showFileChooser() { Intent intent = new Intent(); intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT); startActivityForResult(Intent.createChooser(intent, "Select Picture"), PICK_IMAGE_REQUEST); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == PICK_IMAGE_REQUEST &amp;&amp; resultCode == RESULT_OK &amp;&amp; data != null &amp;&amp; data.getData() != null) { Uri filePath = data.getData(); try { //Getting the Bitmap from Gallery bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), filePath); //Setting the Bitmap to ImageView imageView.setImageBitmap(bitmap); } catch (IOException e) { e.printStackTrace(); } } } public String getStringImage(Bitmap bmp){ ByteArrayOutputStream baos = new ByteArrayOutputStream(); bmp.compress(Bitmap.CompressFormat.JPEG, 100, baos); byte[] imageBytes = baos.toByteArray(); String encodedImage = Base64.encodeToString(imageBytes, Base64.DEFAULT); return encodedImage; } private void uploadImage(){ //Showing the progress dialog final ProgressDialog loading = ProgressDialog.show(this,"Uploading...","Please wait...",false,false); StringRequest stringRequest = new StringRequest(Request.Method.POST, UPLOAD_URL, new Response.Listener&lt;String&gt;() { @Override public void onResponse(String s) { //Disimissing the progress dialog loading.dismiss(); //Showing toast message of the response Toast.makeText(Main.this, s, Toast.LENGTH_LONG).show(); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError volleyError) { //Dismissing the progress dialog loading.dismiss(); //Showing toast Toast.makeText(Main.this, volleyError.getMessage().toString(), Toast.LENGTH_LONG).show(); } }){ @Override protected Map&lt;String, String&gt; getParams() throws AuthFailureError { //Converting Bitmap to String String image = getStringImage(bitmap); //Getting Image Name String FName = FoodName.getText().toString().trim(); String FLocation = FoodLocation.getText().toString().trim(); String SName = ShopName.getText().toString().trim(); int selectedId = radioGroup.getCheckedRadioButtonId(); radioType = (RadioButton)findViewById(selectedId); String rType = radioType.getText().toString().trim(); //Creating parameters Map&lt;String, String&gt; params = new Hashtable&lt;String, String&gt;(); //Adding parameters params.put(KEY_IMAGE, image); params.put(KEY_NAME, FName); params.put(KEY_LOCATION, FLocation); params.put(KEY_SHOP, SName); params.put(KEY_TYPE, rType); //returning parameters return params; } }; //Creating a Request Queue RequestQueue requestQueue = Volley.newRequestQueue(this); //Adding request to the queue requestQueue.add(stringRequest); } } </code></pre> <p>PHP: </p><pre><code>if($_SERVER['REQUEST_METHOD']=='POST'){ $image = $_POST['image']; $FoodName = $_POST['FoodName']; $FoodLocation = $_POST['FoodLocation']; $ShopName = $_POST['ShopName']; $Type = $_POST['Type']; require_once('dbConnect.php'); $sql ="SELECT id FROM foodstore ORDER BY id ASC"; $res = mysqli_query($con,$sql); $id = 0; while($row = mysqli_fetch_array($res)){ $id = $row['id']; } $path = "images/$id.png"; $actualpath = "http://xyz.ttt.com/$path"; $sql = "INSERT INTO foodstore (image,FoodName,FoodLocation,ShopName,Type) VALUES ('$actualpath','$FoodName','$FoodLocation','$ShopName','$Type')"; if(mysqli_query($con,$sql)){ file_put_contents($path,base64_decode($image)); echo "Successfully Uploaded"; } mysqli_close($con); }else{ echo "Error"; } </code></pre> <p>What is wrong with the above code?</p> </div>

大学四年自学走来,这些私藏的实用工具/学习网站我贡献出来了

大学四年,看课本是不可能一直看课本的了,对于学习,特别是自学,善于搜索网上的一些资源来辅助,还是非常有必要的,下面我就把这几年私藏的各种资源,网站贡献出来给你们。主要有:电子书搜索、实用工具、在线视频学习网站、非视频学习网站、软件下载、面试/求职必备网站。 注意:文中提到的所有资源,文末我都给你整理好了,你们只管拿去,如果觉得不错,转发、分享就是最大的支持了。 一、电子书搜索 对于大部分程序员...

在中国程序员是青春饭吗?

今年,我也32了 ,为了不给大家误导,咨询了猎头、圈内好友,以及年过35岁的几位老程序员……舍了老脸去揭人家伤疤……希望能给大家以帮助,记得帮我点赞哦。 目录: 你以为的人生 一次又一次的伤害 猎头界的真相 如何应对互联网行业的「中年危机」 一、你以为的人生 刚入行时,拿着傲人的工资,想着好好干,以为我们的人生是这样的: 等真到了那一天,你会发现,你的人生很可能是这样的: ...

程序员请照顾好自己,周末病魔差点一套带走我。

程序员在一个周末的时间,得了重病,差点当场去世,还好及时挽救回来了。

技术大佬:我去,你写的 switch 语句也太老土了吧

昨天早上通过远程的方式 review 了两名新来同事的代码,大部分代码都写得很漂亮,严谨的同时注释也很到位,这令我非常满意。但当我看到他们当中有一个人写的 switch 语句时,还是忍不住破口大骂:“我擦,小王,你丫写的 switch 语句也太老土了吧!” 来看看小王写的代码吧,看完不要骂我装逼啊。 private static String createPlayer(PlayerTypes p...

上班一个月,后悔当初着急入职的选择了

最近有个老铁,告诉我说,上班一个月,后悔当初着急入职现在公司了。他之前在美图做手机研发,今年美图那边今年也有一波组织优化调整,他是其中一个,在协商离职后,当时捉急找工作上班,因为有房贷供着,不能没有收入来源。所以匆忙选了一家公司,实际上是一个大型外包公司,主要派遣给其他手机厂商做外包项目。**当时承诺待遇还不错,所以就立马入职去上班了。但是后面入职后,发现薪酬待遇这块并不是HR所说那样,那个HR自...

女程序员,为什么比男程序员少???

昨天看到一档综艺节目,讨论了两个话题:(1)中国学生的数学成绩,平均下来看,会比国外好?为什么?(2)男生的数学成绩,平均下来看,会比女生好?为什么?同时,我又联想到了一个技术圈经常讨...

为什么本科以上学历的人只占中国人口的5%,但感觉遍地都是大学生?

中国大学生占总人口不到5% 2017年,中国整体的本科率仅有5.9%;如果算上研究生,这一比例可以进一步上升到6.5% 为什么在国家统计局推出的这份年鉴中,学历的最高一阶就是到研究生,而没有进一步再统计博士生的数量的。 原因其实并不难理解,相比全国和各省整体人口体量,博士生的占比非常之低,属于绝对意义上的小概率样本。 这一点,我们从上表中的各省研究生占比情况也可以看出端倪。除北京、天津、上海三...

副业收入是我做程序媛的3倍,工作外的B面人生是怎样的?

提到“程序员”,多数人脑海里首先想到的大约是:为人木讷、薪水超高、工作枯燥…… 然而,当离开工作岗位,撕去层层标签,脱下“程序员”这身外套,有的人生动又有趣,马上展现出了完全不同的A/B面人生! 不论是简单的爱好,还是正经的副业,他们都干得同样出色。偶尔,还能和程序员的特质结合,产生奇妙的“化学反应”。 @Charlotte:平日素颜示人,周末美妆博主 大家都以为程序媛也个个不修边幅,但我们也许...

MySQL数据库面试题(2020最新版)

文章目录数据库基础知识为什么要使用数据库什么是SQL?什么是MySQL?数据库三大范式是什么mysql有关权限的表都有哪几个MySQL的binlog有有几种录入格式?分别有什么区别?数据类型mysql有哪些数据类型引擎MySQL存储引擎MyISAM与InnoDB区别MyISAM索引与InnoDB索引的区别?InnoDB引擎的4大特性存储引擎选择索引什么是索引?索引有哪些优缺点?索引使用场景(重点)...

如果你是老板,你会不会踢了这样的员工?

有个好朋友ZS,是技术总监,昨天问我:“有一个老下属,跟了我很多年,做事勤勤恳恳,主动性也很好。但随着公司的发展,他的进步速度,跟不上团队的步伐了,有点...

我入职阿里后,才知道原来简历这么写

私下里,有不少读者问我:“二哥,如何才能写出一份专业的技术简历呢?我总感觉自己写的简历太烂了,所以投了无数份,都石沉大海了。”说实话,我自己好多年没有写过简历了,但我认识的一个同行,他在阿里,给我说了一些他当年写简历的方法论,我感觉太牛逼了,实在是忍不住,就分享了出来,希望能够帮助到你。 01、简历的本质 作为简历的撰写者,你必须要搞清楚一点,简历的本质是什么,它就是为了来销售你的价值主张的。往深...

程序员写出这样的代码,能不挨骂吗?

当你换槽填坑时,面对一个新的环境。能够快速熟练,上手实现业务需求是关键。但是,哪些因素会影响你快速上手呢?是原有代码写的不够好?还是注释写的不够好?昨夜...

外包程序员的幸福生活

今天给你们讲述一个外包程序员的幸福生活。男主是Z哥,不是在外包公司上班的那种,是一名自由职业者,接外包项目自己干。接下来讲的都是真人真事。 先给大家介绍一下男主,Z哥,老程序员,是我十多年前的老同事,技术大牛,当过CTO,也创过业。因为我俩都爱好喝酒、踢球,再加上住的距离不算远,所以一直也断断续续的联系着,我对Z哥的状况也有大概了解。 Z哥几年前创业失败,后来他开始干起了外包,利用自己的技术能...

带了6个月的徒弟当了面试官,而身为高级工程师的我天天修Bug......

即将毕业的应届毕业生一枚,现在只拿到了两家offer,但最近听到一些消息,其中一个offer,我这个组据说客户很少,很有可能整组被裁掉。 想问大家: 如果我刚入职这个组就被裁了怎么办呢? 大家都是什么时候知道自己要被裁了的? 面试软技能指导: BQ/Project/Resume 试听内容: 除了刷题,还有哪些技能是拿到offer不可或缺的要素 如何提升面试软实力:简历, 行为面试,沟通能...

优雅的替换if-else语句

场景 日常开发,if-else语句写的不少吧??当逻辑分支非常多的时候,if-else套了一层又一层,虽然业务功能倒是实现了,但是看起来是真的很不优雅,尤其是对于我这种有强迫症的程序"猿",看到这么多if-else,脑袋瓜子就嗡嗡的,总想着解锁新姿势:干掉过多的if-else!!!本文将介绍三板斧手段: 优先判断条件,条件不满足的,逻辑及时中断返回; 采用策略模式+工厂模式; 结合注解,锦...

离职半年了,老东家又发 offer,回不回?

有小伙伴问松哥这个问题,他在上海某公司,在离职了几个月后,前公司的领导联系到他,希望他能够返聘回去,他很纠结要不要回去? 俗话说好马不吃回头草,但是这个小伙伴既然感到纠结了,我觉得至少说明了两个问题:1.曾经的公司还不错;2.现在的日子也不是很如意。否则应该就不会纠结了。 老实说,松哥之前也有过类似的经历,今天就来和小伙伴们聊聊回头草到底吃不吃。 首先一个基本观点,就是离职了也没必要和老东家弄的苦...

记录下入职中软一个月(外包华为)

我在年前从上一家公司离职,没想到过年期间疫情爆发,我也被困在家里,在家呆着的日子让人很焦躁,于是我疯狂的投简历,看面试题,希望可以进大公司去看看。 我也有幸面试了我觉得还挺大的公司的(虽然不是bat之类的大厂,但是作为一名二本计算机专业刚毕业的大学生bat那些大厂我连投简历的勇气都没有),最后选择了中软,我知道这是一家外包公司,待遇各方面甚至不如我的上一家公司,但是对我而言这可是外包华为,能...

为什么程序员做外包会被瞧不起?

二哥,有个事想询问下您的意见,您觉得应届生值得去外包吗?公司虽然挺大的,中xx,但待遇感觉挺低,马上要报到,挺纠结的。

当HR压你价,说你只值7K,你该怎么回答?

当HR压你价,说你只值7K时,你可以流畅地回答,记住,是流畅,不能犹豫。 礼貌地说:“7K是吗?了解了。嗯~其实我对贵司的面试官印象很好。只不过,现在我的手头上已经有一份11K的offer。来面试,主要也是自己对贵司挺有兴趣的,所以过来看看……”(未完) 这段话主要是陪HR互诈的同时,从公司兴趣,公司职员印象上,都给予对方正面的肯定,既能提升HR的好感度,又能让谈判气氛融洽,为后面的发挥留足空间。...

面试:第十六章:Java中级开发

HashMap底层实现原理,红黑树,B+树,B树的结构原理 Spring的AOP和IOC是什么?它们常见的使用场景有哪些?Spring事务,事务的属性,传播行为,数据库隔离级别 Spring和SpringMVC,MyBatis以及SpringBoot的注解分别有哪些?SpringMVC的工作原理,SpringBoot框架的优点,MyBatis框架的优点 SpringCould组件有哪些,他们...

面试阿里p7,被按在地上摩擦,鬼知道我经历了什么?

面试阿里p7被问到的问题(当时我只知道第一个):@Conditional是做什么的?@Conditional多个条件是什么逻辑关系?条件判断在什么时候执...

Python爬虫,高清美图我全都要(彼岸桌面壁纸)

爬取彼岸桌面网站较为简单,用到了requests、lxml、Beautiful Soup4

无代码时代来临,程序员如何保住饭碗?

编程语言层出不穷,从最初的机器语言到如今2500种以上的高级语言,程序员们大呼“学到头秃”。程序员一边面临编程语言不断推陈出新,一边面临由于许多代码已存在,程序员编写新应用程序时存在重复“搬砖”的现象。 无代码/低代码编程应运而生。无代码/低代码是一种创建应用的方法,它可以让开发者使用最少的编码知识来快速开发应用程序。开发者通过图形界面中,可视化建模来组装和配置应用程序。这样一来,开发者直...

面试了一个 31 岁程序员,让我有所触动,30岁以上的程序员该何去何从?

最近面试了一个31岁8年经验的程序猿,让我有点感慨,大龄程序猿该何去何从。

6年开发经验女程序员,面试京东Java岗要求薪资28K

写在开头: 上周面试了一位女程序员,上午10::30来我们部门面试,2B哥接待了她.来看看她的简历: 个人简历 个人技能: ● 熟悉spring mvc 、spring、mybatis 等框架 ● 熟悉 redis 、rocketmq、dubbo、zookeeper、netty 、nginx、tomcat、mysql。 ● 阅读过juc 中的线程池、锁的源...

大三实习生,字节跳动面经分享,已拿Offer

说实话,自己的算法,我一个不会,太难了吧

程序员垃圾简历长什么样?

已经连续五年参加大厂校招、社招的技术面试工作,简历看的不下于万份 这篇文章会用实例告诉你,什么是差的程序员简历! 疫情快要结束了,各个公司也都开始春招了,作为即将红遍大江南北的新晋UP主,那当然要为小伙伴们做点事(手动狗头)。 就在公众号里公开征简历,义务帮大家看,并一一点评。《启舰:春招在即,义务帮大家看看简历吧》 一石激起千层浪,三天收到两百多封简历。 花光了两个星期的所有空闲时...

Java岗开发3年,公司临时抽查算法,离职后这几题我记一辈子

前几天我们公司做了一件蠢事,非常非常愚蠢的事情。我原以为从学校出来之后,除了找工作有测试外,不会有任何与考试有关的事儿。 但是,天有不测风云,公司技术总监、人事总监两位大佬突然降临到我们事业线,叫上我老大,给我们组织了一场别开生面的“考试”。 那是一个风和日丽的下午,我翘着二郎腿,左手端着一杯卡布奇诺,右手抓着我的罗技鼠标,滚动着轮轴,穿梭在头条热点之间。 “淡黄的长裙~蓬松的头发...

大牛都会用的IDEA调试技巧!!!

导读 前天面试了一个985高校的实习生,问了他平时用什么开发工具,他想也没想的说IDEA,于是我抛砖引玉的问了一下IDEA的调试用过吧,你说说怎么设置断点...

都前后端分离了,咱就别做页面跳转了!统统 JSON 交互

文章目录1. 无状态登录1.1 什么是有状态1.2 什么是无状态1.3 如何实现无状态1.4 各自优缺点2. 登录交互2.1 前后端分离的数据交互2.2 登录成功2.3 登录失败3. 未认证处理方案4. 注销登录 这是本系列的第四篇,有小伙伴找不到之前文章,松哥给大家列一个索引出来: 挖一个大坑,Spring Security 开搞! 松哥手把手带你入门 Spring Security,别再问密...

面试官:你连SSO都不懂,就别来面试了

大厂竟然要考我SSO,卧槽。

97年世界黑客编程大赛冠军作品(大小仅为16KB),惊艳世界的编程巨作

这是世界编程大赛第一名作品(97年Mekka ’97 4K Intro比赛)汇编语言所写。 整个文件只有4095个字节, 大小仅仅为16KB! 不仅实现了3D动画的效果!还有一段震撼人心的背景音乐!!! 内容无法以言语形容,实在太强大! 下面是代码,具体操作看最后! @echo off more +1 %~s0|debug e100 33 f6 bf 0 20 b5 10 f3 a5...

立即提问
相关内容推荐