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 不包含任何字符。为什么这段代码没有运行出结果呢?

1个回答

LayoutInflater.from(context).inflate(R.layout.dialog_view, null) 这样会得到一个新的view, 不是你想要的那个(之前inflate 出来的那个)。
解决办法是:

View  view = builder.setView(LayoutInflater.from(context).inflate(R.layout.dialog_view, null));
final  EditText et = (EditText) view.findViewById(R.id.etxtDialog))
builder.setView(view);
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialog, int which) {
        mInput = et.getText().toString();
    }
});
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
解析EditText.getText().toString()得到的图片
求助各位大神:我在EditText中插入了一张图片,我用edit_text.getText().toString将图片以String形式保存,我怎么把String又转换为图片显示在TextView中呢? ``` SpannableString ss = new SpannableString(imagePath); Pattern p=Pattern.compile("/mnt/sdcard/.+?\\.\\w{3}"); Matcher m=p.matcher(imagePath); while(m.find()){ Bitmap bm = BitmapFactory.decodeFile(m.group()); Bitmap rbm = r.resizeImage(bm, 100, 100); ImageSpan span = new ImageSpan(this, rbm); ss.setSpan(span, m.start(), m.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } Editable edit_text = display.getEditableText(); edit_text.append(ss); ``` 这样做只能得到路径格式的字符串。怎么让图片再显示出来呢?
怎么让焦点显示在数字的右边
![图片说明](https://img-ask.csdn.net/upload/201704/14/1492119486_773564.jpg) ![图片说明](https://img-ask.csdn.net/upload/201704/14/1492119505_494862.jpg) ``` package com.example.calculate; 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.EditText; public class Calculate extends Activity implements OnClickListener { Button btn0; Button btn1; Button btn2; Button btn3; Button btn4; Button btn5; Button btn6; Button btn7; Button btn8; Button btn9; Button btnAdd; Button btnSub; Button btnPoint; Button btnMul; Button btnDiv; Button btnEqu; Button btnCE; EditText editText; String Symbol; double firnum; double secnum; double res; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_calculate); btn0=(Button)findViewById(R.id.btn0); btn1=(Button)findViewById(R.id.btn1); btn2=(Button)findViewById(R.id.btn2); btn3=(Button)findViewById(R.id.btn3); btn4=(Button)findViewById(R.id.btn4); btn5=(Button)findViewById(R.id.btn5); btn6=(Button)findViewById(R.id.btn6); btn7=(Button)findViewById(R.id.btn7); btn8=(Button)findViewById(R.id.btn8); btn9=(Button)findViewById(R.id.btn9); btnSub=(Button)findViewById(R.id.btnSub); btnAdd=(Button)findViewById(R.id.btnAdd); ; btnPoint=(Button)findViewById(R.id.btnPoint); btnMul=(Button)findViewById(R.id.btnMul); btnDiv=(Button)findViewById(R.id.btnDiv); btnEqu=(Button)findViewById(R.id.btnEqu); btnCE=(Button)findViewById(R.id.btnCE); editText=(EditText)findViewById(R.id.editText); btn0.setOnClickListener(this); btn1.setOnClickListener(this); btn2.setOnClickListener(this); btn3.setOnClickListener(this); btn4.setOnClickListener(this); btn5.setOnClickListener(this); btn6.setOnClickListener(this); btn7.setOnClickListener(this); btn8.setOnClickListener(this); btn9.setOnClickListener(this); btnAdd.setOnClickListener(this); btnDiv.setOnClickListener(this); btnPoint.setOnClickListener(this); btnSub.setOnClickListener(this); btnMul.setOnClickListener(this); btnEqu.setOnClickListener(this); btnCE.setOnClickListener(this); } public void onClick(View v){ switch(v.getId()){ case R.id.btn0: editText.setText(editText.getText()+"0"); break; case R.id.btn1: editText.setText(editText.getText()+"1"); break; case R.id.btn2: editText.setText(editText.getText()+"2"); break; case R.id.btn3: editText.setText(editText.getText()+"3"); break; case R.id.btn4: editText.setText(editText.getText()+"4"); break; case R.id.btn5: editText.setText(editText.getText()+"5"); break; case R.id.btn6: editText.setText(editText.getText()+"6"); break; case R.id.btn7: editText.setText(editText.getText()+"7"); break; case R.id.btn8: editText.setText(editText.getText()+"8"); break; case R.id.btn9: editText.setText(editText.getText()+"9"); break; case R.id.btnPoint: editText.setText(editText.getText()+"."); break; case R.id.btnAdd: Symbol="+"; firnum=Double.valueOf(editText.getText().toString()); editText.setText(""); break; case R.id.btnSub: Symbol="-"; firnum= Double.valueOf(editText.getText().toString()); editText.setText(""); break; case R.id.btnMul: Symbol="*"; firnum=Double.valueOf(editText.getText().toString()); editText.setText(""); break; case R.id.btnDiv: Symbol="/"; firnum= Double.valueOf(editText.getText().toString()); editText.setText(""); break; case R.id.btnCE: editText.setText(""); break; case R.id.btnEqu: secnum=Double.valueOf(editText.getText().toString()); if (Symbol=="+"){ res=firnum+secnum; } if (Symbol=="-"){ res=firnum-secnum; } if (Symbol=="*") { res = firnum * secnum; } if (Symbol=="/") { res = firnum / secnum; } editText.setText(res+" "); } } @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); } } ```
从EditText中获取单个字符
String PT = pt.getText().toString(); int len = PT.length(); char chars[] = PT.toCharArray(); for(int i=0;i<len;i++) { Toast.makeText(encrypt.this,chars[i], 0).show(); } 这段代码是用在EditText中读取字符串,获取单个字符的。但是结果出了一个logcat错误信息: 11-28 12:41:01.228: E/AndroidRuntime(1632): at android.app.ActivityThread.main(ActivityThread.java:3683) 11-28 12:41:01.228: E/AndroidRuntime(1632): at java.lang.reflect.Method.invokeNative(Native Method) 11-28 12:41:01.228: E/AndroidRuntime(1632): at java.lang.reflect.Method.invoke(Method.java:507) 11-28 12:41:01.228: E/AndroidRuntime(1632): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 11-28 12:41:01.228: E/AndroidRuntime(1632): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 11-28 12:41:01.228: E/AndroidRuntime(1632): at dalvik.system.NativeStart.main(Native Method) 11-28 12:46:43.688: W/KeyCharacterMap(1674): No keyboard for id 0 11-28 12:46:43.688: W/KeyCharacterMap(1674): Using default keymap: /system/usr/keychars/qwerty.kcm.bin 11-28 12:46:54.442: W/ResourceType(1674): No package identifier when getting value for resource number 0x00000061 11-28 12:46:54.448: D/AndroidRuntime(1674): Shutting down VM 11-28 12:46:54.448: W/dalvikvm(1674): threadid=1: thread exiting with uncaught exception (group=0x40015560) 11-28 12:46:54.459: E/AndroidRuntime(1674): FATAL EXCEPTION: main 11-28 12:46:54.459: E/AndroidRuntime(1674): android.content.res.Resources$NotFoundException: String resource ID #0x61 11-28 12:46:54.459: E/AndroidRuntime(1674): at android.content.res.Resources.getText(Resources.java:201) 11-28 12:46:54.459: E/AndroidRuntime(1674): at android.widget.Toast.makeText(Toast.java:258) 11-28 12:46:54.459: E/AndroidRuntime(1674): at com.project.DENCrypt.encrypt$1.onClick(encrypt.java:33) 11-28 12:46:54.459: E/AndroidRuntime(1674): at android.view.View.performClick(View.java:2485) 11-28 12:46:54.459: E/AndroidRuntime(1674): at android.view.View$PerformClick.run(View.java:9080) 11-28 12:46:54.459: E/AndroidRuntime(1674): at android.os.Handler.handleCallback(Handler.java:587) 11-28 12:46:54.459: E/AndroidRuntime(1674): at android.os.Handler.dispatchMessage(Handler.java:92) 11-28 12:46:54.459: E/AndroidRuntime(1674): at android.os.Looper.loop(Looper.java:123) 11-28 12:46:54.459: E/AndroidRuntime(1674): at android.app.ActivityThread.main(ActivityThread.java:3683) 11-28 12:46:54.459: E/AndroidRuntime(1674): at java.lang.reflect.Method.invokeNative(Native Method) 11-28 12:46:54.459: E/AndroidRuntime(1674): at java.lang.reflect.Method.invoke(Method.java:507) 11-28 12:46:54.459: E/AndroidRuntime(1674): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 11-28 12:46:54.459: E/AndroidRuntime(1674): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 11-28 12:46:54.459: E/AndroidRuntime(1674): at dalvik.system.NativeStart.main(Native Method)
Android提示错误:on a null object reference
我是在button的onclick里写的用的swith,一按按钮就崩溃,后来捕捉错误为 Attempt to invoke virtual method 'android.text.Editable android.widget.EditText.getText()' on a null object reference 但是我et应该有值啊,不理解 case R.id.next: EditText et = (EditText) v.findViewById(R.id.number); try { System.out.println(et.getText().toString());//这句话报错 } catch (Exception ex) { System.out.println("Error :" + ex.getMessage()); } break;
android中出现ActivityNotFoundException异常
自己编的程序出现了异常数值总传不过去是怎么回事? ``` String num=editText.getText().toString(); num=num.trim(); Intent numIntent=new Intent(); numIntent.putExtra("num",num); startActivityForResult(numIntent,NUMVALUE); ``` 这个是按钮的监听事件。 ``` case NUMVALUE: String guessNum=intent.getStringExtra("num"); System.out.println(guessNum); int guessNumber=Integer.parseInt(guessNum); ``` 这个事onActivityResult方法接收数据的代码,但是总是传不过去是怎么回事? 异常如下: 07-30 14:25:39.328: E/AndroidRuntime(678): FATAL EXCEPTION: main 07-30 14:25:39.328: E/AndroidRuntime(678): android.content.ActivityNotFoundException: No Activity found to handle Intent { (has extras) } 07-30 14:25:39.328: E/AndroidRuntime(678): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1409) 07-30 14:25:39.328: E/AndroidRuntime(678): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1379) 07-30 14:25:39.328: E/AndroidRuntime(678): at android.app.Activity.startActivityForResult(Activity.java:2827) 07-30 14:25:39.328: E/AndroidRuntime(678): at com.example.smallgames.GuessActivity$1.onClick(GuessActivity.java:69) 07-30 14:25:39.328: E/AndroidRuntime(678): at android.view.View.performClick(View.java:2485) 07-30 14:25:39.328: E/AndroidRuntime(678): at android.view.View$PerformClick.run(View.java:9080) 07-30 14:25:39.328: E/AndroidRuntime(678): at android.os.Handler.handleCallback(Handler.java:587) 07-30 14:25:39.328: E/AndroidRuntime(678): at android.os.Handler.dispatchMessage(Handler.java:92) 07-30 14:25:39.328: E/AndroidRuntime(678): at android.os.Looper.loop(Looper.java:123) 07-30 14:25:39.328: E/AndroidRuntime(678): at android.app.ActivityThread.main(ActivityThread.java:3683) 07-30 14:25:39.328: E/AndroidRuntime(678): at java.lang.reflect.Method.invokeNative(Native Method) 07-30 14:25:39.328: E/AndroidRuntime(678): at java.lang.reflect.Method.invoke(Method.java:507) 07-30 14:25:39.328: E/AndroidRuntime(678): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 07-30 14:25:39.328: E/AndroidRuntime(678): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 07-30 14:25:39.328: E/AndroidRuntime(678): at dalvik.system.NativeStart.main(Native Method) 求大神指点呀!!!
Android小白,请各位大佬帮忙看看什么问题,一个关于摄氏华氏转换的小小小程序
做一个摄氏华氏转换的时候,在模拟器上运行有这样的问题 java程序 public class MainActivity extends ActionBarActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void button1_click(View view){ int c; double f; EditText txtc=(EditText) findViewById(R.id.txtc); EditText txtf=(EditText) findViewById(R.id.txtf); c=Integer.parseInt(txtc.getText().toString()); f=(9.0*c)/5.0+32.0; txtf.setText(String.valueOf(f)); } } 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" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.example.ftoc.MainActivity" > <TableRow > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/c" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/equals"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/f" /> </TableRow> <TableRow > <EditText android:id="@+id/txtc" android:layout_width="100dp" android:layout_height="wrap_content" android:inputType="number"/> <Button android:id="@+id/button1" android:text="@string/shift" android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="button1_Click"/> <EditText android:id="@+id/txtf" android:layout_width="100dp" android:layout_height="wrap_content" android:inputType="numberDecimal"/> </TableRow> </RelativeLayout> log猫 10-04 03:31:06.777: E/AndroidRuntime(913): at android.support.v7.app.ActionBarActivityDelegateBase.setContentView(ActionBarActivityDelegateBase.java:228) 10-04 03:31:06.777: E/AndroidRuntime(913): at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:102) 10-04 03:31:06.777: E/AndroidRuntime(913): at com.example.ftoc.MainActivity.onCreate(MainActivity.java:16) 10-04 03:31:06.777: E/AndroidRuntime(913): at android.app.Activity.performCreate(Activity.java:5933) 10-04 03:31:06.777: E/AndroidRuntime(913): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105) 10-04 03:31:06.777: E/AndroidRuntime(913): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251) 10-04 03:31:06.777: E/AndroidRuntime(913): ... 10 more 10-04 03:31:10.772: I/Process(913): Sending signal. PID: 913 SIG: 9 10-04 04:06:59.931: D/AndroidRuntime(1228): Shutting down VM 10-04 04:06:59.936: E/AndroidRuntime(1228): FATAL EXCEPTION: main 10-04 04:06:59.936: E/AndroidRuntime(1228): Process: com.example.ftoc, PID: 1228 10-04 04:06:59.936: E/AndroidRuntime(1228): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.ftoc/com.example.ftoc.MainActivity}: java.lang.RuntimeException: Binary XML file line #10: You must supply a layout_width attribute. 10-04 04:06:59.936: E/AndroidRuntime(1228): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298) 10-04 04:06:59.936: E/AndroidRuntime(1228): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360) 10-04 04:06:59.936: E/AndroidRuntime(1228): at android.app.ActivityThread.access$800(ActivityThread.java:144) 10-04 04:06:59.936: E/AndroidRuntime(1228): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278) 10-04 04:06:59.936: E/AndroidRuntime(1228): at android.os.Handler.dispatchMessage(Handler.java:102) 10-04 04:06:59.936: E/AndroidRuntime(1228): at android.os.Looper.loop(Looper.java:135) 10-04 04:06:59.936: E/AndroidRuntime(1228): at android.app.ActivityThread.main(ActivityThread.java:5221) 10-04 04:06:59.936: E/AndroidRuntime(1228): at java.lang.reflect.Method.invoke(Native Method) 10-04 04:06:59.936: E/AndroidRuntime(1228): at java.lang.reflect.Method.invoke(Method.java:372) 10-04 04:06:59.936: E/AndroidRuntime(1228): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899) 10-04 04:06:59.936: E/AndroidRuntime(1228): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694) 。。。。。。。。
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 求大神指点一下这个问题???
Android下面代码运行时候报错,仔细核对了控件名,没有问题,求各位大神帮忙看看
button_user_alert.setOnClickListener(new OnClickListener() { View view = View.inflate(DialogComponentTest.this, R.layout.user_dialog, null); final EditText userName = (EditText) findViewById(R.id.edit_text_name); final EditText passWord = (EditText) findViewById(R.id.edit_text_password); @Override public void onClick(View v) { new AlertDialog.Builder(DialogComponentTest.this) .setView(view) .setPositiveButton("取消", null) .setNegativeButton("确定", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { //这里出现nullPointerException,不知道该怎么处理,找不出问题所在 String strUserName = userName.getText().toString(); String strPassWord = passWord.getText().toString(); Toast.makeText(DialogComponentTest.this,strUserName +" : "+strPassWord, 0).show(); } }) .show(); } }); 错误信息如下: 01-13 13:41:16.472: E/SurfaceFlinger(794): ro.sf.lcd_density must be defined as a build property 01-13 13:41:20.792: E/SurfaceFlinger(794): ro.sf.lcd_density must be defined as a build property 01-13 13:41:27.512: E/AndroidRuntime(1878): FATAL EXCEPTION: main 01-13 13:41:27.512: E/AndroidRuntime(1878): java.lang.NullPointerException 01-13 13:41:27.512: E/AndroidRuntime(1878): at com.example.uitest.DialogComponentTest$3$1.onClick(DialogComponentTest.java:97) 01-13 13:41:27.512: E/AndroidRuntime(1878): at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:166) 01-13 13:41:27.512: E/AndroidRuntime(1878): at android.os.Handler.dispatchMessage(Handler.java:99) 01-13 13:41:27.512: E/AndroidRuntime(1878): at android.os.Looper.loop(Looper.java:137) 01-13 13:41:27.512: E/AndroidRuntime(1878): at android.app.ActivityThread.main(ActivityThread.java:5041) 01-13 13:41:27.512: E/AndroidRuntime(1878): at java.lang.reflect.Method.invokeNative(Native Method) 01-13 13:41:27.512: E/AndroidRuntime(1878): at java.lang.reflect.Method.invoke(Method.java:511) 01-13 13:41:27.512: E/AndroidRuntime(1878): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 01-13 13:41:27.512: E/AndroidRuntime(1878): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 01-13 13:41:27.512: E/AndroidRuntime(1878): at dalvik.system.NativeStart.main(Native Method) 01-13 13:41:27.572: E/SurfaceFlinger(794): ro.sf.lcd_density must be defined as a build property 01-13 13:41:29.352: E/Trace(1899): error opening trace file: No such file or directory (2) 01-13 13:41:29.383: E/SurfaceFlinger(794): ro.sf.lcd_density must be defined as a build property 01-13 13:41:29.393: E/SurfaceFlinger(794): ro.sf.lcd_density must be defined as a build property
请问%的怎么实现.在网上找了好多案例,就是不能实现
代码写的比较渣,勿吐槽,新手写了一个星期 基本功能是可以实现的,就是百分号那个真的没法实现,有会的大神麻烦教下 public class MainActivity extends Activity implements View.OnClickListener { /* 利用数组装变量,并创建button数组存放相应的变量 */ private int[] btn = {R.id.zero, R.id.one, R.id.two, R.id.three, R.id.four, R.id.five, R.id.six, R.id.seven, R.id.eight, R.id.nine}; private Button[] bnum = new Button[btn.length]; private int[] takes = {R.id.jia, R.id.jian, R.id.cheng, R.id.chu}; private Button[] take = new Button[takes.length]; private int[] btc = {R.id.dot, R.id.zf, R.id.xc, R.id.qc, R.id.tg, R.id.bai, R.id.lf, R.id.pf, R.id.fen, R.id.sum}; private Button[] btcl = new Button[btc.length]; private EditText editText; boolean clear_flag; //用于:当已经运算出结果的时候,我们再次点击数字按钮的时候,清空屏幕的作用! private String opt; //加减乘除通用变量 double num1, num2; //第一个值,第二个值 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //获取输入框 editText = (EditText) findViewById(R.id.edittext); //输入框复制空字符串 editText.setText(""); //输入框不能够输入,只能接收按钮点击事件 editText.setEnabled(false); //利用循环遍历给每个button分类进行实例化并实现OnClickListener接口 for (int i = 0; i < btn.length; i++) { bnum[i] = (Button) findViewById(btn[i]); bnum[i].setOnClickListener(this); } for (int i = 0; i < takes.length; i++) { take[i] = (Button) findViewById(takes[i]); take[i].setOnClickListener(this); } for (int i = 0; i < btc.length; i++) { btcl[i] = (Button) findViewById(btc[i]); btcl[i].setOnClickListener(this); } } @Override public void onClick(View v) { String str = editText.getText().toString(); //获取当前edittext的内容 //利用switch多分支语句 switch (v.getId()) { case R.id.zero: case R.id.one: case R.id.two: case R.id.three: case R.id.four: case R.id.five: case R.id.six: case R.id.seven: case R.id.eight: case R.id.nine: case R.id.dot: if (clear_flag) { clear_flag = false; str = ""; editText.setText(""); } editText.setText(str + ((Button) v).getText()); break; //加法 case R.id.jia: { if (!TextUtils.isEmpty(str)) { String str1 = editText.getText().toString(); num1 = Double.parseDouble(str1); opt = "+"; editText.setText(opt); break; } } //减法 case R.id.jian: { if (!TextUtils.isEmpty(str)) { String str1 = editText.getText().toString(); num1 = Double.parseDouble(str1); opt = "-"; editText.setText(opt); break; } } //乘法 case R.id.cheng: { if (!TextUtils.isEmpty(str)) { String str1 = editText.getText().toString(); num1 = Double.parseDouble(str1); opt = "*"; editText.setText(opt); break; } } //除法 case R.id.chu: { if (!TextUtils.isEmpty(str)) { String str1 = editText.getText().toString(); num1 = Double.parseDouble(str1); opt = "/"; editText.setText(opt); break; } } //消除 与清除一个功能 case R.id.xc: clear_flag = false; editText.setText(""); break; //退格键 case R.id.tg: if (clear_flag) { clear_flag = false; editText.setText(""); } else if (str != null && !str.equals("")) { editText.setText(str.substring(0, str.length() - 1)); } break; //清除 与消除一个功能 case R.id.qc: Toast toast = Toast.makeText(this, "与消除功能一样", Toast.LENGTH_SHORT); toast.show(); //根计算 case R.id.lf: if (!TextUtils.isEmpty(str)) { String str1 = editText.getText().toString(); num1 = Double.parseDouble(str); if (num1 < 0) { editText.setText("负数没有平方根"); } else { editText.setText(Math.sqrt(num1) + ""); } break; } //正负计算 case R.id.zf: if (!TextUtils.isEmpty(str)) { String str1 = editText.getText().toString(); num1 = Double.parseDouble(str1); if (str.length() > 0) editText.setText(-num1 + ""); break; } case R.id.bai: if (!TextUtils.isEmpty(str)) { } //平方计算 case R.id.pf: if (!TextUtils.isEmpty(str)) { String str1 = editText.getText().toString(); num1 = Double.parseDouble(str1); editText.setText(String.valueOf(num1 * num1)); } // 1/x计算 case R.id.fen: if (!TextUtils.isEmpty(str)) { String str1 = editText.getText().toString(); num1 = Double.parseDouble(str1); editText.setText(String.valueOf(1 / num1)); } case R.id.sum: if (opt == "+") { String str1 = editText.getText().toString(); num2 = Double.parseDouble(str); editText.setText(String.valueOf(num1 + num2)); } else if (opt == "-") { String str1 = editText.getText().toString(); //获取输入框的值 str = str.substring(1); num2 = Double.parseDouble(str); editText.setText(String.valueOf(num1 - num2)); } else if (opt == "*") { String str1 = editText.getText().toString(); str = str.substring(1); num2 = Double.parseDouble(str); editText.setText(String.valueOf(num1 * num2)); } else if (opt == "/") { String str1 = editText.getText().toString(); str = str.substring(1); num2 = Double.parseDouble(str); editText.setText(String.valueOf(num1 / num2)); } break; } } }
android为什么我照样画葫芦总是会出错!!想不通~~高手帮忙
logcat如下: 08-23 14:32:32.586: W/KeyCharacterMap(335): No keyboard for id 0 08-23 14:32:32.586: W/KeyCharacterMap(335): Using default keymap: /system/usr/keychars/qwerty.kcm.bin 08-23 14:32:41.207: D/AndroidRuntime(335): Shutting down VM 08-23 14:32:41.207: W/dalvikvm(335): threadid=1: thread exiting with uncaught exception (group=0x40015560) 08-23 14:32:41.227: E/AndroidRuntime(335): FATAL EXCEPTION: main 08-23 14:32:41.227: E/AndroidRuntime(335): java.lang.ClassCastException: android.widget.Button 08-23 14:32:41.227: E/AndroidRuntime(335): at com.example.android_4_2.MainActivity$1.onClick(MainActivity.java:28) 08-23 14:32:41.227: E/AndroidRuntime(335): at android.view.View.performClick(View.java:2485) 08-23 14:32:41.227: E/AndroidRuntime(335): at android.view.View$PerformClick.run(View.java:9080) 08-23 14:32:41.227: E/AndroidRuntime(335): at android.os.Handler.handleCallback(Handler.java:587) 08-23 14:32:41.227: E/AndroidRuntime(335): at android.os.Handler.dispatchMessage(Handler.java:92) 08-23 14:32:41.227: E/AndroidRuntime(335): at android.os.Looper.loop(Looper.java:123) 08-23 14:32:41.227: E/AndroidRuntime(335): at android.app.ActivityThread.main(ActivityThread.java:3683) 08-23 14:32:41.227: E/AndroidRuntime(335): at java.lang.reflect.Method.invokeNative(Native Method) 08-23 14:32:41.227: E/AndroidRuntime(335): at java.lang.reflect.Method.invoke(Method.java:507) 08-23 14:32:41.227: E/AndroidRuntime(335): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 08-23 14:32:41.227: E/AndroidRuntime(335): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 08-23 14:32:41.227: E/AndroidRuntime(335): at dalvik.system.NativeStart.main(Native Method) 代码如下: import android.net.Uri; import android.os.Bundle; import android.R.string; import android.app.Activity; import android.content.Intent; import android.telephony.PhoneNumberUtils; import android.view.Menu; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button bCall = (Button)findViewById(R.id.TelBtn); bCall.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { // TODO 自动生成的方法存根 EditText telnum =(EditText)findViewById(R.id.TelBtn); String telNum = telnum.getText().toString(); if (PhoneNumberUtils.isGlobalPhoneNumber(telNum)) { Intent i = new Intent(Intent.ACTION_DIAL,Uri.parse( "tel://"+telNum)); MainActivity.this.startActivity(i); } else { Toast.makeText(MainActivity.this, "号码不正确", 5000).show(); } } } ); } 真的要把我弄疯了。。这让怎么学习啊~!希望大家帮忙,万分感谢。。
百分号怎么实现,求大手指导,网上的案例都试过了
代码如下: public class MainActivity extends Activity implements View.OnClickListener { /* 利用数组装变量,并创建button数组存放相应的变量 */ private int[] btn = {R.id.zero, R.id.one, R.id.two, R.id.three, R.id.four, R.id.five, R.id.six, R.id.seven, R.id.eight, R.id.nine}; private Button[] bnum = new Button[btn.length]; private int[] takes = {R.id.jia, R.id.jian, R.id.cheng, R.id.chu}; private Button[] take = new Button[takes.length]; private int[] btc = {R.id.dot, R.id.zf, R.id.xc, R.id.qc, R.id.tg, R.id.bai, R.id.lf, R.id.pf, R.id.fen, R.id.sum}; private Button[] btcl = new Button[btc.length]; private EditText editText; boolean clear_flag; //用于:当已经运算出结果的时候,我们再次点击数字按钮的时候,清空屏幕的作用! private String opt; //加减乘除通用变量 double num1, num2; //第一个值,第二个值 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //获取输入框 editText = (EditText) findViewById(R.id.edittext); //输入框复制空字符串 editText.setText(""); //输入框不能够输入,只能接收按钮点击事件 editText.setEnabled(false); //利用循环遍历给每个button分类进行实例化并实现OnClickListener接口 for (int i = 0; i < btn.length; i++) { bnum[i] = (Button) findViewById(btn[i]); bnum[i].setOnClickListener(this); } for (int i = 0; i < takes.length; i++) { take[i] = (Button) findViewById(takes[i]); take[i].setOnClickListener(this); } for (int i = 0; i < btc.length; i++) { btcl[i] = (Button) findViewById(btc[i]); btcl[i].setOnClickListener(this); } } @Override public void onClick(View v) { String str = editText.getText().toString(); //获取当前edittext的内容 //利用switch多分支语句 switch (v.getId()) { case R.id.zero: case R.id.one: case R.id.two: case R.id.three: case R.id.four: case R.id.five: case R.id.six: case R.id.seven: case R.id.eight: case R.id.nine: case R.id.dot: if (clear_flag) { clear_flag = false; str = ""; editText.setText(""); } editText.setText(str + ((Button) v).getText()); break; //加法 case R.id.jia: { if (!TextUtils.isEmpty(str)) { String str1 = editText.getText().toString(); num1 = Double.parseDouble(str1); opt = "+"; editText.setText(opt); break; } } //减法 case R.id.jian: { if (!TextUtils.isEmpty(str)) { String str1 = editText.getText().toString(); num1 = Double.parseDouble(str1); opt = "-"; editText.setText(opt); break; } } //乘法 case R.id.cheng: { if (!TextUtils.isEmpty(str)) { String str1 = editText.getText().toString(); num1 = Double.parseDouble(str1); opt = "*"; editText.setText(opt); break; } } //除法 case R.id.chu: { if (!TextUtils.isEmpty(str)) { String str1 = editText.getText().toString(); num1 = Double.parseDouble(str1); opt = "/"; editText.setText(opt); break; } } //消除 与清除一个功能 case R.id.xc: clear_flag = false; editText.setText(""); break; //退格键 case R.id.tg: if (clear_flag) { clear_flag = false; editText.setText(""); } else if (str != null && !str.equals("")) { editText.setText(str.substring(0, str.length() - 1)); } break; //清除 与消除一个功能 case R.id.qc: Toast toast = Toast.makeText(this, "与消除功能一样", Toast.LENGTH_SHORT); toast.show(); //根计算 case R.id.lf: if (!TextUtils.isEmpty(str)) { String str1 = editText.getText().toString(); num1 = Double.parseDouble(str); if (num1 < 0) { editText.setText("负数没有平方根"); } else { editText.setText(Math.sqrt(num1) + ""); } break; } //正负计算 case R.id.zf: if (!TextUtils.isEmpty(str)) { String str1 = editText.getText().toString(); num1 = Double.parseDouble(str1); if (str.length() > 0) editText.setText(-num1 + ""); break; } case R.id.bai: if (!TextUtils.isEmpty(str)) { } //平方计算 case R.id.pf: if (!TextUtils.isEmpty(str)) { String str1 = editText.getText().toString(); num1 = Double.parseDouble(str1); editText.setText(String.valueOf(num1 * num1)); } // 1/x计算 case R.id.fen: if (!TextUtils.isEmpty(str)) { String str1 = editText.getText().toString(); num1 = Double.parseDouble(str1); editText.setText(String.valueOf(1 / num1)); } case R.id.sum: if (opt == "+") { String str1 = editText.getText().toString(); num2 = Double.parseDouble(str); editText.setText(String.valueOf(num1 + num2)); } else if (opt == "-") { String str1 = editText.getText().toString(); //获取输入框的值 str = str.substring(1); num2 = Double.parseDouble(str); editText.setText(String.valueOf(num1 - num2)); } else if (opt == "*") { String str1 = editText.getText().toString(); str = str.substring(1); num2 = Double.parseDouble(str); editText.setText(String.valueOf(num1 * num2)); } else if (opt == "/") { String str1 = editText.getText().toString(); str = str.substring(1); num2 = Double.parseDouble(str); editText.setText(String.valueOf(num1 / num2)); } break; } } }
简单写了一个Android计算器,事件处理代码一团糟,该如何优化?
大家好: 刚刚开始学习Android开发,写了一个简单的计算器,主要是为了熟悉界面布局和事件处理。我写的代码很蠢,在一个主Activity中,一个按钮添加一个事件,请问有什么好的模式可以优化一下这种代码,谢谢! [code="java"]package com.wondershare.calculator; import android.app.Activity; import android.os.Bundle; import android.text.Editable; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; public class Calculator extends Activity { private String number1 = null; private String number2 = null; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); final EditText editText = (EditText) findViewById(R.id.editText); Button del = (Button) findViewById(R.id.del); del.setOnClickListener(new OnClickListener() { //有问题 @Override public void onClick(View v) { // Editable str = editText.getText(); // if(!str.equals("")){ // int length = str.length(); // str.delete(length-1, length); // editText.setText(str); // } editText.getText().clear(); } }); final Button digit0 = (Button) findViewById(R.id.digit0); digit0.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { String str = (String) digit0.getText(); if (str.equals("")) { } else { editText.append(digit0.getText()); } } }); final Button digit1 = (Button) findViewById(R.id.digit1); digit1.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { editText.append(digit1.getText()); } }); final Button digit2 = (Button) findViewById(R.id.digit2); digit2.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { editText.append(digit2.getText()); } }); final Button digit3 = (Button) findViewById(R.id.digit3); digit3.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { editText.append(digit3.getText()); } }); final Button digit4 = (Button) findViewById(R.id.digit4); digit4.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { editText.append(digit4.getText()); } }); final Button digit5 = (Button) findViewById(R.id.digit5); digit5.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { editText.append(digit5.getText()); } }); final Button digit6 = (Button) findViewById(R.id.digit6); digit6.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { editText.append(digit6.getText()); } }); final Button digit7 = (Button) findViewById(R.id.digit7); digit7.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { editText.append(digit7.getText()); } }); final Button digit8 = (Button) findViewById(R.id.digit8); digit8.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { editText.append(digit8.getText()); } }); final Button digit9 = (Button) findViewById(R.id.digit9); digit9.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { editText.append(digit9.getText()); } }); final Button div = (Button) findViewById(R.id.div); div.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { number1 = editText.getText().toString(); editText.append(div.getText()); } }); final Button dot = (Button) findViewById(R.id.dot); dot.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { editText.append(dot.getText()); } }); final Button equal = (Button) findViewById(R.id.equal); equal.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { String str = editText.getText().toString();//文本 number2 = str.substring(number1.length()+1, str.length()); String operation = str.substring(number1.length(), number1.length()+1); float result = 0; if(operation.equals("+")){ result = Float.parseFloat(number1)+Float.parseFloat(number2); }else if(operation.equals("-")){ result = Float.parseFloat(number1)-Float.parseFloat(number2); }else if(operation.equals("×")){ result = Float.parseFloat(number1)*Float.parseFloat(number2); }else if(operation.equals("/")){ result = Float.parseFloat(number1)/Float.parseFloat(number2); } editText.setText(String.valueOf(result)); } }); final Button minus = (Button) findViewById(R.id.minus); minus.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { number1 = editText.getText().toString(); editText.append(minus.getText()); } }); final Button mul = (Button) findViewById(R.id.mul); mul.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { number1 = editText.getText().toString(); editText.append(mul.getText()); } }); final Button plus = (Button) findViewById(R.id.plus); plus.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { //保存第一个操作数 number1 = editText.getText().toString(); editText.append(plus.getText()); } }); } }[/code]
Geocode 没有返回值的问题
我想把地址转换成long和纬度型,但是它返回0。请大家帮我看看错误出现在哪里? 代码如下: geocoder = new Geocoder(this); buttonSave.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { try { EditText loc = (EditText)findViewById(R.id.txtAddress); String locationName = loc.getText().toString(); List<Address> addressList = geocoder.getFromLocationName(locationName, 2); if(addressList!=null && addressList.size()>0) { lat = (int)(addressList.get(0).getLatitude()*1000000); lng = (int)(addressList.get(0).getLongitude()*1000000); } } catch (IOException e) { e.printStackTrace(); } lattitude = Integer.toString(lat); longertude = Integer.toString(lng); LOGCAT: 06-10 13:44:28.799: I/System.out(274): [INFO:19529614]: LogSource: Running flush 06-10 13:44:28.799: I/System.out(274): [INFO:19529623]: LogSource: Sending payload [bytes=267] 06-10 13:44:32.262: D/SntpClient(83): request time failed: java.net.SocketException: Address family not supported by protocol 06-10 13:44:33.809: I/System.out(274): [INFO:19534623]: LogSource: Running delayed flush 06-10 13:44:33.809: W/System.err(2517): java.io.IOException: Unable to parse response from server 06-10 13:44:33.823: I/System.out(274): [INFO:19534640]: LogSource: Running flush 06-10 13:44:33.829: I/System.out(274): [INFO:19534651]: LogSource: Sending payload [bytes=267] 06-10 13:44:33.869: W/System.err(2517): at android.location.Geocoder.getFromLocationName(Geocoder.java:178) 06-10 13:44:33.869: W/System.err(2517): at de.vogella.android.locationapi.simple.InsertStock$1.onClick(InsertStock.java:108) 06-10 13:44:33.879: W/System.err(2517): at android.view.View.performClick(View.java:3110) 06-10 13:44:33.891: W/System.err(2517): at android.view.View$PerformClick.run(View.java:11928) 06-10 13:44:33.899: W/System.err(2517): at android.os.Handler.handleCallback(Handler.java:587) 06-10 13:44:33.899: W/System.err(2517): at android.os.Handler.dispatchMessage(Handler.java:92) 06-10 13:44:33.899: W/System.err(2517): at android.os.Looper.loop(Looper.java:132) 06-10 13:44:33.913: W/System.err(2517): at android.app.ActivityThread.main(ActivityThread.java:4025) 06-10 13:44:33.919: W/System.err(2517): at java.lang.reflect.Method.invokeNative(Native Method) 06-10 13:44:33.939: W/System.err(2517): at java.lang.reflect.Method.invoke(Method.java:491) 06-10 13:44:33.939: W/System.err(2517): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841) 06-10 13:44:33.939: W/System.err(2517): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599) 06-10 13:44:33.939: W/System.err(2517): at dalvik.system.NativeStart.main(Native Method)
安卓让关键字变色 如何控制?
Spanned str = Html.fromHtml(s.replace(edittext.getText.toString, "<font color=#00FF00>" + edittext.getText.toString + "</font>")); 这是我之前实现的方法把字符串s中含有输入的关键字的字符替换成红色,现在有一个新的要求就是比如查询到的ID有一个 3和3530 输入3的时候3变色 3530 中的第一个3变色这样类推~~求指导
onCreateDialog 中的 EditText
在程序中通过 longCLick 创建了AlertDialog @Override protected Dialog onCreateDialog(int id) { switch (id) { case DIALOG_TEXT_ENTRY: // This example shows how to add a custom layout to an AlertDialog LayoutInflater factory = LayoutInflater.from(this); final View textEntryView = factory.inflate(R.layout.custom_dialog, null); final EditText cdet11 = (EditText) findViewById(R.id.cdet1); final TextView tv11 = (TextView) findViewById(R.id.buname1); return new AlertDialog.Builder(Main.this) .setIcon(R.drawable.icon) .setTitle("Title") .setView(textEntryView) .setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { android.os.Debug.waitingForDebugger(); String string1 = getSharedPreferences("PREFERENCE", MODE_PRIVATE).getString("butname11", ""); String ss1 = cdet11.getText().toString(); getSharedPreferences("PREFERENCE", MODE_PRIVATE) .edit() .putString("butname11", ss1 ) .commit(); String string11 = getSharedPreferences("PREFERENCE", MODE_PRIVATE).getString("butname11", ""); tv11.setText(string11); /* User clicked OK so do some stuff */ } }) .setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { /* User clicked cancel so do some stuff */ } }) .create(); } return null; } 但是获得这样的错误: 04-21 14:54:25.319: E/AndroidRuntime(6331): java.lang.NullPointerException 04-21 14:54:25.319: E/AndroidRuntime(6331): at com.home.Main$3.onClick(Main.java:166) 04-21 14:54:25.319: E/AndroidRuntime(6331): at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:158) 04-21 14:54:25.319: E/AndroidRuntime(6331): at android.os.Handler.dispatchMessage(Handler.java:99) 04-21 14:54:25.319: E/AndroidRuntime(6331): at android.os.Looper.loop(Looper.java:144) 04-21 14:54:25.319: E/AndroidRuntime(6331): at android.app.ActivityThread.main(ActivityThread.java:4937) 04-21 14:54:25.319: E/AndroidRuntime(6331): at java.lang.reflect.Method.invokeNative(Native Method) 04-21 14:54:25.319: E/AndroidRuntime(6331): at java.lang.reflect.Method.invoke(Method.java:521) 04-21 14:54:25.319: E/AndroidRuntime(6331): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 04-21 14:54:25.319: E/AndroidRuntime(6331): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 04-21 14:54:25.319: E/AndroidRuntime(6331): at dalvik.system.NativeStart.main(Native Method) 问题出在哪里呢?
android studio连接web报错?
1.问题描述 可以通过浏览器连接web应用,但用android studio连接报错 2.代码如下 Android端 **activity_main.xml:** <android.support.constraint.ConstraintLayout 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" tools:context=".MainActivity"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <EditText android:id="@+id/et_username" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="请输入用户名 " /> <EditText android:id="@+id/et_password" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="请输入密码" /> <Button android:onClick="click1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="get"/> <Button android:onClick="click2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="post"/> </LinearLayout> </android.support.constraint.ConstraintLayout> ``` ``` MainActivity private EditText username; private EditText password; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); username = (EditText) findViewById(R.id.et_username); password = (EditText) findViewById(R.id.et_password); } public void click1(View v) { new Thread() { @Override public void run() { super.run(); } }.start(); try { String name = username.getText().toString().trim(); String pwd = password.getText().toString().trim(); String path = "http://10.0.2.2:8080/login/loginServlet?username=" + name + "&password=" + pwd + ""; URL url = new URL(path); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("GET"); conn.setConnectTimeout(5000); int code = conn.getResponseCode(); if (code == 200) { showToast("连接成功"); } } catch (Exception e) { e.printStackTrace(); } } public void click2(View v) { } public void showToast(final String content) { runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(getApplicationContext(), content, Toast.LENGTH_LONG).show(); } }); } } ``` ``` AndroidManifest.xml <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.administrator.myapplication1"> <uses-permission android:name="android.permission.INTERNET"></uses-permission> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> ``` ``` 点击按钮后的日志 05-01 04:50:39.613 9826-9826/? I/art: Not late-enabling -Xcheck:jni (already on) 05-01 04:50:39.613 9826-9826/? W/art: Unexpected CPU variant for X86 using defaults: x86 05-01 04:50:39.911 9826-9826/com.example.administrator.myapplication1 W/System: ClassLoader referenced unknown path: /data/app/com.example.administrator.myapplication1-2/lib/x86 05-01 04:50:39.933 9826-9826/com.example.administrator.myapplication1 I/InstantRun: starting instant run server: is main process 05-01 04:50:40.140 9826-9826/com.example.administrator.myapplication1 W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable 05-01 04:50:40.727 9826-9852/com.example.administrator.myapplication1 I/OpenGLRenderer: Initialized EGL, version 1.4 05-01 04:50:40.727 9826-9852/com.example.administrator.myapplication1 D/OpenGLRenderer: Swap behavior 1 05-01 04:50:40.727 9826-9852/com.example.administrator.myapplication1 W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without... 05-01 04:50:40.727 9826-9852/com.example.administrator.myapplication1 D/OpenGLRenderer: Swap behavior 0 05-01 04:50:40.896 9826-9826/com.example.administrator.myapplication1 W/art: Before Android 4.1, method int android.support.v7.widget.ListViewCompat.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView 05-01 04:51:59.575 9826-9826/com.example.administrator.myapplication1 W/IInputConnectionWrapper: finishComposingText on inactive InputConnection 05-01 04:52:02.649 9826-9826/com.example.administrator.myapplication1 D/NetworkSecurityConfig: No Network Security Config specified, using platform default 05-01 04:52:02.651 9826-9826/com.example.administrator.myapplication1 W/System.err: android.os.NetworkOnMainThreadException at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1303) at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:333) at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:196) at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:178) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:356) 05-01 04:52:02.652 9826-9826/com.example.administrator.myapplication1 W/System.err: at java.net.Socket.connect(Socket.java:605) at com.android.okhttp.internal.Platform.connectSocket(Platform.java:113) at com.android.okhttp.Connection.connectSocket(Connection.java:196) at com.android.okhttp.Connection.connect(Connection.java:172) at com.android.okhttp.Connection.connectAndSetOwner(Connection.java:367) at com.android.okhttp.OkHttpClient$1.connectAndSetOwner(OkHttpClient.java:130) at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:329) at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:246) at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:457) at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:405) at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:521) at com.example.administrator.myapplication1.MainActivity.click1(MainActivity.java:44) at java.lang.reflect.Method.invoke(Native Method) at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288) at android.view.View.performClick(View.java:5637) at android.view.View$PerformClick.run(View.java:22429) at android.os.Handler.handleCallback(Handler.java:751) at android.os.Handler.dispatchMessage(Handler.java:95) 05-01 04:52:02.655 9826-9826/com.example.administrator.myapplication1 W/System.err: at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6119) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
fragement中控件空指针
public class FoundNew extends Fragment{ private EditText ed_found_id; private Button btn_ok,btn_cancel; @Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { // TODO Auto-generated method stub super.onActivityCreated(savedInstanceState); } @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreateView(inflater, container, savedInstanceState); View founNewView = inflater.inflate(R.layout.found_new, container,false); ed_found_id = (EditText)founNewView.findViewById(R.id.ed_found_id); btn_cancel = (Button)founNewView.findViewById(R.id.btn_fundNewCancel); btn_ok = (Button)founNewView.findViewById(R.id.btn_fundNewOk); btn_cancel.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub String sttt = ed_found_id.getText().toString(); ed_found_id.setText(""); } }); return founNewView; } } ed_found_id.setText("");执行不过 04-13 06:31:47.860: D/AndroidRuntime(941): Shutting down VM 04-13 06:31:47.860: W/dalvikvm(941): threadid=1: thread exiting with uncaught exception (group=0x409c01f8) 04-13 06:31:47.880: E/AndroidRuntime(941): FATAL EXCEPTION: main 04-13 06:31:47.880: E/AndroidRuntime(941): java.lang.NullPointerException 04-13 06:31:47.880: E/AndroidRuntime(941): at com.example.foundmanager.FoundNew$1.onClick(FoundNew.java:77) 04-13 06:31:47.880: E/AndroidRuntime(941): at android.view.View.performClick(View.java:3511) 04-13 06:31:47.880: E/AndroidRuntime(941): at android.view.View$PerformClick.run(View.java:14105) 04-13 06:31:47.880: E/AndroidRuntime(941): at android.os.Handler.handleCallback(Handler.java:605) 04-13 06:31:47.880: E/AndroidRuntime(941): at android.os.Handler.dispatchMessage(Handler.java:92) 04-13 06:31:47.880: E/AndroidRuntime(941): at android.os.Looper.loop(Looper.java:137) 04-13 06:31:47.880: E/AndroidRuntime(941): at android.app.ActivityThread.main(ActivityThread.java:4424) 04-13 06:31:47.880: E/AndroidRuntime(941): at java.lang.reflect.Method.invokeNative(Native Method) 04-13 06:31:47.880: E/AndroidRuntime(941): at java.lang.reflect.Method.invoke(Method.java:511) 04-13 06:31:47.880: E/AndroidRuntime(941): atcom.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) 04-13 06:31:47.880: E/AndroidRuntime(941): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 04-13 06:31:47.880: E/AndroidRuntime(941): at dalvik.system.NativeStart.main(Native Method) 好像ed_found_id是空指针 大神帮忙呀
android studio发送短信程序添加权限依然报错
MainActivity: public class MainActivity extends AppCompatActivity { private EditText messageeditText; private EditText numbereditText; private Button button; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); numbereditText= (EditText) findViewById(R.id.numbereditText); messageeditText= (EditText) findViewById(R.id.messageeditetext); button= (Button) findViewById(R.id.button); final PendingIntent pendingIntent=PendingIntent.getBroadcast(this,0,new Intent(),0); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { SmsManager smsManager=SmsManager.getDefault(); smsManager.sendTextMessage(numbereditText.getText().toString(),null, messageeditText.getText().toString(),null,null); } }); } } 配置文件: <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.study.sendreceivemessage"> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> <uses-permission android:name="android.permission.SEND_SMS"></uses-permission> </manifest> logcat: E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.study.sendreceivemessage, PID: 4115 java.lang.SecurityException: Sending SMS message: uid 10058 does not have android.permission.SEND_SMS. at android.os.Parcel.readException(Parcel.java:1599) at android.os.Parcel.readException(Parcel.java:1552) at com.android.internal.telephony.ISms$Stub$Proxy.sendTextForSubscriber(ISms.java:768) at android.telephony.SmsManager.sendTextMessageInternal(SmsManager.java:310) at android.telephony.SmsManager.sendTextMessage(SmsManager.java:293) at com.example.study.sendreceivemessage.MainActivity$1.onClick(MainActivity.java:29) at android.view.View.performClick(View.java:5198) at android.view.View$PerformClick.run(View.java:21147) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
ADT中,下面一段Android代码中的if判断句前两个if为什么始终不执行(结果始终"偏旁")?
![图片说明](https://img-ask.csdn.net/upload/201710/13/1507862039_982606.png) MainActivity.java ``` package com.example.a; import javax.security.auth.PrivateCredentialPermission; import android.app.Activity; import android.content.DialogInterface; //import android.content.DialogInterface.OnClickListener; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; import android.view.View.OnClickListener; /*与"import android.content.DialogInterface.OnClickListener;"冲突*/ public class MainActivity extends Activity { EditText shengao,tizhong; Button jisuan,quxiao; double height=0; double weight=0; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.fragment_main); shengao=(EditText)findViewById(R.id.shengao); tizhong=(EditText)findViewById(R.id.tizhong); jisuan=(Button)findViewById(R.id.jisuan); quxiao=(Button)findViewById(R.id.quxiao); jisuan.setOnClickListener(new View.OnClickListener() { //导入"import android.view.View.OnClickListener;"后无需加"View" @Override public void onClick(View v) { try{ if("".equals(shengao.getText().toString())) //if("".equals(shengao.getText().toString().trim())) //if(shengao.getText()==null || "".equals(shengao.getText().toString().trim())) { shengao.setError("身高不得为空"); } if("".equals(shengao.getText().toString().trim())) { tizhong.setError("体重不能为空"); } if("".equals(shengao.getText().toString())) //if("".equals(shengao.getText().toString().trim())) //if(shengao.getText()!=null && "".equals(shengao.getText().toString().trim())) { height=Double.parseDouble(shengao.getText().toString()); } if(tizhong.getText()!=null && "".equals(tizhong.getText().toString().trim())) { weight=Double.parseDouble(tizhong.getText().toString()); } //double bmi=weight*10000/height/height; double bmi=weight/(height*height); //Toast.makeText(MainActivity.this, ""+bmi, 10000); if(bmi<18) { Toast.makeText(MainActivity.this, "您身材偏瘦, 请加强营养",3000).show(); } else if(bmi<=25) { Toast.makeText(MainActivity.this, "您身材标准, 请继续保持",3000).show(); } else { Toast.makeText(MainActivity.this, "您身材偏胖, 请加强锻炼",3000).show(); } } catch(NumberFormatException e) { Toast.makeText(MainActivity.this, "身高或体重必须是数字", 3000).show(); e.printStackTrace(); } } }); quxiao.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { shengao.setText(""); tizhong.setText(""); } }); } } ``` fragment_main.xml ``` <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="身高" /> <EditText android:id="@+id/shengao" android:layout_width="match_parent" android:layout_height="wrap_content" android:ems="10" > <requestFocus /> </EditText> <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="体重" /> <EditText android:id="@+id/tizhong" android:layout_width="match_parent" android:layout_height="wrap_content" android:ems="10" /> <Button android:id="@+id/jisuan" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="计算" /> <Button android:id="@+id/quxiao" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="取消" /> </LinearLayout> ```
大学四年自学走来,这些私藏的实用工具/学习网站我贡献出来了
大学四年,看课本是不可能一直看课本的了,对于学习,特别是自学,善于搜索网上的一些资源来辅助,还是非常有必要的,下面我就把这几年私藏的各种资源,网站贡献出来给你们。主要有:电子书搜索、实用工具、在线视频学习网站、非视频学习网站、软件下载、面试/求职必备网站。 注意:文中提到的所有资源,文末我都给你整理好了,你们只管拿去,如果觉得不错,转发、分享就是最大的支持了。 一、电子书搜索 对于大部分程序员...
JSON解析——net.sf.json.JSONObject
简介 在程序开发过程中,在参数传递,函数返回值等方面,越来越多的使用JSON。JSON(JavaScript Object Notation)是一种轻量级的数据交换格式,同时也易于机器解析和生成、易于理解、阅读和撰写,而且Json采用完全独立于语言的文本格式,这使得Json成为理想的数据交换语言。 JSON建构于两种结构: “名称/值”对的集合(A Collection of name/va...
卸载 x 雷某度!GitHub 标星 1.5w+,从此我只用这款全能高速下载工具!
作者 | Rocky0429 来源 | Python空间 大家好,我是 Rocky0429,一个喜欢在网上收集各种资源的蒟蒻… 网上资源眼花缭乱,下载的方式也同样千奇百怪,比如 BT 下载,磁力链接,网盘资源等等等等,下个资源可真不容易,不一样的方式要用不同的下载软件,因此某比较有名的 x 雷和某度网盘成了我经常使用的工具。 作为一个没有钱的穷鬼,某度网盘几十 kb 的下载速度让我...
2019年还剩1天,我从外包公司离职了
这日子过的可真快啊,2019年还剩1天,外包公司干了不到3个月,我离职了
我一个37岁的程序员朋友
周末了,人一旦没有点事情干,心里就瞎想,而且跟几个老男人坐在一起,更容易瞎想,我自己现在也是 30 岁了,也是无时无刻在担心自己的职业生涯,担心丢掉工作没有收入,担心身体机能下降,担心突...
计算机网络的核心概念
这是《计算机网络》系列文章的第二篇文章 我们第一篇文章讲述了计算机网络的基本概念,互联网的基本名词,什么是协议以及几种接入网以及网络传输的物理媒体,那么本篇文章我们来探讨一下网络核心、交换网络、时延、丢包、吞吐量以及计算机网络的协议层次和网络攻击。 网络核心 网络的核心是由因特网端系统和链路构成的网状网络,下面这幅图正确的表达了这一点 那么在不同的 ISP 和本地以及家庭网络是如何交换信息的呢?...
python自动下载图片
近日闲来无事,总有一种无形的力量萦绕在朕身边,让朕精神涣散,昏昏欲睡。 可是,像朕这么有职业操守的社畜怎么能在上班期间睡瞌睡呢,我不禁陷入了沉思。。。。 突然旁边的IOS同事问:‘嘿,兄弟,我发现一个网站的图片很有意思啊,能不能帮我保存下来提升我的开发灵感?’ 作为一个坚强的社畜怎么能说自己不行呢,当时朕就不假思索的答应:‘oh, It’s simple. Wait for me for a ...
一名大专同学的四个问题
【前言】   收到一封来信,赶上各种事情拖了几日,利用今天要放下工作的时机,做个回复。   2020年到了,就以这一封信,作为开年标志吧。 【正文】   您好,我是一名现在有很多困惑的大二学生。有一些问题想要向您请教。   先说一下我的基本情况,高考失利,不想复读,来到广州一所大专读计算机应用技术专业。学校是偏艺术类的,计算机专业没有实验室更不用说工作室了。而且学校的学风也不好。但我很想在计算机领...
复习一周,京东+百度一面,不小心都拿了Offer
京东和百度一面都问了啥,面试官百般刁难,可惜我全会。
Java 14 都快来了,为什么还有这么多人固守Java 8?
从Java 9开始,Java版本的发布就让人眼花缭乱了。每隔6个月,都会冒出一个新版本出来,Java 10 , Java 11, Java 12, Java 13, 到2020年3月份,...
达摩院十大科技趋势发布:2020 非同小可!
【CSDN编者按】1月2日,阿里巴巴发布《达摩院2020十大科技趋势》,十大科技趋势分别是:人工智能从感知智能向认知智能演进;计算存储一体化突破AI算力瓶颈;工业互联网的超融合;机器间大规模协作成为可能;模块化降低芯片设计门槛;规模化生产级区块链应用将走入大众;量子计算进入攻坚期;新材料推动半导体器件革新;保护数据隐私的AI技术将加速落地;云成为IT技术创新的中心 。 新的画卷,正在徐徐展开。...
轻松搭建基于 SpringBoot + Vue 的 Web 商城应用
首先介绍下在本文出现的几个比较重要的概念: 函数计算(Function Compute): 函数计算是一个事件驱动的服务,通过函数计算,用户无需管理服务器等运行情况,只需编写代码并上传。函数计算准备计算资源,并以弹性伸缩的方式运行用户代码,而用户只需根据实际代码运行所消耗的资源进行付费。Fun: Fun 是一个用于支持 Serverless 应用部署的工具,能帮助您便捷地管理函数计算、API ...
讲真,这两个IDE插件,可以让你写出质量杠杠的代码
周末躺在床上看《拯救大兵瑞恩》 周末在闲逛的时候,发现了两个优秀的 IDE 插件,据说可以提高代码的质量,我就安装了一下,试了试以后发现,确实很不错,就推荐给大家。 01、Alibaba Java 代码规范插件 《阿里巴巴 Java 开发手册》,相信大家都不会感到陌生,其 IDEA 插件的下载次数据说达到了 80 万次,我今天又贡献了一次。嘿嘿。 该项目的插件地址: https://github....
Python+OpenCV实时图像处理
目录 1、导入库文件 2、设计GUI 3、调用摄像头 4、实时图像处理 4.1、阈值二值化 4.2、边缘检测 4.3、轮廓检测 4.4、高斯滤波 4.5、色彩转换 4.6、调节对比度 5、退出系统 初学OpenCV图像处理的小伙伴肯定对什么高斯函数、滤波处理、阈值二值化等特性非常头疼,这里给各位分享一个小项目,可通过摄像头实时动态查看各类图像处理的特点,也可对各位调参、测试...
2020年一线城市程序员工资大调查
人才需求 一线城市共发布岗位38115个,招聘120827人。 其中 beijing 22805 guangzhou 25081 shanghai 39614 shenzhen 33327 工资分布 2020年中国一线城市程序员的平均工资为16285元,工资中位数为14583元,其中95%的人的工资位于5000到20000元之间。 和往年数据比较: yea...
为什么猝死的都是程序员,基本上不见产品经理猝死呢?
相信大家时不时听到程序员猝死的消息,但是基本上听不到产品经理猝死的消息,这是为什么呢? 我们先百度搜一下:程序员猝死,出现将近700多万条搜索结果: 搜索一下:产品经理猝死,只有400万条的搜索结果,从搜索结果数量上来看,程序员猝死的搜索结果就比产品经理猝死的搜索结果高了一倍,而且从下图可以看到,首页里面的五条搜索结果,其实只有两条才是符合条件。 所以程序员猝死的概率真的比产品经理大,并不是错...
害怕面试被问HashMap?这一篇就搞定了!
声明:本文以jdk1.8为主! 搞定HashMap 作为一个Java从业者,面试的时候肯定会被问到过HashMap,因为对于HashMap来说,可以说是Java集合中的精髓了,如果你觉得自己对它掌握的还不够好,我想今天这篇文章会非常适合你,至少,看了今天这篇文章,以后不怕面试被问HashMap了 其实在我学习HashMap的过程中,我个人觉得HashMap还是挺复杂的,如果真的想把它搞得明明白...
毕业5年,我问遍了身边的大佬,总结了他们的学习方法
我问了身边10个大佬,总结了他们的学习方法,原来成功都是有迹可循的。
程序员如何通过造轮子走向人生巅峰?
前言:你所做的事情,也许暂时看不到成果。但不要灰心,你不是没有成长,而是在扎根。 程序员圈经常流行的一句话:“不要重复造轮子”。在计算机领域,我们将封装好的组件、库,叫做轮子。因为它可以拿来直接用,直接塞进我们的项目中,就能实现对应的功能。 有些同学会问,人家都已经做好了,你再来重新弄一遍,有什么意义?这不是在浪费时间吗。 殊不知,造轮子是一种学习方式,能快速进步,造得好,是自己超强能力的表...
推荐10个堪称神器的学习网站
每天都会收到很多读者的私信,问我:“二哥,有什么推荐的学习网站吗?最近很浮躁,手头的一些网站都看烦了,想看看二哥这里有什么新鲜货。” 今天一早做了个恶梦,梦到被老板辞退了。虽然说在我们公司,只有我辞退老板的份,没有老板辞退我这一说,但是还是被吓得 4 点多都起来了。(主要是因为我掌握着公司所有的核心源码,哈哈哈) 既然 4 点多起来,就得好好利用起来。于是我就挑选了 10 个堪称神器的学习网站,推...
这些软件太强了,Windows必装!尤其程序员!
Windows可谓是大多数人的生产力工具,集娱乐办公于一体,虽然在程序员这个群体中都说苹果是信仰,但是大部分不都是从Windows过来的,而且现在依然有很多的程序员用Windows。 所以,今天我就把我私藏的Windows必装的软件分享给大家,如果有一个你没有用过甚至没有听过,那你就赚了????,这可都是提升你幸福感的高效率生产力工具哦! 走起!???? NO、1 ScreenToGif 屏幕,摄像头和白板...
阿里面试一个ArrayList我都能跟面试官扯半小时
我是真的没想到,面试官会这样问我ArrayList。
曾经优秀的人,怎么就突然不优秀了。
职场上有很多辛酸事,很多合伙人出局的故事,很多技术骨干被裁员的故事。说来模板都类似,曾经是名校毕业,曾经是优秀员工,曾经被领导表扬,曾经业绩突出,然而突然有一天,因为种种原因,被裁员了,...
大学四年因为知道了这32个网站,我成了别人眼中的大神!
依稀记得,毕业那天,我们导员发给我毕业证的时候对我说“你可是咱们系的风云人物啊”,哎呀,别提当时多开心啦????,嗯,我们导员是所有导员中最帅的一个,真的???? 不过,导员说的是实话,很多人都叫我大神的,为啥,因为我知道这32个网站啊,你说强不强????,这次是绝对的干货,看好啦,走起来! PS:每个网站都是学计算机混互联网必须知道的,真的牛杯,我就不过多介绍了,大家自行探索,觉得没用的,尽管留言吐槽吧???? 社...
良心推荐,我珍藏的一些Chrome插件
上次搬家的时候,发了一个朋友圈,附带的照片中不小心暴露了自己的 Chrome 浏览器插件之多,于是就有小伙伴评论说分享一下我觉得还不错的浏览器插件。 我下面就把我日常工作和学习中经常用到的一些 Chrome 浏览器插件分享给大家,随便一个都能提高你的“生活品质”和工作效率。 Markdown Here Markdown Here 可以让你更愉快的写邮件,由于支持 Markdown 直接转电子邮...
看完这篇HTTP,跟面试官扯皮就没问题了
我是一名程序员,我的主要编程语言是 Java,我更是一名 Web 开发人员,所以我必须要了解 HTTP,所以本篇文章就来带你从 HTTP 入门到进阶,看完让你有一种恍然大悟、醍醐灌顶的感觉。 最初在有网络之前,我们的电脑都是单机的,单机系统是孤立的,我还记得 05 年前那会儿家里有个电脑,想打电脑游戏还得两个人在一个电脑上玩儿,及其不方便。我就想为什么家里人不让上网,我的同学 xxx 家里有网,每...
史上最全的IDEA快捷键总结
现在Idea成了主流开发工具,这篇博客对其使用的快捷键做了总结,希望对大家的开发工作有所帮助。
阿里程序员写了一个新手都写不出的低级bug,被骂惨了。
这种新手都不会范的错,居然被一个工作好几年的小伙子写出来,差点被当场开除了。
谁是华为扫地僧?
是的,华为也有扫地僧!2020年2月11-12日,“养在深闺人不知”的华为2012实验室扫地僧们,将在华为开发者大会2020(Cloud)上,和大家见面。到时,你可以和扫地僧们,吃一个洋...
Idea 中最常用的10款插件(提高开发效率),一定要学会使用!
学习使用一些插件,可以提高开发效率。对于我们开发人员很有帮助。这篇博客介绍了开发中使用的插件。
立即提问