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)

10个回答

你的创建方法中缺少setContentView(R.layout.?);
没有设置此activity与之关联的显示页面,所以listview查找不到

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//这里加上 setContentView(R.layout.?);
mListView = (ListView) findViewById(R.id.list_contact);
ArrayAdapter adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, contactList);
mListView.setAdapter(adapter);
readContacts();
}

clean一下工程,代码应该没问题,感觉像是地址映射错误,找不到listview。

可能出错的是读取联系人的方法,你直接复制安卓源码中的联系人的方法重新试试,应该就不会读取数据出错

没有加入布局 setContentView
所以会找不到控件

这个。新建一个Activity你没有对应的加入布局啊,这个方法呢:
setContentView(),太粗心了

setContentView("布局文件"); 这个都没有 肯定报错啊

setContentView

谢谢了,的确是没有绑定视图的原因。按回答顺序采纳了。

谢谢大家了,昨天晚上弄了好久

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

![图片说明](https://img-ask.csdn.net/upload/201908/17/1566049082_240434.png) ![图片说明](https://img-ask.csdn.net/upload/201908/17/1566048986_150068.png) 这个空指针异常是什么意思 求解 各位大佬 感谢

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

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)

android 混淆后所有的Adapter里个getview都空指针了

01-06 21:02:55.407: E/AndroidRuntime(1914): java.lang.NullPointerException 01-06 21:02:55.407: E/AndroidRuntime(1914): at fxyy.lx.gqj.a.af.getView(Unknown Source) 01-06 21:02:55.407: E/AndroidRuntime(1914): at android.widget.AbsListView.obtainView(AbsListView.java:2255) 01-06 21:02:55.407: E/AndroidRuntime(1914): at android.widget.ListView.measureHeightOfChildren(ListView.java:1263) 01-06 21:02:55.407: E/AndroidRuntime(1914): at android.widget.ListView.onMeasure(ListView.java:1175) 01-06 21:02:55.407: E/AndroidRuntime(1914): at android.view.View.measure(View.java:16505) 01-06 21:02:55.407: E/AndroidRuntime(1914): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125) 01-06 21:02:55.407: E/AndroidRuntime(1914): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404) 01-06 21:02:55.407: E/AndroidRuntime(1914): at android.widget.LinearLayout.measureVertical(LinearLayout.java:695) 01-06 21:02:55.407: E/AndroidRuntime(1914): at android.widget.LinearLayout.onMeasure(LinearLayout.java:588) 01-06 21:02:55.407: E/AndroidRuntime(1914): at android.view.View.measure(View.java:16505) 01-06 21:02:55.407: E/AndroidRuntime(1914): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125) 01-06 21:02:55.407: E/AndroidRuntime(1914): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404) 01-06 21:02:55.407: E/AndroidRuntime(1914): at android.widget.LinearLayout.measureVertical(LinearLayout.java:695) 01-06 21:02:55.407: E/AndroidRuntime(1914): at android.widget.LinearLayout.onMeasure(LinearLayout.java:588) 01-06 21:02:55.407: E/AndroidRuntime(1914): at android.view.View.measure(View.java:16505) 01-06 21:02:55.407: E/AndroidRuntime(1914): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125) 01-06 21:02:55.407: E/AndroidRuntime(1914): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310) 01-06 21:02:55.407: E/AndroidRuntime(1914): at android.view.View.measure(View.java:16505) 01-06 21:02:55.407: E/AndroidRuntime(1914): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125) 01-06 21:02:55.407: E/AndroidRuntime(1914): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404) 01-06 21:02:55.407: E/AndroidRuntime(1914): at android.widget.LinearLayout.measureVertical(LinearLayout.java:695) 01-06 21:02:55.407: E/AndroidRuntime(1914): at android.widget.LinearLayout.onMeasure(LinearLayout.java:588) 01-06 21:02:55.407: E/AndroidRuntime(1914): at android.view.View.measure(View.java:16505) 01-06 21:02:55.407: E/AndroidRuntime(1914): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125) 01-06 21:02:55.407: E/AndroidRuntime(1914): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310) 01-06 21:02:55.407: E/AndroidRuntime(1914): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2294) 01-06 21:02:55.407: E/AndroidRuntime(1914): at android.view.View.measure(View.java:16505) 01-06 21:02:55.407: E/AndroidRuntime(1914): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125) 01-06 21:02:55.407: E/AndroidRuntime(1914): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404) 01-06 21:02:55.407: E/AndroidRuntime(1914): at android.widget.LinearLayout.measureVertical(LinearLayout.java:695) 01-06 21:02:55.407: E/AndroidRuntime(1914): at android.widget.LinearLayout.onMeasure(LinearLayout.java:588) 01-06 21:02:55.407: E/AndroidRuntime(1914): at android.view.View.measure(View.java:16505) 01-06 21:02:55.407: E/AndroidRuntime(1914): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125) 01-06 21:02:55.407: E/AndroidRuntime(1914): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404) 01-06 21:02:55.407: E/AndroidRuntime(1914): at android.widget.LinearLayout.measureVertical(LinearLayout.java:695) 01-06 21:02:55.407: E/AndroidRuntime(1914): at android.widget.LinearLayout.onMeasure(LinearLayout.java:588) 01-06 21:02:55.407: E/AndroidRuntime(1914): at android.view.View.measure(View.java:16505) 01-06 21:02:55.407: E/AndroidRuntime(1914): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125) 01-06 21:02:55.407: E/AndroidRuntime(1914): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310) 01-06 21:02:55.407: E/AndroidRuntime(1914): at android.view.View.measure(View.java:16505) 01-06 21:02:55.407: E/AndroidRuntime(1914): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125) 01-06 21:02:55.407: E/AndroidRuntime(1914): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404) 01-06 21:02:55.407: E/AndroidRuntime(1914): at android.widget.LinearLayout.measureVertical(LinearLayout.java:695) 01-06 21:02:55.407: E/AndroidRuntime(1914): at android.widget.LinearLayout.onMeasure(LinearLayout.java:588) 01-06 21:02:55.407: E/AndroidRuntime(1914): at android.view.View.measure(View.java:16505) 01-06 21:02:55.407: E/AndroidRuntime(1914): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125) 01-06 21:02:55.407: E/AndroidRuntime(1914): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310) 01-06 21:02:55.407: E/AndroidRuntime(1914): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2294) 01-06 21:02:55.407: E/AndroidRuntime(1914): at android.view.View.measure(View.java:16505) 01-06 21:02:55.407: E/AndroidRuntime(1914): at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1912) 01-06 21:02:55.407: E/AndroidRuntime(1914): at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1109) 01-06 21:02:55.407: E/AndroidRuntime(1914): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1291) 01-06 21:02:55.407: E/AndroidRuntime(1914): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:996) 01-06 21:02:55.407: E/AndroidRuntime(1914): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5600) 01-06 21:02:55.407: E/AndroidRuntime(1914): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:771) 01-06 21:02:55.407: E/AndroidRuntime(1914): at android.view.Choreographer.doCallbacks(Choreographer.java:574) 01-06 21:02:55.407: E/AndroidRuntime(1914): at android.view.Choreographer.doFrame(Choreographer.java:544) 01-06 21:02:55.407: E/AndroidRuntime(1914): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:757) 01-06 21:02:55.407: E/AndroidRuntime(1914): at android.os.Handler.handleCallback(Handler.java:733) 01-06 21:02:55.407: E/AndroidRuntime(1914): at android.os.Handler.dispatchMessage(Handler.java:95) 01-06 21:02:55.407: E/AndroidRuntime(1914): at a 各位前辈,请指教

RecyclerView 的onBindViewHolder出现空指针异常

package com.example.haha.note; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; import java.util.ArrayList; import java.util.List; import java.util.Random; /** * Created by haha on 2017/9/8. */ public class NotesTitleFragment extends Fragment { private boolean isTwoPane; public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){ View view=inflater.inflate(R.layout.notes_title_frag,container,false); RecyclerView noteTitleRecyclerView=(RecyclerView) view.findViewById(R.id.notes_title_recycler_view); LinearLayoutManager layoutManager=new LinearLayoutManager(getActivity()); noteTitleRecyclerView.setLayoutManager(layoutManager); NoteAdapter adapter=new NoteAdapter(getNote()); noteTitleRecyclerView.setAdapter(adapter); return view; } private List<notes> getNote(){ List<notes> notesList=new ArrayList<>(); for(int i=1;i<=50;i++){ notes note=new notes(); note.setTitle("This is title" + i); note.setContent(getRandomLengthContent("This is note content"+i+".")); notesList.add(note); } return notesList; } private String getRandomLengthContent(String content){ Random random=new Random(); int length=random.nextInt(20)+1; StringBuilder builder=new StringBuilder(); for(int i=0;i<length;i++){ builder.append(content); } return builder.toString(); } public void onActivityCreated(Bundle savedInstanceState){ super.onActivityCreated(savedInstanceState); if(getActivity().findViewById(R.id.notes_content_layout) !=null){ isTwoPane=true; } else isTwoPane=false; } class NoteAdapter extends RecyclerView.Adapter<NoteAdapter.ViewHolder>{ private List<notes> mNoteList; class ViewHolder extends RecyclerView.ViewHolder{ TextView noteTitleText; public ViewHolder(View view){ super(view); noteTitleText=(TextView) view.findViewById(R.id.note_title); } } public NoteAdapter(List<notes> notesList){ mNoteList=notesList; } @Override public ViewHolder onCreateViewHolder(ViewGroup parent,int viewType){ View view=LayoutInflater.from(parent.getContext()).inflate(R.layout.notes_item,parent,false); final ViewHolder holder=new ViewHolder(view); view.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { notes note=mNoteList.get(holder.getAdapterPosition()); if(isTwoPane){ NotesContentFragment notesContentFragment=(NotesContentFragment) getFragmentManager().findFragmentById(R.id.notes_content_fragment); notesContentFragment.refresh(note.getTitle(),note.getContent()); }else { notesContentActivity.actionStart(getActivity(),note.getTitle(),note.getContent()); } } }); return holder; } public void onBindViewHolder(ViewHolder holder,int position){ notes note=mNoteList.get(position); holder.noteTitleText.setText(note.getTitle()); } public int getItemCount(){ return mNoteList.size(); } } } 看了很多网上得解决办法还是没解决问题,小白求教

myList.setAdapter(adapter);报空指针异常。

//初始化view private void initView() { list = new ArrayList<MusicInfo>(); //把扫描到的音乐赋值给list list = com.example.music.MusicUtil.getMp3Infos(this);//此处可获得数据 adapter = new com.example.music.MusicListAdapter(this,list); myList.setAdapter(adapter); mediaPlayer = new MediaPlayer(); myList.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { //创建一个播放音频的方法,把点击到的地址传过去 //list.get(i).path这个就是歌曲的地址 play(list.get(i).getUrl()); } }); }

RecyclerView adapter.addAll的空指针问题

这次用了别人封装的RecyclerView,自己又将其封装了一下 public void addDataThenNotify(List<E> list){ LogUtil.i("dat", "..." +adapter); adapter.addAll(list); adapter.notifyDataSetChanged(); } 这是其中的一段代码,负责向adapter里添加list 但android studio在“adapter.addAll()”这里报空指针,同时我确定adapter、list绝非为空, 而它的size(),也为等同传进去的size(),adapter

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; } } 如何出现的这个异常啊?

Android中的RecyclerView空指针异常

``` Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.widget.RecyclerView.setLayoutManager(android.support.v7.widget.RecyclerView$LayoutManager)' on a null object reference ``` 网上说是没有设置布局管理器,我设置了 还是报这个异常 ``` //设置RecyclerView的布局管理: LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this,LinearLayoutManager.HORIZONTAL,false); //上面的属性为(this,orientation,reverseLayout)上面使用垂直属性 mRecyclerView.setLayoutManager(linearLayoutManager); ```

安卓的intent报出空指针异常

当使用intent的时候报出NullPoiterException,具体是在调用这行代码的时候: int posizione2 =Integer.parseInt((getIntent().getExtras().getString(Intent.EXTRA_TEXT))); 请多指教!谢谢 private void aggiungiImm(View arg1, int arg2) { Intent i=newintent(Intent.ACTION_PICK,ContactsContract.Contacts.CONTENT_URI); i.putExtra(Intent.EXTRA_TEXT, Integer.toString(arg2)); startActivityForResult(i, PICK_REQUEST); } @Override protected void onActivityResult(int requestCode, int resultCode,Intent data) { Uri contactData=null; if (requestCode==PICK_REQUEST) { if (resultCode==RESULT_OK) { contactData=data.getData(); int posizione2 =Integer.parseInt((getIntent().getExtras().getString(Intent.EXTRA_TEXT))); 错误是不是和intent是隐式有关?

Android ListView 自定义Adapter 滑动时报空指针异常

问题背景:在制作一个即时聊天的APP中,聊天界面聊天消息的显示我使用了ListView,并且使用了自定义的Adapter,获取到聊天记录之后ListView可以正常显示,但是一旦滑动就会报空指针异常。我查看了很多博客,都没有提到与这个相关或者类似的错误已经被这个错误逼疯了,希望有了解的大神能够给予指点。 具体相关代码如下: 自定义的Adapter: ``` public class ChatMessageAdapter extends BaseAdapter { private LayoutInflater layoutInflater; private List<MessageShow> messageShowList; public ChatMessageAdapter(Context context, List<MessageShow> messageShowList){ layoutInflater = LayoutInflater.from(context); this.messageShowList = messageShowList; } @Override public int getCount() { return messageShowList.size(); } @Override public Object getItem(int position) { return messageShowList.get(position); } @Override public int getItemViewType(int position) { if(messageShowList.get(position).getMessageType()==0) return 0; else return 1; } //Item类型的总数 @Override public int getViewTypeCount() { return 2; } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { MessageShow messageShow = messageShowList.get(position); ViewHolder viewHolder = null; if(convertView == null){ if(messageShow.getMessageType() == 0){ convertView = layoutInflater.inflate(R.layout.from_message_item,null); viewHolder = new ViewHolder(); // viewHolder.imageView = (ImageView) convertView.findViewById(R.id.from_user_icons); viewHolder.time = (TextView) convertView.findViewById(R.id.from_time); viewHolder.message = (TextView) convertView.findViewById(R.id.from_message); } else{ convertView = layoutInflater.inflate(R.layout.to_message_item,null); viewHolder = new ViewHolder(); // viewHolder.imageView = (ImageView) convertView.findViewById(R.id.to_user_icons); viewHolder.time = (TextView) convertView.findViewById(R.id.to_time); viewHolder.message = (TextView) convertView.findViewById(R.id.to_message); } } else { viewHolder = (ViewHolder) convertView.getTag(); } System.out.println("我到了这里"+position); System.out.println("我添加了适配器: "+messageShow.getContents()); // viewHolder.imageView.setImageResource(R.drawable.photo); //报空指针异常的是这里 viewHolder.message.setText(messageShow.getContents()); viewHolder.time.setText(messageShow.getTime()); return convertView; } private final class ViewHolder{ // ImageView imageView; TextView time; TextView message; } ``` ,ChatActivity代码如下: ``` private List<MessageShow> showMessageList; private ChatMessageAdapter chatMessageAdapter; 、、、省略无关 //初始化数据 private void initData(){ showMessageList = new ArrayList<MessageShow>(); chatMessageAdapter = new ChatMessageAdapter(this,showMessageList); listView.setAdapter(chatMessageAdapter); getMessageRecord(); chatMessageAdapter.notifyDataSetChanged(); } ``` 其中获取聊天记录我已经在控制台打印出来检查过了,没有错误,而ListView能够显示说明Apapter也不会有基本的错误,但是还是报空指针。我对错误的猜测如下: 虽然给的数据集可能有几十项,但是Adapter加载的时候只加载了当前显示的几项,后面的没加载,等我我滑动之后去加载的时候没加载到数据就报空指针了。但是这不太科学啊,我看了好多博客发现都没有专门说到这点,仔细检查代码也不知道应该怎么改,求指教。报错信息如下: ``` I/System.out: 我到了这里1 I/System.out: 我添加了适配器: 图片这些不能点击? I/System.out: 我到了这里2 I/System.out: 我添加了适配器: 还没做那些功能呢233 I/System.out: 我到了这里3 I/System.out: 我添加了适配器: 图片和表情 I/System.out: 我到了这里4 I/System.out: 我添加了适配器: 额 I/System.out: 我到了这里5 I/System.out: 我添加了适配器: 准备等APP开发完之后再说 I/System.out: 我到了这里6 I/System.out: 我添加了适配器: 真的挺费脑的 I/System.out: 我到了这里7 I/System.out: 我添加了适配器: 嗯 加油 E/InputEventReceiver: Exception dispatching input event. D/AndroidRuntime: Shutting down VM W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0xa6160908) E/AndroidRuntime: FATAL EXCEPTION: main java.lang.NullPointerException at cn.justwithme.withme.Adapaer.ChatMessageAdapter$override.getView(ChatMessageAdapter.java:84) at cn.justwithme.withme.Adapaer.ChatMessageAdapter$override.access$dispatch(ChatMessageAdapter.java) at cn.justwithme.withme.Adapaer.ChatMessageAdapter.getView(ChatMessageAdapter.java:0) ``` 本来有十几项的,第一页只有7项,我在Adapter的输出就只出输出了7项。 ![图片说明](https://img-ask.csdn.net/upload/201702/19/1487495789_116858.png) ![图片说明](https://img-ask.csdn.net/upload/201702/19/1487495801_419892.png)

andriod gridview 空指针异常

package com.example.weishi03; import android.app.Activity; import android.app.AlertDialog; import android.content.Intent; import android.os.Bundle; import android.text.TextUtils; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.BaseAdapter; import android.widget.Button; import android.widget.EditText; import android.widget.GridView; import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast; import com.example.weishi03.utils.Md5; import com.example.weishi03.utils.MyConstant; import com.example.weishi03.utils.SpTool; public class HomeActivity extends Activity { private int[] icons = {R.drawable.one,R.drawable.two,R.drawable.three, R.drawable.four,R.drawable.five,R.drawable.six, R.drawable.seven,R.drawable.eight,R.drawable.nine}; private String[] names = {"one","two","three","four","five","six","seven","eight","nine"}; private GridView gv; private MyAdapter adapter; private AlertDialog dialog; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); initView(); initData(); initEvent(); } private void initEvent() { gv.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { switch (position) { case 0: if (TextUtils.isEmpty(SpTool.getString(getApplicationContext(), MyConstant.PASSWORD, ""))){ showSetPassWord(); }else { showEnterPassWord(); } break; default: break; } } }); } protected void showEnterPassWord() { AlertDialog.Builder ab = new AlertDialog.Builder(this); View view =View.inflate(getApplicationContext(), R.layout.dialog_enterpass, null); final EditText pass = (EditText) findViewById(R.id.et_dialogenterpassword_pass); Button confim = (Button) findViewById(R.id.bt_dialogenterpassword_confim); Button cancel = (Button) findViewById(R.id.bt_dialogenterpassword_cancel); ab.setView(view); confim.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { String passWord = pass.getText().toString(); String truePass = SpTool.getString(getApplicationContext(), MyConstant.PASSWORD, ""); passWord = Md5.md5(Md5.md5(passWord)); if (passWord == null || passWord != truePass ) { Toast.makeText(getApplicationContext(), "Wrong pass", 1).show(); return; }else { Intent intent = new Intent(HomeActivity.this,LostFindActivity.class); startActivity(intent); } dialog.dismiss(); } }); cancel.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); } }); dialog = ab.create(); dialog.show(); } protected void showSetPassWord() { AlertDialog.Builder ab = new AlertDialog.Builder(this); View view = View.inflate(getApplicationContext(), R.layout.dialog_setpass, null); final EditText et_passone = (EditText) findViewById(R.id.et_dialogsetpass_passone); final EditText et_passtwo = (EditText) findViewById(R.id.et_dialogsetpass_passtwo); Button bt_confim = (Button) findViewById(R.id.bt_dialogsetpass_confim); Button bt_cancel = (Button) findViewById(R.id.bt_dialogsetpass_cancel); ab.setView(view); bt_confim.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { String passone = et_passone.getText().toString().trim(); String passtwo = et_passtwo.getText().toString().trim(); if (passone.equals("") || passtwo.equals("")) { Toast.makeText(getApplicationContext(), "Pass is null", 1).show(); return; }else if (!passone.equals(passtwo)) { Toast.makeText(getApplicationContext(), "Pass is nu", 1).show(); return; }else { passone = Md5.md5(Md5.md5(passone)); SpTool.putString(getApplicationContext(), MyConstant.PASSWORD, passone); dialog.dismiss(); } } }); bt_cancel.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); } }); dialog = ab.create(); dialog.show(); } private void initData() { adapter = new MyAdapter(); gv.setAdapter(adapter); } private class MyAdapter extends BaseAdapter{ @Override public int getCount() { return icons.length; } @Override public View getView(int position, View convertView, ViewGroup parent) { View view = View.inflate(getBaseContext(), R.layout.item_gridview, null); ImageView iv = (ImageView) findViewById(R.id.iv_item_gridview_icon); TextView tv = (TextView) findViewById(R.id.tv_item_gridview_name); iv.setImageResource(icons[position]); tv.setText(names[position]); return view; } @Override public Object getItem(int position) { // TODO Auto-generated method stub return null; } @Override public long getItemId(int position) { // TODO Auto-generated method stub return 0; } } private void initView() { setContentView(R.layout.activity_home); gv = (GridView) findViewById(R.id.gv_home_gridview); } } 上面的代码我是按照视频里敲的,但是在 iv.setImageResource(icons[position]);这里报空指针异常,我该怎么改?

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中重写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中重写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) ```

安卓开发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空指针异常,求大神指教,已纠结好几天了。。。

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)

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

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

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

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

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

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

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

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

和黑客斗争的 6 天!

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

点沙成金:英特尔芯片制造全过程揭密

“亚马逊丛林里的蝴蝶扇动几下翅膀就可能引起两周后美国德州的一次飓风……” 这句人人皆知的话最初用来描述非线性系统中微小参数的变化所引起的系统极大变化。 而在更长的时间尺度内,我们所生活的这个世界就是这样一个异常复杂的非线性系统…… 水泥、穹顶、透视——关于时间与技艺的蝴蝶效应 公元前3000年,古埃及人将尼罗河中挖出的泥浆与纳特龙盐湖中的矿物盐混合,再掺入煅烧石灰石制成的石灰,由此得来了人...

讲一个程序员如何副业月赚三万的真实故事

loonggg读完需要3分钟速读仅需 1 分钟大家好,我是你们的校长。我之前讲过,这年头,只要肯动脑,肯行动,程序员凭借自己的技术,赚钱的方式还是有很多种的。仅仅靠在公司出卖自己的劳动时...

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

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

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

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

副业收入是我做程序媛的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.现在的日子也不是很如意。否则应该就不会纠结了。 老实说,松哥之前也有过类似的经历,今天就来和小伙伴们聊聊回头草到底吃不吃。 首先一个基本观点,就是离职了也没必要和老东家弄的苦...

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

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

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

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

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

二哥,有个事想询问下您的意见,您觉得应届生值得去外包吗?公司虽然挺大的,中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多个条件是什么逻辑关系?条件判断在什么时候执...

你打算用Java 8一辈子都不打算升级到Java 14,真香

我们程序员应该抱着尝鲜、猎奇的心态,否则就容易固步自封,技术停滞不前。

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

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

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

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

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

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

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

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

《经典算法案例》01-08:如何使用质数设计扫雷(Minesweeper)游戏

我们都玩过Windows操作系统中的经典游戏扫雷(Minesweeper),如果把质数当作一颗雷,那么,表格中红色的数字哪些是雷(质数)?您能找出多少个呢?文中用列表的方式罗列了10000以内的自然数、质数(素数),6的倍数等,方便大家观察质数的分布规律及特性,以便对算法求解有指导意义。另外,判断质数是初学算法,理解算法重要性的一个非常好的案例。

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

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

一文带你入门Java Stream流,太强了

两个星期以前,就有读者强烈要求我写一篇 Java Stream 流的文章,我说市面上不是已经有很多了吗,结果你猜他怎么说:“就想看你写的啊!”你看你看,多么苍白的喜欢啊。那就“勉为其难”写一篇吧,嘻嘻。 单从“Stream”这个单词上来看,它似乎和 java.io 包下的 InputStream 和 OutputStream 有些关系。实际上呢,没毛关系。Java 8 新增的 Stream 是为...

立即提问
相关内容推荐