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();
        }
    }

图片说明

2个回答

你的jsonData为空

Message msg=new Message();
msg.getData().putString("JSON",responseJSON);
handler.sendMessage(msg);

然后执行这里时候
orderresult=msg.getData().getString("msg");
这个orderresult为空

然后
List transPackList = gson.fromJson(jsonData, new TypeToken>() {
}.getType());
这个jsonData就是传空了

//发送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("JSO

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

public class Floating_windowActivity extends Activity { private SliderRelativeLayout sliderLayout = null; private Handler mHandler =new Handler (){ public void handleMessage(Message msg){ Log.i(TAG, "handleMessage : #### " ); if(MSG_LOCK_SUCESS == msg.what){ closeLig(); android.os.Process.killProcess(android.os.Process.myPid()); } super.handleMessage(msg); } }; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); sliderLayout = (SliderRelativeLayout)findViewById(R.id.slider_layout); sliderLayout.setMainHandler(mHandler); // 运行到这里报空指针异常,求大神解释。。。 } } public class SliderRelativeLayout extends RelativeLayout { public Handler mainHandler = null; public void setMainHandler(Handler handler){ mainHandler = handler;//activity所在的Handler对象 } private void handleActionUpEvent(MotionEvent event){ Message message = new Message(); message.what = 1; mainHandler.sendMessage(message); } }

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); } }; ```

handler处理2个setText怎么弄 报空指针

我有2个按钮 先点扫描 然后得到二维码内容 显示在二维码信息那里(二维码本身就是JSON格式) 然后点查询 把二维码内容发送出去 得到返回值 显示在返回信息那里 2个方法的返回值都是通过handler发送然后再获取msg 再setText 然后我如果显示了二维码信息 再点查询的话就会退回上一级 报空指针 如果我单扫描二维码 不显示出来(还是获得了二维码信息 仅不setText) 那我点查询就可以显示返回值 请问要怎么解决 让我显示了二维码信息后还是可以显示返回值 新手小白。。。 ``` String orderresult; Handler handler = new Handler() { public void handleMessage(Message msg) { super.handleMessage(msg); orderresult=msg.getData().getString("msg"); parseJSONWithGSONForQR(orderresult); responseinfo.setText(msg.getData().getString("JSON")); } }; 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(); } 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(); } } ```

增加个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 传递给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在动画结束的onAnimationEnd中移除视图报空指针

我在通过按钮删除一个视图,使用了淡出动画,在动画结束的监听中,删除视图removeView,报了空指针,但是用了handler.post后就好了,为什么呢?

android adapter 提示空指针异常

``` public class ContactInfoParser extends Activity { ListView mListView; List<String> contactList = new ArrayList<String>(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mListView = (ListView) findViewById(R.id.list_contact); ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, contactList); mListView.setAdapter(adapter); readContacts(); } private void readContacts() { Cursor cursor = null; try{ cursor = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, null); while (cursor.moveToNext()) { String displayname = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME)); String diplaynumber = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)); contactList.add(displayname + "\n" + diplaynumber); } }catch (Exception e){ e.printStackTrace(); }finally { if (cursor != null) { cursor.close(); } } } } ``` 上面这段代码从其他activity跳转过来,执行到mListView.setAdapter(adapter);这句话的时候,提示一直报错空指针异常。 报错代码如下: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.liujing.shanzhaisafe/com.liujing.shanzhaisage.fangdaomokuai.dialog.ContactInfoParser}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ListView.setAdapter(android.widget.ListAdapter)' on a null object reference at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) at android.app.ActivityThread.access$800(ActivityThread.java:151) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) 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:903) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) 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.liujing.shanzhaisage.fangdaomokuai.dialog.ContactInfoParser.onCreate(ContactInfoParser.java:24)

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) ```

Android的GLES20RecordingCanvas空指针的问题

错误是友盟统计提供的,只有这些,没法确定是哪段代码出了问题,所以只想问问大家有没有碰到过类似的问题,给我点提示就好啦,谢谢! 目前看都是出现在4.0以上的版本上,应该跟硬件加速有关。但不知道该怎么解决这个问题。不可能全局关闭硬件加速,代价太高 ``` java.lang.NullPointerException at android.view.GLES20RecordingCanvas.drawBitmap(GLES20RecordingCanvas.java:118) at android.graphics.drawable.BitmapDrawable.draw(BitmapDrawable.java:393) at android.widget.ImageView.onDraw(ImageView.java:892) at android.view.View.draw(View.java:11015) at android.view.ViewGroup.drawChild(ViewGroup.java:2971) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2573) at android.view.ViewGroup.drawChild(ViewGroup.java:2969) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2573) at android.view.View.draw(View.java:11018) at android.widget.FrameLayout.draw(FrameLayout.java:450) at android.widget.ScrollView.draw(ScrollView.java:1525) at android.view.ViewGroup.drawChild(ViewGroup.java:2971) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2573) at android.view.ViewGroup.drawChild(ViewGroup.java:2969) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2573) at android.view.View.draw(View.java:11018) at android.support.v4.view.ViewPager.draw(ViewPager.java:2092) at android.view.ViewGroup.drawChild(ViewGroup.java:2971) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2573) at android.view.View.getDisplayList(View.java:10452) at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:2681) at android.view.View.getDisplayList(View.java:10417) at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:2681) at android.view.View.getDisplayList(View.java:10417) at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:2681) at android.view.View.getDisplayList(View.java:10417) at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:2681) at android.view.View.getDisplayList(View.java:10417) at android.view.HardwareRenderer$GlRenderer.draw(HardwareRenderer.java:851) at android.view.ViewRootImpl.draw(ViewRootImpl.java:2034) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1748) at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2583) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:4503) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:809) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:576) at dalvik.system.NativeStart.main(Native Method) ```

android adapter提示空指针异常情况

主要代码如下: package com.example.mydreamhero.ActivityManage; import android.app.Activity; import android.app.ActivityManager; import android.content.Context; import android.os.Bundle; import android.os.Debug; import android.widget.ListView; import com.example.mydreamhero.R; import java.util.ArrayList; import java.util.List; /** * Created by 刘 on 2017/3/5. */ public class AMProcessActivity extends Activity { private ListView listView; private List<AMProcessInfo> mAmprocessInfo = null; private ActivityManager manager; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.am_main); listView = (ListView) findViewById(R.id.listview_am_process); manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); //提示下面这一行出错 listView.setAdapter(new AMProcessAdapter(this, getRunningprocess())); } private List<AMProcessInfo> getRunningprocess() { mAmprocessInfo = new ArrayList<AMProcessInfo>(); List<ActivityManager.RunningAppProcessInfo> appprocessInfo = manager.getRunningAppProcesses(); for (int i = 0; i < appprocessInfo.size(); i++) { ActivityManager.RunningAppProcessInfo info = appprocessInfo.get(i); int pid = info.pid; int uid = info.uid; String processName = info.processName; int[] memorypid = new int[]{pid}; Debug.MemoryInfo memoryInfo[] = manager.getProcessMemoryInfo(memorypid); int memorySize = memoryInfo[0].getTotalPss(); AMProcessInfo amProcessInfo = new AMProcessInfo(); amProcessInfo.setPid(""+pid); amProcessInfo.setUid(""+uid); amProcessInfo.setMemorySize(memorySize+"KB"); amProcessInfo.setProcessName(processName); mAmprocessInfo.add(amProcessInfo); } return mAmprocessInfo; } }** 出错一次如下: 03/05 23:17:17: Launching app $ adb push F:\androidforGoogle\MyDreamHero\app\build\outputs\apk\app-debug.apk /data/local/tmp/com.example.mydreamhero $ adb shell pm install -r "/data/local/tmp/com.example.mydreamhero" pkg: /data/local/tmp/com.example.mydreamhero Success $ adb shell am start -n "com.example.mydreamhero/com.example.mydreamhero.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER Client not ready yet..Waiting for process to come online Waiting for process to come online Connected to process 3275 on device genymotion-genymotion_vbox86p_6_0_160825_141918-192.168.196.101:5555 I/art: Background partial concurrent mark sweep GC freed 1613(300KB) AllocSpace objects, 0(0B) LOS objects, 39% free, 1587KB/2MB, paused 101us total 183.475ms D/AndroidRuntime: Shutting down VM E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.mydreamhero, PID: 3275 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mydreamhero/com.example.mydreamhero.ActivityManage.AMProcessActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ListView.setAdapter(android.widget.ListAdapter)' on a null object reference at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) at android.app.ActivityThread.-wrap11(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) at android.os.Handler.dispatchMessage(Handler.java:102) 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) 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.example.mydreamhero.ActivityManage.AMProcessActivity.onCreate(AMProcessActivity.java:29) at android.app.Activity.performCreate(Activity.java:6237) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)  at android.app.ActivityThread.-wrap11(ActivityThread.java)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)  at android.os.Handler.dispatchMessage(Handler.java:102)  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)  我查了好多次都没有找到原因,求大神来不吝解答一下

Android RecyclerView滑动出现空指针异常

ViewPager里面是Fragment然后Fragment里面是RecyclerV但是可以正常显示列表,一旦滑动就会出现异常,这个是垂直方向的 然后里面还嵌套了一个水平方向的网格式RecyclerView没有显示出来!TIME=1429828195000 FINGERPRINT=Xiaomi/cancro_wc_lte/cancro:4.4.4/KTU84P/5.4.24:user/release-keys HARDWARE=qcom UNKNOWN=unknown RADIO=unknown BOARD=MSM8974 versionCode=1 PRODUCT=cancro_wc_lte versionName=1.0 DISPLAY=KTU84P USER=builder HOST=qh-miui-ota-bd56 DEVICE=cancro TAGS=release-keys MODEL=MI 4LTE BOOTLOADER=unknown CPU_ABI=armeabi-v7a CPU_ABI2=armeabi IS_DEBUGGABLE=true ID=KTU84P SERIAL=895f2f74 MANUFACTURER=Xiaomi BRAND=Xiaomi TYPE=user java.lang.NullPointerException at android.support.v4.view.ViewCompat$ICSViewCompatImpl.setAccessibilityDelegate(ViewCompat.java:923) at android.support.v4.view.ViewCompat.setAccessibilityDelegate(ViewCompat.java:1343) at android.support.v7.widget.RecyclerView$Recycler.addViewHolderToRecycledViewPool(RecyclerView.java:3900) at android.support.v7.widget.RecyclerView$Recycler.recycleCachedViewAt(RecyclerView.java:3843) at android.support.v7.widget.RecyclerView$Recycler.recycleViewHolderInternal(RecyclerView.java:3880) at android.support.v7.widget.RecyclerView$Recycler.recycleView(RecyclerView.java:3804) at android.support.v7.widget.RecyclerView$LayoutManager.removeAndRecycleViewAt(RecyclerView.java:5529) at android.support.v7.widget.LinearLayoutManager.recycleChildren(LinearLayoutManager.java:1143) at android.support.v7.widget.LinearLayoutManager.recycleViewsFromEnd(LinearLayoutManager.java:1218) at android.support.v7.widget.LinearLayoutManager.recycleByLayoutState(LinearLayoutManager.java:1242) at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1268) at android.support.v7.widget.LinearLayoutManager.scrollBy(LinearLayoutManager.java:1102) at android.support.v7.widget.LinearLayoutManager.scrollVerticallyBy(LinearLayoutManager.java:959) at android.support.v7.widget.RecyclerView$ViewFlinger.run(RecyclerView.java:3062) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761) at android.view.Choreographer.doCallbacks(Choreographer.java:574) at android.view.Choreographer.doframe(Choreographer.java:543) at android.view.Choreographer$frameDisplayEventReceiver.run(Choreographer.java:747) at android.os.Handler.handleCallback(Handler.java:733) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5047) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:806) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622) at dalvik.system.NativeStart.main(Native Method)

fragment中通过getActivity()获取Context空指针

试了好多方法不行; 在onCreateView()中可以获取,然后在onCreateView()中获取,并设置为全局变量,然后在其它方法中使用,可是郁闷的是还报空指针 java.lang.NullPointerException at com.weather.weather.activity.WeatherFragment.jointURL(WeatherFragment.java:390) at com.weather.weather.activity.MyAsyncTask.onPostExecute(MyAsyncTask.java:99) at com.weather.weather.activity.MyAsyncTask.onPostExecute(MyAsyncTask.java:25) at android.os.AsyncTask.finish(AsyncTask.java:631) at android.os.AsyncTask.access$600(AsyncTask.java:177) at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:5457) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:525) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:879) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:695) at dalvik.system.NativeStart.main(Native Method)

LayoutInflater.from(context) 报空指针异常

这是打印出来的Log: Process: com.hql.rssr, PID: 1905 java.lang.NullPointerException at android.view.LayoutInflater.from(LayoutInflater.java:211) at com.hql.Adapter.FragmentExpanableListViewAdapter.<init>(FragmentExpanableListViewAdapter.java:32) at com.hql.fragment.TechnologyFragment$2.showListView(TechnologyFragment.java:94) at com.hql.fragment.TechnologyFragment$2.handleMessage(TechnologyFragment.java:81) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5045) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) at dalvik.system.NativeStart.main(Native Method) 报错的是这行代码:public FragmentExpanableListViewAdapter(Context context, ArrayList<GroupTitle> Gp, Map<Integer,List<RssItem>> ChildMap) { mInflater = LayoutInflater.from(context); //是这里。。。。。 this.Gp = Gp; this.ChilderMap = ChildMap; list = new ArrayList<RssItem>(); } 我在碎片里面调用的时候是这样子的: adapter = new FragmentExpanableListViewAdapter(getActivity(), title, list); 能运行,数据的加载和显示也没问题,就是在页面切换的时候会偶尔报这个错。我想问一下 这会不会是和多个碎片共用一个适配器有关,因为碎片的布局的样式都一样,只是加载的数据类型不一样 adapter = new FragmentExpanableListViewAdapter(getActivity(), title, list); (就是像这行代码一样 这是里面的title 和list 不一样而已) 我就直接用多个碎片对应一个适配器了 这是怎么回事呢?/d:

android运行报错求教 空指针异常

报错日志 显示空指针异常 上日志 06-20 19:35:24.264 3122-3122/com.example.wangzhe.ssapp E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.wangzhe.ssapp, PID: 3122 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.wangzhe.ssapp/com.example.wangzhe.ssapp.Drawer.Device_managment}: java.lang.NullPointerException: Attempt to invoke virtual method 'com.lidroid.xutils.DbUtils com.example.wangzhe.ssapp.My.getDb()' on a null object reference at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) at android.app.ActivityThread.-wrap11(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) at android.os.Handler.dispatchMessage(Handler.java:102) 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) Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'com.lidroid.xutils.DbUtils com.example.wangzhe.ssapp.My.getDb()' on a null object reference at com.example.wangzhe.ssapp.Drawer.Device_managment.init(Device_managment.java:53) at com.example.wangzhe.ssapp.Drawer.Device_managment.onCreate(Device_managment.java:40) at android.app.Activity.performCreate(Activity.java:6237) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)  at android.app.ActivityThread.-wrap11(ActivityThread.java)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)  at android.os.Handler.dispatchMessage(Handler.java:102)  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)  ![日志提示位置](https://img-ask.csdn.net/upload/201606/21/1466452017_434017.png) getDb(); package com.example.wangzhe.ssapp; import android.app.Application; import com.lidroid.xutils.DbUtils; import com.lidroid.xutils.DbUtils.DaoConfig; public class My extends Application { private static My mInstance; private DbUtils db; public static My getInstance() { return mInstance; } @Override public void onCreate() { super.onCreate(); mInstance = this; } public DbUtils getDb() { if (db == null) { DaoConfig daoConfig = new DaoConfig(this); daoConfig.setDbName("data.db"); daoConfig.setDbVersion(2); db = DbUtils.create(daoConfig); } return db; } }

安卓开发Fragment里面空指针问题求大神赐教

报错代码: 12-20 10:21:08.243 4780-4780/? E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.asus.accuntingapp, PID: 4780 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.asus.accuntingapp/com.example.asus.accuntingapp.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.util.LinkedList com.example.asus.accuntingapp.RecordDatabaseHelper.getAvaliableDate()' on a null object reference at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360) at android.app.ActivityThread.access$800(ActivityThread.java:144) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5221) 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:899) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694) Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.util.LinkedList com.example.asus.accuntingapp.RecordDatabaseHelper.getAvaliableDate()' on a null object reference at com.example.asus.accuntingapp.MainViewPagerAdapter.initFragments(MainViewPagerAdapter.java:23) at com.example.asus.accuntingapp.MainViewPagerAdapter.<init>(MainViewPagerAdapter.java:19) at com.example.asus.accuntingapp.MainActivity.onCreate(MainActivity.java:28) at android.app.Activity.performCreate(Activity.java:5933) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)  at android.app.ActivityThread.access$800(ActivityThread.java:144)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)  at android.os.Handler.dispatchMessage(Handler.java:102)  at android.os.Looper.loop(Looper.java:135)  at android.app.ActivityThread.main(ActivityThread.java:5221)  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:899)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)  相关代码: public class MainViewPagerAdapter extends FragmentPagerAdapter { LinkedList<Mainfragment> fragments=new LinkedList<>(); LinkedList<String> dates=new LinkedList<>(); public MainViewPagerAdapter(FragmentManager fm) { super(fm); initFragments(); } private void initFragments(){ dates = GlobalUtil.getInstance().databaseHelper.getAvaliableDate(); if(!dates.contains(DateUtil.getFormattedDate())){ dates.addLast(DateUtil.getFormattedDate()); } for(String date:dates){ Mainfragment fragment=new Mainfragment(date); fragments.add(fragment); } } public void reload(){ for(Mainfragment fragment:fragments){ fragment.reload(); } } public int getLastIndex(){ return fragments.size()-1; } @Override public Fragment getItem(int position) { return fragments.get(position); } @Override public int getCount() { return fragments.size(); } } public class MainActivity extends AppCompatActivity { private TickerView tickerView; private ViewPager viewPager; private MainViewPagerAdapter pagerAdapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); getSupportActionBar().setElevation(0); viewPager=(ViewPager)findViewById(R.id.view_pager); pagerAdapter=new MainViewPagerAdapter(getSupportFragmentManager()); pagerAdapter.notifyDataSetChanged(); viewPager.setAdapter(pagerAdapter); viewPager.setCurrentItem(pagerAdapter.getLastIndex()); findViewById(R.id.fab).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent=new Intent(MainActivity.this,AddRecordActivity.class); startActivityForResult(intent,1); } }); GlobalUtil.getInstance().setContext(getApplicationContext()); LinkedList<String> dates=new LinkedList<>(); dates = GlobalUtil.getInstance().databaseHelper.getAvaliableDate(); Log.d("MainActivity","时间"+dates); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); pagerAdapter.reload(); } } 我在别的地方调用这个getAvaliableDate()方法没问题,在MainViewPagerAdapter类里面的initFragments()方法里面调用getAvaliableDate()就会报空指针。我不知道为什么,望大神赐教!

求大神指导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 ```

android空指针异常,求大神指教,已纠结好几天了。。。

package com.rong.shop.myshop.home; import android.content.Context; import android.support.v4.app.Fragment; import android.os.Bundle; import android.support.v4.view.ViewPager; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.GridView; import android.widget.ImageView; import android.widget.SimpleAdapter; import com.rong.shop.R; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; /** Created by Administrator on 2016/8/13. */ public class MyFragment_home extends Fragment { //ViewPager private ViewPager vpager_one; private ArrayList aList; private Adapter_homeViewPager mAdapter; //GridView private GridView gridview; private ImageView imageview; private Context mcontext = this.getActivity(); private List> listitem; private SimpleAdapter gAdapter; private int[] imgIds; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fg_home, container, false); //ViewPager vpager_one = (ViewPager) view.findViewById(R.id.vpager); aList = new ArrayList(); LayoutInflater li = getLayoutInflater(null); aList.add(li.inflate(R.layout.fg_home_viewpager_view_1, null, false)); aList.add(li.inflate(R.layout.fg_home_viewpager_view_2, null, false)); aList.add(li.inflate(R.layout.fg_home_viewpager_view_3, null, false)); aList.add(li.inflate(R.layout.fg_home_viewpager_view_4, null, false)); aList.add(li.inflate(R.layout.fg_home_viewpager_view_5, null, false)); mAdapter = new Adapter_homeViewPager(aList); vpager_one.setAdapter(mAdapter); //GridView gridview = (GridView)view.findViewById(R.id.gridview); listitem= new ArrayList<>(); imgIds = new int[]{ R.drawable.fg_home_gridview_1, R.drawable.fg_home_gridview_2, R.drawable.fg_home_gridview_3, R.drawable.fg_home_gridview_4, R.drawable.fg_home_gridview_5, R.drawable.fg_home_gridview_6, R.drawable.fg_home_gridview_7, R.drawable.fg_home_gridview_8, }; for (int i = 0; i < imgIds.length; i++) { Map showitem = new HashMap(); showitem.put("image", imgIds[i]); listitem.add(showitem); } gAdapter = new SimpleAdapter(mcontext, listitem, R.layout.fg_home_gridview_item, new String[] { "image" }, new int[]{R.id.gridview_image}); gridview.setAdapter(gAdapter);这里是第75行报错的代码 return view; } } 报错信息是: 09-01 08:49:51.260 22924-22924/? E/AndroidRuntime: FATAL EXCEPTION: main Process: com.rong.shop, PID: 22924 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.rong.shop/com.rong.shop.myshop.home.MainActivity}: java.lang.NullPointerException at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2212) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2271) at android.app.ActivityThread.access$800(ActivityThread.java:144) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1205) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5146) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:732) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:566) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.NullPointerException at android.widget.SimpleAdapter.(SimpleAdapter.java:85) at com.rong.shop.myshop.home.MyFragment_home.onCreateView(MyFragment_home.java:75) at android.support.v4.app.Fragment.performCreateView(Fragment.java:2074) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1286) at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:758) at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1671) at android.support.v4.app.FragmentController.execPendingActions(FragmentController.java:388) at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:619) at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1171) at android.app.Activity.performStart(Activity.java:5241) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2178) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2271) at android.app.ActivityThread.access$800(ActivityThread.java:144) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1205) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5146) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:732) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:566) at dalvik.system.NativeStart.main(Native Method)

安卓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)

AsyncTask 空指针错误, 新手求教

04-08 23:15:21.478: E/BaseActivity(1456): BaseActivity.class :: onCreate() 04-08 23:15:21.488: I/LoginActivity(1456): LoginActivity.class :: onCreate() 04-08 23:15:22.248: E/HttpRequest(1456): Request Url :: http://192.168.1.101:8026/login 04-08 23:15:22.248: E/HttpRequest(1456): Parameters' HashMap :: {password=admin, username=admin} 04-08 23:15:22.538: E/HttpRequest(1456): StatusCode = 200 04-08 23:15:22.548: E/HttpRequest(1456): {"response":"login","userinfo":{"uid":0,"uname":"admin","upass":""}} 04-08 23:15:22.568: E/BaseActivity(1456): Request complete successfully 04-08 23:15:22.998: I/dalvikvm-heap(1456): Grow heap (frag case) to 23.853MB for 6554896-byte allocation 04-08 23:15:23.078: I/dalvikvm(1456): Could not find method android.content.Context.getExternalFilesDirs, referenced from method com.baidu.mapapi.utils.e.c 04-08 23:15:23.078: W/dalvikvm(1456): VFY: unable to resolve virtual method 268: Landroid/content/Context;.getExternalFilesDirs (Ljava/lang/String;)[Ljava/io/File; 04-08 23:15:23.398: I/System.out(1456): admin 04-08 23:15:23.438: I/Choreographer(1456): Skipped 31 frames! The application may be doing too much work on its main thread. 04-08 23:15:41.668: W/dalvikvm(1456): threadid=1: thread exiting with uncaught exception (group=0x4184a898) 04-08 23:15:41.668: E/AndroidRuntime(1456): FATAL EXCEPTION: main 04-08 23:15:41.668: E/AndroidRuntime(1456): java.lang.NullPointerException 04-08 23:15:41.668: E/AndroidRuntime(1456): at com.zwu.navi.BasetoActivity$AT.onPreExecute(BasetoActivity.java:439) 04-08 23:15:41.668: E/AndroidRuntime(1456): at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:586) 04-08 23:15:41.668: E/AndroidRuntime(1456): at android.os.AsyncTask.execute(AsyncTask.java:534) 04-08 23:15:41.668: E/AndroidRuntime(1456): at com.zwu.navi.BasetoActivity$3.onClick(BasetoActivity.java:190) 04-08 23:15:41.668: E/AndroidRuntime(1456): at android.view.View.performClick(View.java:4476) 04-08 23:15:41.668: E/AndroidRuntime(1456): at android.view.View$PerformClick.run(View.java:18799) 04-08 23:15:41.668: E/AndroidRuntime(1456): at android.os.Handler.handleCallback(Handler.java:730) 04-08 23:15:41.668: E/AndroidRuntime(1456): at android.os.Handler.dispatchMessage(Handler.java:92) 04-08 23:15:41.668: E/AndroidRuntime(1456): at android.os.Looper.loop(Looper.java:177) 04-08 23:15:41.668: E/AndroidRuntime(1456): at android.app.ActivityThread.main(ActivityThread.java:5493) 04-08 23:15:41.668: E/AndroidRuntime(1456): at java.lang.reflect.Method.invokeNative(Native Method) 04-08 23:15:41.668: E/AndroidRuntime(1456): at java.lang.reflect.Method.invoke(Method.java:525) 04-08 23:15:41.668: E/AndroidRuntime(1456): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1225) 04-08 23:15:41.668: E/AndroidRuntime(1456): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1041) 04-08 23:15:41.668: E/AndroidRuntime(1456): at dalvik.system.NativeStart.main(Native Method) 04-08 23:16:02.548: I/Process(2064): Sending signal. PID: 2064 SIG: 9 System.out.println(getIntent().getStringExtra("test"));有数据 new AT().execute(getIntent().getStringExtra("test"));出现错误

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

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

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

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

和黑客斗争的 6 天!

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

搜狗输入法也在挑战国人的智商!

故事总是一个接着一个到来...上周写完《鲁大师已经彻底沦为一款垃圾流氓软件!》这篇文章之后,鲁大师的市场工作人员就找到了我,希望把这篇文章删除掉。经过一番沟通我先把这篇文章从公号中删除了...

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

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

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

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

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

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

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

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

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

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

优雅的替换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中级开发(16k)

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

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

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

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

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

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

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

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

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

《Oracle Java SE编程自学与面试指南》最佳学习路线图2020年最新版(进大厂必备)

正确选择比瞎努力更重要!

《Oracle Java SE编程自学与面试指南》最佳学习路线图(2020最新版)

正确选择比瞎努力更重要!

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

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

字节跳动面试官竟然问了我JDBC?

轻松等回家通知

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

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

阿里面试官让我用Zk(Zookeeper)实现分布式锁

他可能没想到,我当场手写出来了

终于,月薪过5万了!

来看几个问题想不想月薪超过5万?想不想进入公司架构组?想不想成为项目组的负责人?想不想成为spring的高手,超越99%的对手?那么本文内容是你必须要掌握的。本文主要详解bean的生命...

自从喜欢上了B站这12个UP主,我越来越觉得自己是个废柴了!

不怕告诉你,我自从喜欢上了这12个UP主,哔哩哔哩成为了我手机上最耗电的软件,几乎每天都会看,可是吧,看的越多,我就越觉得自己是个废柴,唉,老天不公啊,不信你看看…… 间接性踌躇满志,持续性混吃等死,都是因为你们……但是,自己的学习力在慢慢变强,这是不容忽视的,推荐给你们! 都说B站是个宝,可是有人不会挖啊,没事,今天咱挖好的送你一箩筐,首先啊,我在B站上最喜欢看这个家伙的视频了,为啥 ,咱撇...

代码注释如此沙雕,会玩还是你们程序员!

某站后端代码被“开源”,同时刷遍全网的,还有代码里的那些神注释。 我们这才知道,原来程序员个个都是段子手;这么多年来,我们也走过了他们的无数套路… 首先,产品经理,是永远永远吐槽不完的!网友的评论也非常扎心,说看这些代码就像在阅读程序员的日记,每一页都写满了对产品经理的恨。 然后,也要发出直击灵魂的质问:你是尊贵的付费大会员吗? 这不禁让人想起之前某音乐app的穷逼Vip,果然,穷逼在哪里都是...

立即提问
相关内容推荐