android安卓开发 TextView空指针问题怎么解决

我的rmsg已经取到了 System.out.println打印输出也正常 那我设置textView22为什么就报了空指针呢 还是要把textView22放到别的地方去设置 我是点了一个按钮 开始刷卡 然后返回值通过handler发送 然后接收到以后设置成rmsg

    private TextView textView22;
    private String rmsg;
    Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            rmsg=(String)msg.obj;
            System.out.println("我的卡号是******"+rmsg);
            textView22.setText(rmsg);
        }
    };

13个回答

textView22没有初始化 需要findviewById()

cheryl_chenxin
cheryl_chenxin 回复tankgoing: 你这初始化不是全局的当然不可以了,你只声明了全局变量,但你却在初始化的时候又声明了个新的去初始化,赋值时要用的textview当然空指针
2 年多之前 回复
tankgoing
tankgoing findviewbyid是有的。。。但是我写的是TextView textView22 = (TextView) findViewById(R.id.textView22); 把TextView拿掉了就可以了 根本没有意识到这里会出问题
2 年多之前 回复

textView22=(TextView)findViewById(R.id.textView22的id);

textview 没有初始化,然后到时setText导致空指针报错

在发送handler的地方用bundle的方式试试吧
Bundle bundle=new Bundle();
bundle.putString("msg",你的返回值);
Message message=new Message();
message.setData(bundle);
message.what=0x00;
myHandler.sendMessage(message);

接着在回到主线程的handler函数中
String msg1=msg.getData().getString("msg");
然后再进行Textview的设置吧

重写dispatchMessage函数

在oncreat()方法里,找到你的布局文件setContentView(R.layout.xxxx),xxx表示你真正的布局XML文件,在布局XML文件中找到你的TextView控件,给它
赋一个id属性,如:android:id="@+id/tv_card"。
在setContentView方法下面,写一句textView22 = (TextView)findViewById.(R.id.tv_card);
这样试用textView22.setText(rmsg);的时候就不用空指针了。
如果还有问题欢迎回复。

xiao_pin_nong
xiao_pin_nong textview 没有初始化,然后到时setText导致空指针报错
2 年多之前 回复
u010507199
还没想好ne 要获取控件啊,findviewById()
2 年多之前 回复
tankgoing
tankgoing TextView textView22 = (TextView) findViewById(R.id.textView22);多加了一个TextView 影响这么大。。。新手伤不起啊
2 年多之前 回复

一看到空指针,那就看对象是否实例化,是否为null

看下是不是没有初始化

楼上的都是正解,还有就是,如果发送的过程退出该页面也有可能引发空指针

这代码写的有我往年的风范。有一点救。你要不在每个点前面都判断下是否为空。再调用方法

共13条数据 1 尾页
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
android 空指针的问题

在我的MainActivity的onCreate方法里面 现setContentView(R.layout.main)加载main.xml, 然后layout = (LinearLayout)findViewById(R.id.change_page); View view = getLayoutInflater().inflate(R.layout.main_tab1, null); LayoutParams params = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); layout.addView(view, params); 之后我在另一个方法里面 tab1_listView = (ListView)findViewById(R.id.main_tab1_list); int[] colors = {Color.WHITE,Color.WHITE}; tab1_listView.setDivider(new GradientDrawable(Orientation.RIGHT_LEFT, colors)); 然后执行的时候就在tab1_listView.setDivider(new GradientDrawable(Orientation.RIGHT_LEFT, colors));这一行报空指针错误,我的main.xml和main_tab1两个xml文件都正常,没有错误,实在不知道哪里的问题,请大神指教

android 传递给service数据空指针问题

74行出错 ,nullpointException,帮我解答感激不尽,我想把这个数据传给service public class pdrActivity extends Activity implements View.OnClickListener{ private Button wifi_btn,pdr_btn,photo_btn,other_btn; EditText ed1,ed2,ed3; TextView txt1,txt2,txt3,txt4,txt5; Button startBtn,stopBtn; Spinner spinner; pdrService myservice; pdrService.myBind mybind; float[] sendmessage=new float[3]; Handler handler; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_pdr); ed1=(EditText)findViewById(R.id.ed1_pdr); ed2=(EditText)findViewById(R.id.ed2_pdr); ed3=(EditText)findViewById(R.id.ed3_pdr); txt1=(TextView)findViewById(R.id.txt1_pdr); txt2=(TextView)findViewById(R.id.txt2_pdr); txt3=(TextView)findViewById(R.id.txt3_pdr); txt4=(TextView)findViewById(R.id.txt4_pdr); txt5=(TextView)findViewById(R.id.txt5_pdr); spinner=(Spinner)findViewById(R.id.spin_pdr); startBtn=(Button)findViewById(R.id.start_pdr); stopBtn=(Button)findViewById(R.id.stop_pdr); wifi_btn=(Button)findViewById(R.id.btn1_main); photo_btn=(Button)findViewById(R.id.btn3_main); other_btn=(Button)findViewById(R.id.btn4_main); startBtn.setOnClickListener(this); stopBtn.setOnClickListener(this); handler=new Handler(); setData(); // wifi_btn.setOnClickListener(this); // photo_btn.setOnClickListener(this); // other_btn.setOnClickListener(this); } @Override protected void onDestroy() { super.onDestroy(); } @Override public void onClick(View v) { switch (v.getId()){ case R.id.start_pdr: Intent intent=new Intent(this,pdrService.class); bindService(intent,conn,BIND_AUTO_CREATE); handler.postDelayed(runnable,20000); mybind.setData(sendmessage); //error line break; case R.id.stop_pdr: if (myservice.serviceState=="onBind"){ Toast.makeText(this,"service关闭关闭关闭关闭",Toast.LENGTH_SHORT).show(); unbindService(conn); } } } private ServiceConnection conn=new ServiceConnection() { @Override public void onServiceConnected(ComponentName name, IBinder service) { System.out.print("service 连接"); mybind=(pdrService.myBind)service; myservice=mybind.getService(); } @Override public void onServiceDisconnected(ComponentName name) { } }; public void setData(){ sendmessage[0]=1; sendmessage[1]=1; sendmessage[2]=1; } Runnable runnable=new Runnable() { @Override public void run() { float[] inf=mybind.getInf(); if(inf==null){ Toast.makeText(pdrActivity.this,"空数据",Toast.LENGTH_SHORT).show(); } else { Toast.makeText(pdrActivity.this,"非空数据",Toast.LENGTH_SHORT).show(); } txt1.setText(String.valueOf(inf[0])); txt2.setText(String.valueOf(inf[1])); txt3.setText(String.valueOf(inf[2])); txt4.setText(String.valueOf(inf[3])); txt5.setText(String.valueOf(inf[4])); handler.postDelayed(this,20000); } }; } 下面的是我的service public class pdrService extends Service implements SensorEventListener{ float[] inf=new float[5]; float[] infmation={0,0,0}; dataExchange dataexchange; private myBind mybind=new myBind(); public static String serviceState=""; proceedThread thread; @Override public void onCreate() { super.onCreate(); if (infmation!=null){ inf[0]=1; inf[1]=1; inf[2]=1; } else{ inf[0]=2; inf[1]=2; inf[2]=2; } thread=new proceedThread(); thread.start(); } @Nullable @Override public IBinder onBind(Intent intent) { serviceState="onBind"; return mybind; } public class myBind extends Binder { public float[] getInf(){ return inf; } public pdrService getService(){ return pdrService.this; } public void setData(float[] data){ pdrService.this.infmation=data; } } private class proceedThread extends Thread{ public Handler myHandler; public void run(){ Looper.prepare(); myHandler=new Handler(){ @Override public void handleMessage(Message msg) { super.handleMessage(msg); if (msg.what==1){ inf[0]+=1; inf[1]+=1; inf[2]+=1; inf[3]+=1; inf[4]+=1; } } }; Looper.loop(); } } @Override public void onSensorChanged(SensorEvent event) { } @Override public void onAccuracyChanged(Sensor sensor, int accuracy) { } public void dataListener(dataExchange listener){ this.dataexchange=listener; } }

android安卓handler报空指针错

有2个按钮 一个是扫描一个查询 按扫描可以扫描二维码(二维码包含json信息)然后解析后显示在二维码信息那里 然后点查询 把二维码所含的json信息发送出去 得到返回值显示在返回信息那里 如果我只做查询 解析结果可以正常显示 如果我再点查询就会报一个空指针 说我解析那一步错 如果我不做解析 那发送也正常 有没有大神帮我看看为什么 错误信息 Process: com.abc.smartpos.cash, PID: 25086 java.lang.NullPointerException: Attempt to invoke interface method 'java.util.Iterator java.util.List.iterator()' on a null object reference at com.abc.smartpos.cash.ScanQR.parseJSONWithGSONForQR(ScanQR.java:138) at com.abc.smartpos.cash.ScanQR$4.handleMessage(ScanQR.java:127) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5254) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:902) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:697) 我的代码 ``` String orderresult; Handler handler = new Handler() { public void handleMessage(Message msg) { super.handleMessage(msg); orderresult=msg.getData().getString("msg"); //单独执行parseJSONWithGSONForQR()正常显示,继续执行查询操作这里报空指针 parseJSONWithGSONForQR(orderresult); responseinfo.setText(msg.getData().getString("JSON")); } }; //解析扫描得到的JSON数据后设置textview public void parseJSONWithGSONForQR(String jsonData) { String showorder; Gson gson = new Gson(); List<TransPack> transPackList = gson.fromJson(jsonData, new TypeToken<List<TransPack>>() { }.getType()); for (TransPack transPack : transPackList) { showorder="订单号:"+transPack.getId().toString()+"\n"+"意向金:"+transPack.getIntention().toString()+"\n"+"进度款:"+transPack.getProgress().toString()+"\n"+"设计费:"+transPack.getDesign().toString(); orderinfo.setText(showorder); } } //开启新线程 public void queryOrder(){ new Thread(){ public void run(){ postJson(); } }.start(); } //发送JSON并得到返回值,用handler发送 public String responseJSON; public static final String TAG="ScanQR"; public static final MediaType JSON=MediaType.parse("application/json; charset=utf-8"); public void postJson(){ OkHttpClient okHttpClient=new OkHttpClient(); RequestBody requestBody=RequestBody.create(JSON,orderresult); Request request=new Request.Builder() .url("http://api.jisuapi.com/iqa/query") .post(requestBody) .build(); try{ Response response=okHttpClient.newCall(request).execute(); if(response.isSuccessful()){ Log.i(TAG,response.body().string()); responseJSON=response.toString(); Message msg=new Message(); msg.getData().putString("JSON",responseJSON); handler.sendMessage(msg); } }catch (IOException e){ e.printStackTrace(); } } ``` ![图片说明](https://img-ask.csdn.net/upload/201712/31/1514704455_550345.jpg)

android listview 报错 空指针

这问题 困扰了我3天了 不知道为什么 求大神指点 上代码 这是onCreate里面的 // 商品 listview lv_friend=(ListView) findViewById(R.id.LV_store); adapter=new Myadapter(this, getdatas()); System.out.println("adapter+++++++++++"+adapter); lv_friend.setAdapter(adapter); } private List<GetDataType> getdatas() { List<GetDataType> list=new ArrayList<GetDataType>(); GetDataType data1=new GetDataType(); data1.setIv_portrait(R.drawable.ic_launcher); data1.setName("杨幂"); data1.setSignature("喜欢我就来找我啊"); list.add(data1); GetDataType data2=new GetDataType(); data2.setIv_portrait(R.drawable.ic_launcher); data2.setName("范冰冰"); data2.setSignature("我在这里等你哦"); list.add(data2); GetDataType data3=new GetDataType(); data3.setIv_portrait(R.drawable.ic_launcher); data3.setName("唐嫣"); data3.setSignature("来追我呀,呵呵"); list.add(data3); GetDataType data4=new GetDataType(); data4.setIv_portrait(R.drawable.ic_launcher); data4.setName("李小璐"); data4.setSignature("386562,加我好友呀"); list.add(data4); GetDataType data5=new GetDataType(); data5.setIv_portrait(R.drawable.ic_launcher); data5.setName("柳岩"); data5.setSignature("帅哥,过来一下"); list.add(data5); return list; } 这是Myadapter package com.android.workapp; import java.util.List; import android.content.Context; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.ImageView; import android.widget.TextView; public class Myadapter extends BaseAdapter{ private List<GetDataType> mData; private Context mcontext; private int mid; public Myadapter(Context context,List data){ this.mcontext=context; this.mData=data; } //获取列表列的数量 @Override public int getCount() { return mData.size(); } //根据postion获取item的数据 @Override public Object getItem(int position) { return mData.get(position); } //获取position对应的id @Override public long getItemId(int position) { return position; } //创建item的视图 @Override public View getView(int position, View convertView, ViewGroup parent) { View view=View.inflate(mcontext, R.layout.saver_tickey_store_item, null); //获取item对应的数据对象 GetDataType getdata=mData.get(position); //初始化view ImageView iv_portrait= (ImageView) view.findViewById(R.id.IV_portrait); TextView txt_name=(TextView) view.findViewById(R.id.txt_name); TextView signature=(TextView) view.findViewById(R.id.signature); //邦定数据到view iv_portrait.setImageResource(getdata.getIv_portrait()); txt_name.setText(getdata.getName()); signature.setText(getdata.getSignature()); return view; } } GetDataType package com.android.workapp; public class GetDataType { private int iv_portrait; private String name; private String signature; public int getIv_portrait() { return iv_portrait; } public void setIv_portrait(int iv_portrait) { this.iv_portrait = iv_portrait; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getSignature() { return signature; } public void setSignature(String signature) { this.signature = signature; } } ![图片说明](https://img-ask.csdn.net/upload/201601/25/1453724110_137295.png)

android Adapter空指针问题 求大神看看 解决不了

是这样的。我是在做一个相当于一个手机卫士,里面有通讯录和黑名单两个功能。这个代码是我做的黑名单里的。![图片说明](https://img-ask.csdn.net/upload/201706/17/1497695379_112155.png) 想实现的功能是点黑名单按钮,可以出现这个黑名单的Activity。通讯录做了一个Listview,点通讯录按钮,可以导入系统通讯录,然后设置点击监听,长按item可以发短信,点击可以打电话。 现在的问题是,无论是通讯录还是黑名单,一点按钮就报错,报错的内容就是空指针。不知道怎么觉得。哭唧唧。 这个是代码。无论尝试什么方法,都报错空指针。 package com.jinwen.pengu.communication; import android.app.Activity; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.BaseAdapter; import android.widget.GridView; import android.widget.ListView; import android.widget.TextView; import android.widget.Toast; import java.util.ArrayList; import java.util.List; public class Stop extends Activity { private ListView iv_main; private BlackNumberAdapter adapter; private BlackNumberDao dao; private List<BlackNumber> data; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); iv_main = (ListView) findViewById(R.id.iv_main); adapter = new BlackNumberAdapter(); dao = new BlackNumberDao(this); data = dao.getAll(); iv_main.setAdapter(adapter); } public void add(View v){ } class BlackNumberAdapter extends BaseAdapter{ @Override public int getCount() { return data.size(); } @Override public Object getItem(int position) { return data.get(position); } @Override public long getItemId(int position) { return 0; } @Override public View getView(int position, View convertView, ViewGroup parent) { if (convertView ==null){ convertView = View.inflate(Stop.this,android.R.layout.simple_list_item_1,null); } BlackNumber blackNumber = data.get(position); TextView textView = (TextView) convertView.findViewById(android.R.id.text1); textView.setText(blackNumber.getNumber()); return convertView; } } } 错误: Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ListView.setAdapter(android.widget.ListAdapter)' on a null object reference at com.jinwen.pengu.communication.Stop.onCreate(Stop.java:31)

安卓Adapter空指针,一直解决不了

是这样的。我是在做一个相当于一个手机卫士,里面有通讯录和黑名单两个功能。这个代码是我做的黑名单里的。图片说明 想实现的功能是点黑名单按钮,可以出现这个黑名单的Activity。通讯录做了一个Listview,点通讯录按钮,可以导入系统通讯录,然后设置点击监听,长按item可以发短信,点击可以打电话。 现在的问题是,无论是通讯录还是黑名单,一点按钮就报错,报错的内容就是空指针。不知道怎么解决。哭唧唧。 ![图片说明](https://img-ask.csdn.net/upload/201706/18/1497753680_955031.png) 这个是代码。无论尝试什么方法,都报错空指针。 package com.jinwen.pengu.communication; import android.app.Activity; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.BaseAdapter; import android.widget.GridView; import android.widget.ListView; import android.widget.TextView; import android.widget.Toast; import java.util.ArrayList; import java.util.List; public class Stop extends Activity { private ListView iv_main; private BlackNumberAdapter adapter; private BlackNumberDao dao; private List data; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); iv_main = (ListView) findViewById(R.id.iv_main); adapter = new BlackNumberAdapter(); dao = new BlackNumberDao(this); data = dao.getAll(); iv_main.setAdapter(adapter); } public void add(View v){ } class BlackNumberAdapter extends BaseAdapter{ @Override public int getCount() { return data.size(); } @Override public Object getItem(int position) { return data.get(position); } @Override public long getItemId(int position) { return 0; } @Override public View getView(int position, View convertView, ViewGroup parent) { if (convertView ==null){ convertView = View.inflate(Stop.this,android.R.layout.simple_list_item_1,null); } BlackNumber blackNumber = data.get(position); TextView textView = (TextView) convertView.findViewById(android.R.id.text1); textView.setText(blackNumber.getNumber()); return convertView; } } } 错误: Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ListView.setAdapter(android.widget.ListAdapter)' on a null object reference at com.jinwen.pengu.communication.Stop.onCreate(Stop.java:31)

如何获得一个动态创建的textview的ID?

我想要在一个android app中动态添加和删除TextView,我现在正在做,但是我在设置和获得TextView的ID的时候碰到了困难。在最后两行代码中我好想得到了空指针异常(et settext和ll.removeView)。有人知道我怎么可以动态的设置和获得一个textview的ID么?setId似乎没有工作,还是就是我错了? //删除无关的代码 EditText et = (EditText) view.findViewById(R.id.edittext_tags); et.setText(""); TextView nTv = new TextView(view.getContext()); LayoutParams lparams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); lparams.setMargins(10, 0, 0, 0); nTv.setLayoutParams(lparams); nTv.setId(tag_id); nTv.setText(str.substring(0, str.length()-1)); nTv.setTextColor(Color.BLUE); nTv.setTextSize(20); final LinearLayout linl = (LinearLayout) view.findViewById(R.id.linear_layout_tags); linl.addView(nTv); nTv.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { EditText et = (EditText) view.findViewById(R.id.edittext_tags); TextView t = ((TextView)v); et.setText(t.getText().toString()); linl.removeView(v); } });

安卓listview item单击事件跳转空指针问题

两个activity源码, mainactivity: package com.example.newsclient; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import com.example.gxfi.entity.News; import com.example.gxfi.service.GetXmlAndParse; import android.R.string; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.app.Activity; import android.content.Intent; import android.view.Menu; import android.view.View; import android.widget.AdapterView.OnItemClickListener; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.SimpleAdapter; public class MainActivity extends Activity { private List listNews; private ListView list; Handler mHandler = new Handler() { @Override public void handleMessage(Message msg) { // TODO Auto-generated method stub switch (msg.what) { case GetXmlAndParse.PARSESUCCWSS: listNews = (List) msg.obj; initData(); break; } super.handleMessage(msg); } }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); list = (ListView) findViewById(R.id.list); GetXmlAndParse getXmlAndParse = new GetXmlAndParse(mHandler); getXmlAndParse.getXml(); list.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // TODO Auto-generated method stub switch (parent.getId()) { case R.id.list: expressItemClick(position);//position 代表你点的哪一个 break; } } private void expressItemClick(int position) { // TODO Auto-generated method stub Intent intent = new Intent(MainActivity.this,NewsActivity.class); Map<String, String> item = (Map<String, String>) list.getAdapter().getItem(position); String essay = item.get("description"); //添加到intent域中 intent.putExtra("description",essay ); startActivity(intent); finish(); }}); } /** * 将解析后的xml填充到ListView */ protected void initData() { // TODO Auto-generated method stub List items = new ArrayList(); for (News news : (List<News>)listNews) { Map item = new HashMap(); item.put("title", news.getTitle()); item.put("description", news.getDescription()); items.add(item); } SimpleAdapter adapter = new SimpleAdapter(this, items, R.layout.news_view, new String[] { "title" }, new int[] { R.id.textView1 }); list.setAdapter(adapter); } } newsactivity: package com.example.newsclient; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.widget.TextView; public class NewsActivity extends Activity { private TextView myTextView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Intent intent = getIntent(); String value = intent.getStringExtra("description"); myTextView = (TextView) findViewById(R.id.textview2); // myTextView.setText(value); } } 错误: ![图片说明](https://img-ask.csdn.net/upload/201606/19/1466349934_182376.png)

关于new对象后出现空指针问题

我想把Init的东西放到一个类,然后再到主程序中调用。但是在InitView方法里new了SlidingMenu后出现空指针异常。之前是把Init的代码都放在主程序的,那时候就没问题,为什么呢。。。SlidingMenu是一个开源库的一个类。![图片说明](https://img-ask.csdn.net/upload/201603/12/1457750905_35430.png) ![图片说明](https://img-ask.csdn.net/upload/201603/12/1457750924_867622.png)

Android 获取listview数据 然后赋值给popupwindow用于显示报空指针

能得到数据但是给Textview赋值却报空指针! 下边贴代码。 gv.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) { // WindowManager.LayoutParams lp=getWindow().getAttributes(); // lp.alpha = 0.4f; // getWindow().setAttributes(lp); food= (FoodInfo)data.get(position); // 数据类获取数据 Toast.makeText(getApplicationContext(), food.getFoodName(), Toast.LENGTH_SHORT).show(); //这里可以正常显示,说明得到了数据 TextView name=(TextView) findViewById(R.id.popup_tv1);//popupwindow name.setText(food.getFoodName()); // setText 报空指针 initPopuWindow1(arg0); // 加载弹出框 }

Android自定义控件中为Button设置自定义监听器出现空指针。

Android自定义TopBar中给ImageButton设置自定义点击监听器,当点击ImageButton时在listener处出现NullPointerException。 会出错的地方我在后面写了//TODO 。 请问为什么会出现listener没有被实例化的情况? 还有为什么在MainActivity中使用findViewById实例化TopBar也会出现不能实例化控件的情况? IDE : Android Studio ; Compile Sdk Version : API 23 ; Build Tool Version : 23.0.1 ; Min Sdk Version : API 15 ; Target Sdk Version : API 19 ; 部分代码: #MainActivity.java ``` public class MainActivity extends AppCompatActivity { private TopBar topBar; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // topBar = (TopBar) findViewById(R.id.topBar); //TODO 这样无法实例化topBar ??? topBar = new TopBar(getApplicationContext(), null); if (topBar == null) { Toast.makeText(MainActivity.this, "NULL", Toast.LENGTH_SHORT).show(); } topBar.setOnTopBarClickListener(new TopBar.OnClickListener() { @Override public void onLeftButtonClick() { Toast.makeText(MainActivity.this, "Left", Toast.LENGTH_SHORT).show(); } @Override public void onRightButtonClick() { Toast.makeText(MainActivity.this, "Right", Toast.LENGTH_SHORT).show(); } }); } } ``` #TopBar.java ``` public class TopBar extends RelativeLayout { private ImageButton ibtLeft; private ImageButton ibtRight; private TextView tvTitle; private OnClickListener listener; public interface OnClickListener { void onLeftButtonClick(); void onRightButtonClick(); } public void setOnTopBarClickListener(OnClickListener listener) { this.listener = listener; } public TopBar(Context context, AttributeSet attrs) { super(context); LayoutInflater.from(context).inflate(R.layout.layout_top_bar, this); ibtLeft = (ImageButton) findViewById(R.id.ibt_left); ibtRight = (ImageButton) findViewById(R.id.ibt_right); tvTitle = (TextView) findViewById(R.id.tv_title); ibtLeft.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(getContext(), "leftButton", Toast.LENGTH_SHORT).show(); //Toast可以显示 // listener.onLeftButtonClick(); //TODO NullPointerException 为什么没有实例化listener? } }); ibtRight.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { listener.onRightButtonClick(); //TODO NullPointerException } }); } } ``` #logcat输出 ``` 10-14 13:42:14.442 1366-1366/com.vder.puzzlegame E/AndroidRuntime: FATAL EXCEPTION: main 10-14 13:42:14.442 1366-1366/com.vder.puzzlegame E/AndroidRuntime: java.lang.NullPointerException 10-14 13:42:14.442 1366-1366/com.vder.puzzlegame E/AndroidRuntime: at com.vder.puzzlegame.ui.TopBar$2.onClick(TopBar.java:55) 10-14 13:42:14.442 1366-1366/com.vder.puzzlegame E/AndroidRuntime: at android.view.View.performClick(View.java:4204) 10-14 13:42:14.442 1366-1366/com.vder.puzzlegame E/AndroidRuntime: at android.view.View$PerformClick.run(View.java:17355) 10-14 13:42:14.442 1366-1366/com.vder.puzzlegame E/AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:725) 10-14 13:42:14.442 1366-1366/com.vder.puzzlegame E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:92) 10-14 13:42:14.442 1366-1366/com.vder.puzzlegame E/AndroidRuntime: at android.os.Looper.loop(Looper.java:137) 10-14 13:42:14.442 1366-1366/com.vder.puzzlegame E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5041) 10-14 13:42:14.442 1366-1366/com.vder.puzzlegame E/AndroidRuntime: at java.lang.reflect.Method.invokeNative(Native Method) 10-14 13:42:14.442 1366-1366/com.vder.puzzlegame E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:511) 10-14 13:42:14.442 1366-1366/com.vder.puzzlegame E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 10-14 13:42:14.442 1366-1366/com.vder.puzzlegame E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 10-14 13:42:14.442 1366-1366/com.vder.puzzlegame E/AndroidRuntime: at dalvik.system.NativeStart.main(Native Method) ```

ListAdapter 的空指针异常

我想在List View中显示数据,但是在运行时获得Null Pointer Exception错误。 fList.setAdapter(la); 下面是我用的代码。list 在 Log 中全部打印出来了。 public class Forfattere extends Activity { /** Called when the activity is first created. */ ArrayList<String> aList = new ArrayList<String>(); @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.forfattere); ListView fList = (ListView)findViewById(R.id.Author_list); ArrayList<String> a = DBlistbookfestival.getAuthorName(); for(int i=0;i<a.size();i++){ aList.add(a.get(i)); Log.v("all_data",a.get(i)); } ListAdapter1 la = new ListAdapter1(this, R.id.Author_list, aList); fList.setAdapter(la); } private class ListAdapter1 extends ArrayAdapter<String> { // --CloneChangeRequired private ArrayList<String> mList; // --CloneChangeRequired public ListAdapter1(Context context, int textViewResourceId,ArrayList<String> list) { // --CloneChangeRequired super(context, textViewResourceId, list); this.mList = list; } public View getView(int position, View convertView, ViewGroup parent){ View view = convertView; try{ if (view == null) { LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); view = vi.inflate(R.layout.custom_radio, null); // --CloneChangeRequired(list_item) } final String listItem = mList.get(position); // --CloneChangeRequired if (listItem != null) { ( (TextView) view.findViewById(R.id.textView111) ).setText(listItem); }}catch(Exception e){ } return view; } } 如何出现的这个异常啊?

安卓中传递得到空指针

在fragment(Info_Frag)中有如下代码: storeNum = store.getText().toString(); phoneNum = phone.getText().toString(); add = address.getText().toString(); cit = city.getText().toString(); zipCode = zip.getText().toString(); state_picked = myStates.getSelectedItem().toString(); Bundle bundle = new Bundle(); Fragment f = new Fragment(); bundle.putString("store", storeNum); bundle.putString("phone", phoneNum); bundle.putString("address", add); bundle.putString("city", cit); bundle.putString("zip", zipCode); bundle.putString("state", state_picked); f.setArguments(bundle); 代替fragment如下: Fragment fragment = new StoreInfo_Fragment(); getFragmentManager() .beginTransaction() .setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out) .replace(R.id.storeInfo_fragment_container, fragment).commit(); 在其他的fragment (StoreInfo_Fragment) 中调用: public class StoreInfo_Fragment extends Fragment { View view; public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { view = inflater.inflate(R.layout.fragment_store_info, container, false); String mStore = getArguments().getString("store"); String mPhone = getArguments().getString("phone"); String mAddress = getArguments().getString("address"); String mCity = getArguments().getString("city"); String mZip = getArguments().getString("zip"); String mState = getArguments().getString("state"); TextView store = (TextView) view.findViewById(R.id.store); TextView phone = (TextView) view.findViewById(R.id.phone); TextView address = (TextView) view.findViewById(R.id.address); TextView city = (TextView) view.findViewById(R.id.city); TextView zip = (TextView) view.findViewById(R.id.zip); TextView state = (TextView) view.findViewById(R.id.state); store.setText(mStore); phone.setText(mPhone); address.setText(mAddress); city.setText(mCity); zip.setText(mZip); state.setText(mState); return view; } } 在运行之后,报出错误,结果应用崩溃。 说是这行String mStore = getArguments().getString("store"); 有空指针。 很显然是传递时出现错误了。 请高手指教。

android adapter空指针异常

``` public class MainActivity extends AppCompatActivity { DatabaseHelper databaseHelper; private static Toolbar mToolbar; private static TextView mMaintitle,mMaincontent,mMaintime; public static EditText dlx_Input1,dlx_Input2; public static String datetime; public static View mLine; MyAdapter myAdapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); findName(); setSupportActionBar(mToolbar); databaseHelper = new DatabaseHelper(this, databaseHelper.DATABASE_NAME, null, databaseHelper.DATABASE_VERSION); //myAdapter.getData2(); myAdapter = new MyAdapter(this); myAdapter.lv = (ListView)findViewById(R.id.lv); myAdapter.data = myAdapter.getData(); MyAdapter adapter = new MyAdapter(this); myAdapter.lv.setAdapter(adapter); } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.action_add: showDialog_Layout(MainActivity.this); } return super.onOptionsItemSelected(item); } public void findName() { mToolbar = (Toolbar) findViewById(R.id.toolbar); mMaintitle = (TextView)findViewById(R.id.dlx_maintitle); mMaincontent = (TextView)findViewById(R.id.dlx_maincontent); mMaintime = (TextView)findViewById(R.id.dlx_maintime); mLine = (View)findViewById(R.id.dlx_line); } private void showDialog_Layout(Context context) { dlx_Input1 = (EditText)findViewById(R.id.dlx_Input1); dlx_Input2 = (EditText)findViewById(R.id.dlx_Input2); final AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setCancelable(false); builder.setTitle(R.string.dlx_add); builder.setPositiveButton("CANCEL", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { setTitle(""); } }); builder.setNegativeButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { SQLiteDatabase db = databaseHelper.getWritableDatabase(); ContentValues values = new ContentValues(); SimpleDateFormat s = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); datetime = s.format(new java.util.Date()); values.put("title", String.valueOf(dlx_Input1.getText())); values.put("content", String.valueOf(dlx_Input2.getText())); values.put("time", datetime); db.insert(databaseHelper.TABLE_NAME, null, values); myAdapter.getData(); } }); builder.show(); } @Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.menu, menu); menu.findItem(R.id.action_add).setChecked(true); return super.onCreateOptionsMenu(menu); } } public class MyAdapter extends BaseAdapter { public static ListView lv; public static List<Map<String, Object>> data; public LayoutInflater mInflater = null; MainActivity mainActivity; DatabaseHelper databaseHelper; public MyAdapter(Context context) { this.mInflater = LayoutInflater.from(context); } public List<Map<String, Object>> getData() { List<Map<String, Object>> list = new ArrayList<Map<String, Object>>(); Map<String, Object> map; for(int i=0;i<10;i++) { map = new HashMap<String, Object>(); map.put("title",String.valueOf(mainActivity.dlx_Input1.getText())); map.put("content", String.valueOf(mainActivity.dlx_Input2.getText())); map.put("time",mainActivity.datetime); list.add(map); } return list; } static class ViewHolder { public TextView title; public TextView content; public TextView time; public View line; } public int getCount() { //How many items are in the data set represented by this Adapter. //在此适配器中所代表的数据集中的条目数 return data.size(); } public Object getItem(int position) { // Get the data item associated with the specified position in the data set. //获取数据集中与指定索引对应的数据项 return position; } public long getItemId(int position) { //Get the row id associated with the specified position in the list. //获取在列表中与指定索引对应的行id return position; } //Get a View that displays the data at the specified position in the data set. //获取一个在数据集中指定索引的视图来显示数据 public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder = null; //如果缓存convertView为空,则需要创建View if(convertView == null) { holder = new ViewHolder(); //根据自定义的Item布局加载布局 convertView = mInflater.inflate(R.layout.commentlayout, null); holder.title = (TextView)convertView.findViewById(R.id.dlx_maintitle); holder.content = (TextView)convertView.findViewById(R.id.dlx_maincontent); holder.time = (TextView)convertView.findViewById(R.id.dlx_maintime); holder.line = (View)convertView.findViewById(R.id.dlx_line); //将设置好的布局保存到缓存中,并将其设置在Tag里,以便后面方便取出Tag convertView.setTag(holder); }else { holder = (ViewHolder)convertView.getTag(); } holder.title.setText((String)data.get(position).get("title")); holder.content.setText((String)data.get(position).get("content")); holder.time.setText((String)data.get(position).get("time")); holder.line.setBackgroundColor(mainActivity.getResources().getColor(R.color.colorPrimaryDark)); return convertView; } ``` 在map.put("title",String.valueOf(mainActivity.dlx_Input1.getText()));和myAdapter.data = myAdapter.getData();报空指针异常 Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.text.Editable android.widget.EditText.getText()' on a null object reference,求大神指点!!!

求助大神!android的baseadapter老是报空指针

package com.example.kaoqin; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import org.apache.commons.lang.ObjectUtils.Null; import android.R.integer; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.EditText; import android.widget.ListAdapter; import android.widget.ListView; import android.widget.SimpleAdapter; import android.widget.TextView; import android.widget.Toast; public class User_TiaoZhuan_Activity2 extends Activity { private ListView list; private SimpleAdapter SAda; public String huoquuser; private String[] From = new String[]{"yonghu","kaishi","jieshu","zong","yuanyin","zhuangtai","id"}; public ArrayList<HashMap<String, Object>> data = new ArrayList<HashMap<String,Object>>(); private ArrayList<ItemBean> datalist = new ArrayList<ItemBean>(); public String NAME; public String START; public String END; public String SUM; public String REASON; public String STATE; public String ID; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.user_tiaozhuan_activity2); list = (ListView)findViewById(R.id.listViewuser); Intent intent = getIntent();//将检索出来的intent赋值给一个Intent类型的变量intent,getIntent()方法用于直接返回Intent实例 Bundle bundle = intent.getExtras();///获取前面的那个activity传过来的数据 huoquuser = bundle.getString("username"); HttpClien httpClien = new HttpClien(); data = httpClien.HTTPLeaveListView(huoquuser, "2"); //SAda = new SimpleAdapter(User_TiaoZhuan_Activity2.this, getdata(data),R.layout.user_tiaozhuan_buju2, From,new int[]{R.id.tiaozhuan_user2, //R.id.tiaozhuan_start2,R.id.tiaozhuan_end2,R.id.tiaozhuan_sum2,R.id.tiaozhuan_reason2,R.id.tiaozhuan_shenhe2,R.id.tiaozhuan_id2}); //list.setAdapter(SAda); Edit nihao = new Edit(this, getdata(data));//把数据源放入baseadapter list.setAdapter(nihao); } public ArrayList<ItemBean> getdata(ArrayList<HashMap<String,Object>> shuju) { for (int i = 0; i < data.size(); i++) { NAME = String.valueOf(shuju.get(i).get("name")); START = String.valueOf(shuju.get(i).get("start")); END = String.valueOf(shuju.get(i).get("end")); SUM = String.valueOf(shuju.get(i).get("sum")); REASON = String.valueOf(shuju.get(i).get("reason")); STATE = String.valueOf(shuju.get(i).get("state")); ID = String.valueOf(shuju.get(i).get("id")); ItemBean it = new ItemBean(NAME, START, END, SUM, REASON, STATE,ID); datalist.add(it); } return datalist; } } class Edit extends BaseAdapter { private Context context; private ArrayList<ItemBean> list; private LayoutInflater miInflater; public Edit(Context context,ArrayList<ItemBean> list) { LayoutInflater miInflater; miInflater = LayoutInflater.from(context); this.context = context; this.list = list; //根据context上下文加载布局,这里的是User_TiaoZhuan_Activity本身,即this } @Override public int getCount() { // TODO Auto-generated method stub //在此适配器中所代表的数据集中的条目数 return list.size(); } @Override public Object getItem(int position) { // TODO Auto-generated method stub //获取数据集中与指定索引对应的数据项 return list.get(position); } @Override public long getItemId(int position) { // TODO Auto-generated method stub //获取在列表中与指定索引对应的行id return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { // TODO Auto-generated method stub ViewHolder kongjian = null; if(convertView == null) { convertView = miInflater.inflate(R.layout.user_tiaozhuan_buju2, null); kongjian = new ViewHolder(); kongjian.TV_sure = (TextView)convertView.findViewById(R.id.yunxu); kongjian.TV_cancel = (TextView)convertView.findViewById(R.id.bohui); kongjian.TVuser = (TextView)convertView.findViewById(R.id.tiaozhuan_user2); kongjian.TVstart = (TextView)convertView.findViewById(R.id.tiaozhuan_start2); kongjian.TVend = (TextView)convertView.findViewById(R.id.tiaozhuan_end2); kongjian.TVsum = (TextView)convertView.findViewById(R.id.tiaozhuan_sum2); kongjian.TVreason = (TextView)convertView.findViewById(R.id.tiaozhuan_reason2); kongjian.TVstate = (TextView)convertView.findViewById(R.id.tiaozhuan_shenhe2); kongjian.TVid = (TextView)convertView.findViewById(R.id.tiaozhuan_id2); //将设置好的布局保存到缓存中,并将其设置在Tag里,以便后面方便取出Tag convertView.setTag(kongjian); }else { kongjian = (ViewHolder)convertView.getTag(); } kongjian.TV_sure.setText("允许请假"); kongjian.TV_cancel.setText("驳回请假"); ItemBean bean = list.get(position); kongjian.TVuser.setText(bean.Itemuser);; kongjian.TVstart.setText(bean.Itemstarttime); kongjian.TVend.setText(bean.Itemendtime); kongjian.TVsum.setText(bean.Itemsumtime); kongjian.TVreason.setText(bean.Itemreason); kongjian.TVstate.setText(bean.Itemstate); kongjian.TVid.setText(bean.ItemId); kongjian.TV_sure.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub System.out.println("通过"); } }); kongjian.TV_cancel.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub System.out.println("不通过"); } }); return convertView; } } class ViewHolder { TextView TV_sure; TextView TV_cancel; TextView TVuser; TextView TVstart; TextView TVend; TextView TVsum; TextView TVreason; TextView TVid; TextView TVstate; } class ItemBean { public String Itemuser; public String Itemstarttime; public String Itemendtime; public String Itemsumtime; public String Itemreason; public String Itemstate; public String ItemId; public ItemBean(String a,String b,String c, String d,String e,String f,String g) { Itemuser = a; Itemstarttime = b; Itemendtime = c; Itemsumtime = d; Itemreason = e; Itemstate = f; ItemId = g; } }![图片说明](https://img-ask.csdn.net/upload/201611/10/1478771417_684227.png) 错误显示的是121行存在空指针,inflate里的布局文件是存在的啊,R类里也有 地址啊(R.layout.user_tiaozhuan_buju2, null);

Android中重写SimpleAdapter类引用后报空指针异常

直接粘代码吧 - - 重写的SimpleAdapter类: ``` public class MySimpleAdapter extends BaseAdapter { private LayoutInflater mInflater; private ArrayList<HashMap<String, Object>> list; private int layoutID; private String flag[]; private int ItemIDs[]; public MySimpleAdapter(Context context, ArrayList<HashMap<String, Object>> list, int layoutID, String flag[], int ItemIDs[]) { this.mInflater = LayoutInflater.from(context); this.list = list; this.layoutID = layoutID; this.flag = flag; this.ItemIDs = ItemIDs; } @Override public int getCount() { // TODO Auto-generated method stub return list.size(); } @Override public Object getItem(int arg0) { // TODO Auto-generated method stub return 0; } @Override public long getItemId(int arg0) { // TODO Auto-generated method stub return 0; } @Override public View getView(int position, View convertView, ViewGroup parent) { convertView = mInflater.inflate(layoutID, null); convertView = mInflater.inflate(layoutID, null); for (int i = 0; i < flag.length; i++) { if (convertView.findViewById(ItemIDs[i]) instanceof ImageView) { ImageView iv = (ImageView) convertView.findViewById(ItemIDs[i]); iv.setBackgroundResource((Integer) list.get(position).get( flag[i])); } else if (convertView.findViewById(ItemIDs[i]) instanceof TextView) { TextView tv = (TextView) convertView.findViewById(ItemIDs[i]); tv.setText((String) list.get(position).get(flag[i])); } } addListener(convertView); return convertView; } public void addListener(View convertView) { ((TextView)convertView.findViewById(R.id.order_mine_show_handle_confirm)).setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { new AlertDialog.Builder(OrderMineNonPaymentActivity.onp) .setTitle("自定义通用SimpleAdapter") .setMessage("按钮成功触发监听事件!") .show(); } }); } } ``` 引用的地方 OrderMineNonPaymentActivity: ``` /** * 动态生成订单列表 lipeng */ private void addNonPaymentList() { order_mine_show_non_payment_list_ll = (LinearLayout) findViewById(R.id.order_mine_show_non_payment_list_ll); nonPaymentList = (ListView) findViewById(R.id.order_mine_show_non_payment_list); nonPaymentList.setDivider(null); nonPaymentSimpleAdapter = new SimpleAdapter( OrderMineNonPaymentActivity.this, goodsList, R.layout.activity_order_non_payment_item, new String[] { "shopname", "bigimage", "goodname" }, new int[] { R.id.order_mine_show_shopname, R.id.order_mine_show_goods_img, R.id.order_mine_show_goods_name }); MySimpleAdapter nonPaymentSimpleAdapter = new MySimpleAdapter(this, goodsList, R.layout.activity_order_mine_non_payment, new String[] { "shopname", "bigimage", "goodname" }, new int[] { R.id.order_mine_show_shopname, R.id.order_mine_show_goods_img, R.id.order_mine_show_goods_name }); nonPaymentList.setAdapter(nonPaymentSimpleAdapter); } private class MyOnItemClickListener implements OnItemClickListener { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { // TODO Auto-generated method stub } } ``` 异常报的空指针,找了半天也没找到为啥空指针了 ``` 06-17 22:55:32.845: E/AndroidRuntime(1463): FATAL EXCEPTION: main 06-17 22:55:32.845: E/AndroidRuntime(1463): Process: com.zb.stlala, PID: 1463 06-17 22:55:32.845: E/AndroidRuntime(1463): java.lang.NullPointerException 06-17 22:55:32.845: E/AndroidRuntime(1463): at com.zb.stlala.adapter.MySimpleAdapter.addListener(MySimpleAdapter.java:83) 06-17 22:55:32.845: E/AndroidRuntime(1463): at com.zb.stlala.adapter.MySimpleAdapter.getView(MySimpleAdapter.java:75) ```

findviewbyid 空指针的问题

各位大侠,最近发现一个问题个人觉得非常诡异。 在oncreate 中 listView_test = (ListView) this.findViewById(R.id.listcardinfo); 为null。 但是 同一个页面中的一个button的 onClick方法确可以找到这个listview,并且赋值。 附上XML ``` <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:umadsdk="http://schemas.android.com/apk/res/com.LoveBus" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="#FFFFFF" android:orientation="vertical" > <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="测试" android:textColor="#000000" android:textSize="22.0dip" /> <include layout="@layout/home_title_layout"/> </RelativeLayout> <android.support.v4.view.ViewPager android:id="@+id/vPager" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_gravity="center" android:layout_weight="1.0" android:flipInterval="30" android:persistentDrawingCache="animation" /> </LinearLayout> ``` ``` <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" 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=".MainActivity" > <ListView android:id="@+id/listcardinfo" android:layout_width="fill_parent" android:layout_height="fill_parent" > </ListView> </LinearLayout> ```

增加个context变量就报空指针异常

这个代码我是复制网上一位博客的,只不过在他的基础上增加个context,目的是想显示 Toast这个东西,但崩溃了,怎么改?新手不懂 ![图片说明](https://img-ask.csdn.net/upload/201702/17/1487280676_887989.png) ![图片说明](https://img-ask.csdn.net/upload/201702/17/1487280727_591317.jpg) EventHandler.java ``` package com.mytest.handlertest; import android.content.Context; import android.os.Handler; import android.os.Looper; import android.os.Message; import android.util.Log; import android.widget.TextView; import android.widget.Toast; class EventHandler extends Handler { private NoLooperThread noLooperThread; private OwnLooperThread ownLooperThread; private TextView tv; private Context context; public EventHandler(Looper looper) { super(looper); } public EventHandler() { super(); } @Override public void handleMessage(Message msg) { super.handleMessage(msg); Log.e("EventHandler", "当前线程id:------+>"+Thread.currentThread().getId()); Toast.makeText(context, "当前线程id:------+>"+Thread.currentThread().getId(), Toast.LENGTH_SHORT).show(); //可以根据msg.what执行不同的处理,这里没有这么做 switch(msg.what){ case 1: tv.setText((String)msg.obj); break; case 2: tv.setText((String)msg.obj); noLooperThread.stop(); break; case 3: //不能在非主线程的线程里面更新UI,所以这里通过Log打印收到的消息 Log.e("EventHandler", (String)msg.obj); ownLooperThread.stop(); break; default: //不能在非主线程的线程里面更新UI,所以这里通过Log打印收到的消息 Log.e("EventHandler", (String)msg.obj); break; } } } ``` HandlerTest.java ``` package com.mytest.handlertest; import android.app.Activity; import android.os.Bundle; import android.os.Handler; import android.os.Looper; import android.os.Message; 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; public class HandlerTest extends Activity implements OnClickListener { private Button btn1,btn2,btn3,btn4,btn5,btn6; private boolean postRunnable; private EventHandler mHandler; private NoLooperThread noLooperThread; private OwnLooperThread ownLooperThread; private Handler mOtherThreadHandler; private TextView tv; private ReceiveMessageThread receiveMessageThread; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_handler_test); btn1=(Button)findViewById(R.id.b101); btn2=(Button)findViewById(R.id.b102); btn3=(Button)findViewById(R.id.b103); btn4=(Button)findViewById(R.id.b104); btn5=(Button)findViewById(R.id.b105); btn6=(Button)findViewById(R.id.b106); btn1.setOnClickListener(this); btn2.setOnClickListener(this); btn3.setOnClickListener(this); btn4.setOnClickListener(this); btn5.setOnClickListener(this); btn6.setOnClickListener(this); receiveMessageThread=new ReceiveMessageThread(); receiveMessageThread.start(); } @Override public void onClick(View v) { switch(v.getId()){ case R.id.b101: //主线程发送消息给自己 Looper looper; looper = Looper.myLooper(); //get the Main looper related with the main thread //如果不给任何参数的话会用当前线程对应的Looper(这里就是Main Looper)为Handler里面的成员mLooper赋值 mHandler = new EventHandler(looper); //mHandler = new EventHandler(); // 清除整个MessageQueue里的消息 mHandler.removeMessages(0); String obj = "This main thread's message and received by itself!"; //得到Message对象 Message m = mHandler.obtainMessage(1, 1, 1, obj); // 将Message对象送入到main thread的MessageQueue里面 mHandler.sendMessage(m); break; case R.id.b102: //other线程发送消息给主线程 postRunnable = false; noLooperThread = new NoLooperThread(); noLooperThread.start(); break; case R.id.b103: //other thread获取它自己发送的消息 tv.setText("please look at the error level log for other thread received message"); ownLooperThread = new OwnLooperThread(); ownLooperThread.start(); break; case R.id.b104: //other thread通过Post Runnable方式发送消息给主线程 postRunnable = true; noLooperThread = new NoLooperThread(); noLooperThread.start(); break; case R.id.b105: //主线程发送消息给other thread if(null!=mOtherThreadHandler){ tv.setText("please look at the error level log for other thread received message from main thread"); String msgObj = "message from mainThread"; Message mainThreadMsg = mOtherThreadHandler.obtainMessage(1, 1, 1, msgObj); mOtherThreadHandler.sendMessage(mainThreadMsg); } break; case R.id.b106: finish(); break; } } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.handler_test, 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); } } ``` NoLooperThread.java ``` package com.mytest.handlertest; import android.content.Context; import android.os.Looper; import android.os.Message; import android.util.Log; import android.widget.TextView; import android.widget.Toast; class NoLooperThread extends Thread{ private Context context; private TextView tv; private boolean postRunnable; private EventHandler mNoLooperThreadHandler; public void run() { Looper myLooper, mainLooper; myLooper = Looper.myLooper(); mainLooper = Looper.getMainLooper(); //这是一个static函数 String obj; if(myLooper == null){ mNoLooperThreadHandler = new EventHandler(mainLooper); obj = "NoLooperThread has no looper and handleMessage function executed in main thread!"; } else { mNoLooperThreadHandler = new EventHandler(myLooper); obj = "This is from NoLooperThread self and handleMessage function executed in NoLooperThread!"; } Toast.makeText(context, obj, Toast.LENGTH_SHORT).show(); mNoLooperThreadHandler.removeMessages(0); if(false == postRunnable){ //send message to main thread Message m = mNoLooperThreadHandler.obtainMessage(2, 1, 1, obj); mNoLooperThreadHandler.sendMessage(m); Log.e("NoLooperThread", "NoLooperThread id:" + this.getId()); }else{ //下面new出来的实现了Runnable接口的对象中run函数是在Main Thread中执行,不是在NoLooperThread中执行 //注意Runnable是一个接口,它里面的run函数被执行时不会再新建一个线程 //您可以在run上加断点然后在eclipse调试中看它在哪个线程中执行 mNoLooperThreadHandler.post(new Runnable(){ @Override public void run() { tv.setText("update UI through handler post runnalbe mechanism!"); // noLooerThread.stop(); } }); } } } ``` OwnLooperThread.java ``` package com.mytest.handlertest; import android.content.Context; import android.os.Looper; import android.os.Message; import android.widget.Toast; class OwnLooperThread extends Thread{ private Context context; private EventHandler mOwnLooperThreadHandler; public void run() { Looper.prepare(); Looper myLooper, mainLooper; myLooper = Looper.myLooper(); mainLooper = Looper.getMainLooper(); //这是一个static函数 String obj; if(myLooper == null){ mOwnLooperThreadHandler = new EventHandler(mainLooper); obj = "OwnLooperThread has no looper and handleMessage function executed in main thread!"; } else { mOwnLooperThreadHandler = new EventHandler(myLooper); obj = "This is from OwnLooperThread self and handleMessage function executed in NoLooperThread!"; } Toast.makeText(context, obj, Toast.LENGTH_SHORT).show(); mOwnLooperThreadHandler.removeMessages(0); //给自己发送消息 Message m = mOwnLooperThreadHandler.obtainMessage(3, 1, 1, obj); mOwnLooperThreadHandler.sendMessage(m); Looper.loop(); } } ``` ReceiveMessageThread.java ``` package com.mytest.handlertest; import android.content.Context; import android.os.Handler; import android.os.Looper; import android.os.Message; import android.util.Log; import android.widget.Toast; class ReceiveMessageThread extends Thread{ private Handler mOtherThreadHandler; private Context context; public void run() { Looper.prepare(); mOtherThreadHandler = new Handler(){ @Override public void handleMessage(Message msg) { super.handleMessage(msg); Log.e("ReceiveMessageThread", (String)msg.obj); Log.e("ReceiveMessageThread","当前线程id:----+>"+Thread.currentThread().getId()); Toast.makeText(context, "当前线程id:----+>"+Thread.currentThread().getId(), Toast.LENGTH_SHORT).show(); } }; Looper.loop(); } } ```

求大神指导Android中重写SimpleAdapter类引getCount空指针异常,万分感谢

重写的BaseAdapter: ``` public class MyAdapter extends BaseAdapter { List<UserInfo> userInfos=new ArrayList<UserInfo>(); Context context; public MyAdapter(Context c,List<UserInfo> userInfos) { // TODO Auto-generated constructor stub this.context=c; this.userInfos=userInfos; } public void setcotext(List<UserInfo> userInfos){ this.userInfos=userInfos; } @Override public int getCount() { // TODO Auto-generated method stub return userInfos.size(); } @Override public Object getItem(int arg0) { // TODO Auto-generated method stub return userInfos.get(arg0); } @Override public long getItemId(int arg0) { // TODO Auto-generated method stub return userInfos.get(arg0).getId(); } @Override public View getView(int arg0, View arg1, ViewGroup arg2) { // TODO Auto-generated method stub if(arg1==null){ arg1=LayoutInflater.from(context).inflate(R.layout.book_item, null); } TextView _context=(TextView) arg1.findViewById(R.id.content); TextView _datetime=(TextView) arg1.findViewById(R.id.datetime); UserInfo u=userInfos.get(arg0); _context.setText(u.getContent()); _datetime.setText(u.getDatetime()); return arg1; } } ``` Activity的: ``` public class MainActivity extends Activity implements OnClickListener{ Button add; Button re; SQLiteDatabase db; ListView listView; MyAdapter adapter; List<UserInfo> liUse; protected void onRestart() { // TODO Auto-generated method stub super.onRestart(); shuaxin(); } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); DbInit(); add=(Button) findViewById(R.id.add); listView=(ListView) findViewById(R.id.lv); registerForContextMenu(listView); adapter=new MyAdapter(this , liUse); listView.setAdapter(adapter); } public List<UserInfo> selectAll(){ List<UserInfo> ls=new ArrayList<UserInfo>(); Cursor cur=db.rawQuery(" select * from user ", null); while (cur.moveToNext()) { UserInfo u = new UserInfo(); u.setId(cur.getInt(cur.getColumnIndex("_id"))); u.setContent(cur.getString(cur.getColumnIndex("content"))); u.setDatetime(cur.getString(cur.getColumnIndex("datetime"))); ls.add(u); } return liUse; } @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 void onClick(View arg0) { // TODO Auto-generated method stub switch (arg0.getId()) { case R.id.refresh: shuaxin(); break; case R.id.add: Intent intent=new Intent(this,AddConActivity.class); startActivity(intent); break; default: break; } } public void DbInit(){ DBHelper dbHelper=new DBHelper(this, "Cotext.db", null, 1); db=dbHelper.getWritableDatabase(); } class DBHelper extends SQLiteOpenHelper{ public DBHelper(Context context, String name, CursorFactory factory, int version) { super(context, name, factory, version); // TODO Auto-generated constructor stub } @Override public void onCreate(SQLiteDatabase arg0) { // TODO Auto-generated method stub SimpleDateFormat formatter = new SimpleDateFormat ("yyyy年MM月dd日 HH:mm:ss "); Date curDate = new Date(System.currentTimeMillis());//获取当前时间 String str = formatter.format(curDate); arg0.execSQL("create table user ( _id integer primary key autoincrement , datetime text not null , content varchar(100))"); ContentValues cv=new ContentValues(); cv.put("datetime", str); cv.put("content", "测试"); arg0.insert("user", "datetime", cv); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { // TODO Auto-generated method stub } } private void shuaxin() { liUse=selectAll(); adapter.setcotext(liUse); adapter.notifyDataSetInvalidated(); } } ``` get 和 set : ``` public class UserInfo implements Serializable{ private int id; private String datetime; private String content; public UserInfo() { // TODO Auto-generated constructor stub } public UserInfo(int id,String datetime,String content) { // TODO Auto-generated constructor stub this.setId(id); this.setContent(content); this.setDatetime(datetime); } public UserInfo(String datetime,String content) { // TODO Auto-generated constructor stub this.setContent(content); this.setDatetime(datetime); } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getDatetime() { return datetime; } public void setDatetime(String datetime) { this.datetime = datetime; } public String getContent() { return content; } public void setContent(String content) { this.content = content; } } 异常 ``` 04-23 16:48:45.585: E/AndroidRuntime(1823): FATAL EXCEPTION: main 04-23 16:48:45.585: E/AndroidRuntime(1823): Process: com.example.notepad, PID: 1823 04-23 16:48:45.585: E/AndroidRuntime(1823): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.notepad/com.example.notepad.MainActivity}: java.lang.NullPointerException 04-23 16:48:45.585: E/AndroidRuntime(1823): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2219) 04-23 16:48:45.585: E/AndroidRuntime(1823): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2269) 04-23 16:48:45.585: E/AndroidRuntime(1823): at android.app.ActivityThread.access$800(ActivityThread.java:135) 04-23 16:48:45.585: E/AndroidRuntime(1823): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 04-23 16:48:45.585: E/AndroidRuntime(1823): at android.os.Handler.dispatchMessage(Handler.java:102) 04-23 16:48:45.585: E/AndroidRuntime(1823): at android.os.Looper.loop(Looper.java:136) 04-23 16:48:45.585: E/AndroidRuntime(1823): at android.app.ActivityThread.main(ActivityThread.java:5045) 04-23 16:48:45.585: E/AndroidRuntime(1823): at java.lang.reflect.Method.invokeNative(Native Method) 04-23 16:48:45.585: E/AndroidRuntime(1823): at java.lang.reflect.Method.invoke(Method.java:515) 04-23 16:48:45.585: E/AndroidRuntime(1823): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) 04-23 16:48:45.585: E/AndroidRuntime(1823): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) 04-23 16:48:45.585: E/AndroidRuntime(1823): at dalvik.system.NativeStart.main(Native Method) 04-23 16:48:45.585: E/AndroidRuntime(1823): Caused by: java.lang.NullPointerException 04-23 16:48:45.585: E/AndroidRuntime(1823): at com.example.notepad.MyAdapter.getCount(MyAdapter.java:29) 04-23 16:48:45.585: E/AndroidRuntime(1823): at android.widget.ListView.setAdapter(ListView.java:480) 04-23 16:48:45.585: E/AndroidRuntime(1823): at com.example.notepad.MainActivity.onCreate(MainActivity.java:44) 04-23 16:48:45.585: E/AndroidRuntime(1823): at android.app.Activity.performCreate(Activity.java:5231) 04-23 16:48:45.585: E/AndroidRuntime(1823): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104) 04-23 16:48:45.585: E/AndroidRuntime(1823): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2163) 04-23 16:48:45.585: E/AndroidRuntime(1823): ... 11 more ```

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

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

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

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

Java基础知识面试题(2020最新版)

文章目录Java概述何为编程什么是Javajdk1.5之后的三大版本JVM、JRE和JDK的关系什么是跨平台性?原理是什么Java语言有哪些特点什么是字节码?采用字节码的最大好处是什么什么是Java程序的主类?应用程序和小程序的主类有何不同?Java应用程序与小程序之间有那些差别?Java和C++的区别Oracle JDK 和 OpenJDK 的对比基础语法数据类型Java有哪些数据类型switc...

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

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

和黑客斗争的 6 天!

互联网公司工作,很难避免不和黑客们打交道,我呆过的两家互联网公司,几乎每月每天每分钟都有黑客在公司网站上扫描。有的是寻找 Sql 注入的缺口,有的是寻找线上服务器可能存在的漏洞,大部分都...

Intellij IDEA 实用插件安利

1. 前言从2020 年 JVM 生态报告解读 可以看出Intellij IDEA 目前已经稳坐 Java IDE 头把交椅。而且统计得出付费用户已经超过了八成(国外统计)。IDEA 的...

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

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

总结了 150 余个神奇网站,你不来瞅瞅吗?

原博客再更新,可能就没了,之后将持续更新本篇博客。

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

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

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

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

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

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

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

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

魂迁光刻,梦绕芯片,中芯国际终获ASML大型光刻机

据羊城晚报报道,近日中芯国际从荷兰进口的一台大型光刻机,顺利通过深圳出口加工区场站两道闸口进入厂区,中芯国际发表公告称该光刻机并非此前盛传的EUV光刻机,主要用于企业复工复产后的生产线扩容。 我们知道EUV主要用于7nm及以下制程的芯片制造,光刻机作为集成电路制造中最关键的设备,对芯片制作工艺有着决定性的影响,被誉为“超精密制造技术皇冠上的明珠”,根据之前中芯国际的公报,目...

优雅的替换if-else语句

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

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

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

2020阿里全球数学大赛:3万名高手、4道题、2天2夜未交卷

阿里巴巴全球数学竞赛( Alibaba Global Mathematics Competition)由马云发起,由中国科学技术协会、阿里巴巴基金会、阿里巴巴达摩院共同举办。大赛不设报名门槛,全世界爱好数学的人都可参与,不论是否出身数学专业、是否投身数学研究。 2020年阿里巴巴达摩院邀请北京大学、剑桥大学、浙江大学等高校的顶尖数学教师组建了出题组。中科院院士、美国艺术与科学院院士、北京国际数学...

为什么你不想学习?只想玩?人是如何一步一步废掉的

不知道是不是只有我这样子,还是你们也有过类似的经历。 上学的时候总有很多光辉历史,学年名列前茅,或者单科目大佬,但是虽然慢慢地长大了,你开始懈怠了,开始废掉了。。。 什么?你说不知道具体的情况是怎么样的? 我来告诉你: 你常常潜意识里或者心理觉得,自己真正的生活或者奋斗还没有开始。总是幻想着自己还拥有大把时间,还有无限的可能,自己还能逆风翻盘,只不是自己还没开始罢了,自己以后肯定会变得特别厉害...

男生更看重女生的身材脸蛋,还是思想?

往往,我们看不进去大段大段的逻辑。深刻的哲理,往往短而精悍,一阵见血。问:产品经理挺漂亮的,有点心动,但不知道合不合得来。男生更看重女生的身材脸蛋,还是...

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

二哥,有个事想询问下您的意见,您觉得应届生值得去外包吗?公司虽然挺大的,中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

差点跪了...

最近微信又搞出了一个大利器,甚至都上了热搜,当然消息最敏捷的自媒体人,纷纷都开通了自己的视频号。01 视频号是什么呢?视频号是微信体系内的短视频,它不同...

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

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

Vue回炉重造之router路由(更新中)

你好,我是Vam的金豆之路,可以叫我豆哥。2019年年度博客之星、技术领域博客专家。主要领域:前端开发。我的微信是 maomin9761,有什么疑问可以加我哦,自己创建了一个微信技术交流群,可以加我邀请你一起交流学习。最后自己也创建了一个微信公众号,里面的文章是我自己精挑细选的文章,主要介绍各种IT新技术。欢迎关注哦,微信搜索:臻美IT,等你来。 欢迎阅读本博文,本博文主要讲述【】,文字通...

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

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

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

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

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

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

大胆预测下未来5年的Web开发

在2019年的ReactiveConf 上,《Elm in Action》的作者Richard Feldman对未来5年Web开发的发展做了预测,很有意思,分享给大家。如果你有机会从头...

立即提问
相关内容推荐