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

是这样的。我是在做一个相当于一个手机卫士,里面有通讯录和黑名单两个功能。这个代码是我做的黑名单里的。图片说明 想实现的功能是点黑名单按钮,可以出现这个黑名单的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 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)

9个回答

初始化适配器的时候,数据源data是空的,
adapter = new BlackNumberAdapter();
要放在
dao = new BlackNumberDao(this);
data = dao.getAll();
的下面

convertView = View.inflate(Stop.this,android.R.layout.simple_list_item_1,null); 这一行有问题,改为
convertView = Layoutinflater.form(context).inflate(Stop.this,android.R.layout.simple_list_item_1,null);

qq_39205783
qq_39205783 大神你好!我不懂你这个代码的意思,但是我复制了进去 发现也是报错的,而且我不知道怎么解决。我才刚学,不好意思啊。
2 年多之前 回复

convertView = View.inflate(Stop.this,android.R.layout.simple_list_item_1,null);
我也认为是这一行的错误

HuoHao_Blogs
huohao-nicole 回复qq_39205783: convertView = Layoutinflater.form(context).inflate(布局文件资源,parent,false);
2 年多之前 回复
qq_39205783
qq_39205783 请问是哪里错了呢,我才刚学,有点不明白
2 年多之前 回复

listview在设置adapter的时候出现了空指针,你看看你的listview是不是没有获取到,是不是空。

即iv_main = (ListView) findViewById(R.id.iv_main);这句话以后即iv_main是不是空。

看看布局文件有没有写错,activity_main里面有没有id为iv_main的listview控件

zengxianzi
昭杏之念 回复qq_39205783: 那你的 setContentView(R.layout.activity_main);就应该改成 setContentView(R.layout.activity_stop);啊
2 年多之前 回复
qq_39205783
qq_39205783 我写在了activity_stop里 没有写在activity_main里,我想做的这个相当于一个手机卫士,黑名单stop是我想实现的其中一个功能。
2 年多之前 回复

是这样的。我是在做一个相当于一个手机卫士,里面有通讯录和黑名单两个功能。这个代码是我做的黑名单里的。图片说明 想实现的功能是点黑名单按钮,可以出现这个黑名单的Activity。通讯录做了一个Listview,点通讯录按钮,可以导入系统通讯录,然后设置点击监听,长按item可以发短信,点击可以打电话。

现在的问题是,无论是通讯录还是黑名单,一点按钮就报错,报错的内容就是空指针。不知道怎么觉得。哭唧唧。

你findvie完了之后打印下iv_main这个变量是不是null

断点调试,是开发必要技能,在报空地方打断点 ,定位问题,在仔细招待码的问题。

楼上正解,是data的问题,

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
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 adapter 空指针
adapter 中的gerCount 方法里的 返回集合长度 报错 。请指点出有什么原因
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,求大神指点!!!
安卓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提示空指针异常情况
主要代码如下: 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空指针异常,求大神指教,已纠结好几天了。。。
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<View> aList; private Adapter_homeViewPager mAdapter; //GridView private GridView gridview; private ImageView imageview; private Context mcontext = this.getActivity(); private List<Map<String,Object>> 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<View>(); 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<String, Object> showitem = new HashMap<String, Object>();这里是第七十行报错的代码 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); return view; } } 报错信息是 Caused by: java.lang.NullPointerException at com.rong.shop.myshop.home.MyFragment_home.onCreateView(MyFragment_home.java:70)
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
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)
Android空指针问题,该实例化的都实例化了额。。。
求大神帮忙运行一下,分析一下原因,我后面把书里的源码也拉来试了一下,还是报空指针。感觉似乎是Cursor的原因,求大神指点!谢谢!! ``` package com.example.marcus.groupsend; import android.app.Activity; import android.app.PendingIntent; import android.content.DialogInterface; import android.content.Intent; import android.database.Cursor; import android.provider.ContactsContract; import android.support.v7.app.AlertDialog; import android.os.Bundle; import android.telephony.SmsManager; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.Button; import android.widget.CheckBox; import android.widget.EditText; import android.widget.ListView; import android.widget.Toast; import java.util.ArrayList; public class MainActivity extends Activity { Button select,send; EditText numbers,content; SmsManager smsManager; ArrayList<String> phoneNumbers = new ArrayList<>(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); numbers = (EditText) findViewById(R.id.numbers); content = (EditText) findViewById(R.id.content); smsManager = SmsManager.getDefault(); send = (Button) findViewById(R.id.send); select = (Button) findViewById(R.id.select); //发送信息 send.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { PendingIntent pi = PendingIntent.getActivity(MainActivity.this,0,new Intent(),0); for (String number : phoneNumbers){ smsManager.sendTextMessage(number,null,content.getText().toString(),pi,null); } Toast.makeText(MainActivity.this,"群发成功!",Toast.LENGTH_SHORT).show(); } }); //选择群发号码,采用复选框方式 select.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //获取到系统联系人 final Cursor cursor = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, null); BaseAdapter adapter = new BaseAdapter() { @Override public int getCount() { return cursor.getCount(); } @Override public Object getItem(int position) { return position; } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { cursor.moveToPosition(position); //使用复选框 CheckBox checkBox = new CheckBox(MainActivity.this); //获取当前位置选中的号码,并去掉空格和-,然后加入到checkBox中 String number = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)) .replace("-","") .replace(" ",""); checkBox.setText(number); if (isChecked(number)){ checkBox.setChecked(true); } //返还一个复选框视图 return checkBox; } }; View selectView = getLayoutInflater().inflate(R.layout.list,null); final ListView list = (ListView) selectView.findViewById(R.id.list); list.setAdapter(adapter); //利用对话框来加载View,View中是一个复选框列表 new AlertDialog.Builder(MainActivity.this).setView(selectView). setPositiveButton("确定", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { //先将phoneNumbers里面清空 phoneNumbers.clear(); //遍历list里面的各个条目,如果是打勾的就加到这个phoneNumbers列表里 for (int i=0; i<list.getCount(); i++){ CheckBox check = (CheckBox)list.getChildAt(i); if (check.isChecked()){ phoneNumbers.add(check.getText().toString()); } } //最终全部加到这个列表中,并在send里遍历各个号码,然后实现群发功能 numbers.setText(phoneNumbers.toString()); } }).show(); } }); } //判断某个号码是否在群发范围内 public boolean isChecked(String number) { for (String s : phoneNumbers){ if (s.equals(number)){ return true; } } return false; } } ``` 以下是我的两个xml文件 ## main.xml ``` <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content"> <EditText android:id="@+id/numbers" android:layout_weight="8" android:layout_width="0dp" android:layout_height="wrap_content" /> <Button android:id="@+id/select" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="select"/> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <EditText android:id="@+id/content" android:layout_weight="8" android:layout_width="0dp" android:layout_height="wrap_content" /> <Button android:id="@+id/send" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="send"/> </LinearLayout> </LinearLayout> ``` ## list.xml ``` <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <ListView android:id="@+id/list" android:layout_width="wrap_content" android:layout_height="wrap_content"/> </LinearLayout> ```
求大神 android搜索Mysql的内容,int java.util.List.size()错误
安卓开发初学者,本想做一个能搜索数据的小程序, 但是就各种不顺利,帮忙看看哪里出现了错误。 开发环境 Android Studio 3.5.2+XAMPP 3.2.4(Mysql+Apache)+PHP 错误信息 ``` 2019-11-29 14:04:26.591 1398-1398/com.uchiyama.livesearch E/AndroidRuntime: FATAL EXCEPTION: main Process: com.uchiyama.livesearch, PID: 1398 java.lang.NullPointerException: Attempt to invoke interface method 'int java.util.List.size()' on a null object reference at com.uchiyama.livesearch.Adapter.getItemCount(Adapter.java:39) at androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep1(RecyclerView.java:4044) at androidx.recyclerview.widget.RecyclerView.onMeasure(RecyclerView.java:3534) at android.view.View.measure(View.java:19785) at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:715) at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461) at android.view.View.measure(View.java:19785) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6120) at android.widget.FrameLayout.onMeasure(FrameLayout.java:185) at androidx.appcompat.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:143) at android.view.View.measure(View.java:19785) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6120) at androidx.appcompat.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:403) at android.view.View.measure(View.java:19785) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6120) at android.widget.FrameLayout.onMeasure(FrameLayout.java:185) at android.view.View.measure(View.java:19785) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6120) at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1464) at android.widget.LinearLayout.measureVertical(LinearLayout.java:758) at android.widget.LinearLayout.onMeasure(LinearLayout.java:640) at android.view.View.measure(View.java:19785) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6120) at android.widget.FrameLayout.onMeasure(FrameLayout.java:185) at com.android.internal.policy.DecorView.onMeasure(DecorView.java:690) at android.view.View.measure(View.java:19785) at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2275) at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1362) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1611) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1250) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6311) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:871) at android.view.Choreographer.doCallbacks(Choreographer.java:683) at android.view.Choreographer.doFrame(Choreographer.java:619) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:857) at android.os.Handler.handleCallback(Handler.java:751) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:241) at android.app.ActivityThread.main(ActivityThread.java:6217) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) ``` 我的代码 ``` package com.uchiyama.livesearch; import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView; import java.util.List; public class Adapter extends RecyclerView.Adapter<Adapter.MyViewHolder> { private List<Users> users; private Context context; public Adapter(List<Users> users, Context context) { this.users = users; this.context = context; } @Override public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.item,parent,false); return new MyViewHolder(view); } @Override public void onBindViewHolder(MyViewHolder holder, int position) { holder.name.setText(users.get(position).getName()); holder.email.setText(users.get(position).getEmail()); } @Override public int getItemCount() { return users.size(); //在这里报错 } public static class MyViewHolder extends RecyclerView.ViewHolder { TextView name,email; public MyViewHolder(View itemView) { super(itemView); name=itemView.findViewById(R.id.name); email=itemView.findViewById(R.id.email); } } } ```
android程序,报空指针,自己陷入思维僵局了。谁来看看,应该不难。
android程序,这个界面显示的是手机联系人,在我们平台注册过的联系人显示在最前面。这是adapter中的代码,我感觉逻辑没什么问题,但是在把mList中的几个数据显示完后,在显示非注册用户的时候报了空指针。 Contact是个bean,mList是注册过的手机联系人,list是所有的手机联系人。我要让注册过的显示在列表最上面。viewHolder.tv_name.setText(contact.getName()); 这句报了空指针。 public View getView(int position, View convertView, ViewGroup parent) { final Contact contact ; ViewHolder viewHolder ; if (convertView == null) { viewHolder = new ViewHolder() ; convertView = LayoutInflater.from(activity).inflate( R.layout.item_addphone_contact, null); viewHolder.tv_name = (TextView) convertView.findViewById(R.id.tv_name); viewHolder. tv_state = (FriendStateBtn) convertView.findViewById(R.id.tv_add); viewHolder.tv_phone = (TextView) convertView.findViewById(R.id.tv_phone); viewHolder.user_image = (ImageView) convertView .findViewById(R.id.user_image); viewHolder.sort_key_layout = (RelativeLayout) convertView .findViewById(R.id.sort_key_layout); viewHolder.sort_key = (TextView) convertView.findViewById(R.id.sort_key_item); viewHolder.tv_state.setOnClickListener(null); convertView.setTag(viewHolder); }else{ viewHolder = (ViewHolder) convertView.getTag(); } if(position < mList.size()){ //显示注册过的联系人 contact = getContact(mList.get(position).getMember_phone()); if (contact!=null) { list.remove(contact); notifyDataSetChanged(); } }else{ contact = list.get(position-mList.size()); } //在mList中的数据取完后,在取list数据时报了空指针 viewHolder.tv_name.setText(contact.getName()); viewHolder.tv_phone.setText(contact.getNumber().replace(" ", "")); if(position<mList.size()){ if (mList.get(position).getIsFriend().equals("1")) { viewHolder.tv_state.setText("已是好友"); viewHolder.tv_state.setState(FriendStateBtn.State.added); } else { viewHolder.tv_state.setText("添加"); viewHolder.tv_state.setState(FriendStateBtn.State.add); contact.setMember_id(mList.get(position).getMember_id()); } }else { viewHolder.tv_state.setText("邀请"); viewHolder.tv_state.setState(FriendStateBtn.State.invent); } viewHolder.tv_state.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (TextUtils.isEmpty(contact.getMember_id())) { Tools.sendSMS(activity, contact.getNumber().replace(" ", ""), ""); } else { initHttp(contact); } } }); int section = indexer.getSectionForPosition(position); if(position == indexer.getPositionForSection(section)){ viewHolder.sort_key.setText(contact.getSortKey()); viewHolder.sort_key_layout.setVisibility(View.VISIBLE); }else{ viewHolder.sort_key_layout.setVisibility(View.GONE); } return convertView; } private Contact getContact(String member){ for(int i=0;i<list.size();i++){ String number = list.get(i).getNumber().replace("+86","").replace("-",""); if(member.equals(number)){ return list.get(i); } } return null; }
新手问一下, android中setAdapter的空指针问题
代码如下: package com.example.fragmentbestpractice; import java.util.ArrayList; import java.util.List; import android.app.Activity; import android.app.Fragment; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ListView; public class NewsTitleFragment extends Fragment implements OnItemClickListener { private ListView titleListView; private List<News> newsList; private NewsAdapter adapter; private boolean isTwoPane; @Override public void onAttach(Activity activity) { super.onAttach(activity); newsList = getNews(); adapter = new NewsAdapter(activity, R.layout.news_item, newsList); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // TODO Auto-generated method stub View view = inflater .inflate(R.layout.news_title_frag, container, false); titleListView = (ListView) view .findViewById(R.id.title_list); titleListView.setAdapter(adapter); titleListView.setOnItemClickListener(this); return view; } @Override public void onActivityCreated(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onActivityCreated(savedInstanceState); if (getActivity().findViewById(R.id.news_content_layout) != null) { isTwoPane = true; } else { isTwoPane = false; } } @Override public void onItemClick(AdapterView<?> arg0, View view, int position, long id) { News news = newsList.get(position); if (isTwoPane) { NewsContentFragment newsContentFragment = (NewsContentFragment) getFragmentManager() .findFragmentById(R.id.news_content_fragment); newsContentFragment.refresh(news.getTitle(), news.getContent()); } else { NewsContentActivity.actionStart(getActivity(), news.getTitle(), news.getContent()); } } public List<News> getNews() { List<News> newslist = new ArrayList<News>(); News news1 = new News(); news1.setTitle("hahahaahhaahahahhahahaha"); news1.setContent("hohohohohohhohohohohohohohohohohoho" + "hohohohohohohohohohohohohohohohohohohohohohohoh"); newslist.add(news1); News news2 = new News(); news2.setTitle("qoqoqoqoqqoqoqoqoqoqoqoqoqoqo"); news2.setContent("bobobobobobobbobobobbo" + "bobobobobobobobobobobbobobobobbobobobobob" + "bobobooboobobobbobhahahahdhdhabobobobobobobobob"); newslist.add(news2); return newsList; } } 日志中错误提示在这一句中: titleListView.setAdapter(adapter); 网上查了一天了,还是找不到原因,求大神们指教
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()); } }); }
新手求大神帮助。仿照window7写的图片浏览器,运行一直显示空指针异常,求帮助,谢谢
package com.xpc.picture; import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.view.View; import android.view.ViewGroup; import android.view.animation.AnimationUtils; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.BaseAdapter; import android.widget.FrameLayout.LayoutParams; import android.widget.GridView; import android.widget.ImageSwitcher; import android.widget.ImageView; import android.widget.ViewSwitcher.ViewFactory; /* *一直都是空指针异常,求大神指点一点 */ public class MainActivity extends Activity { private int[] imageId = new int[]{R.drawable.a,R.drawable.b,R.drawable.c, R.drawable.e,R.drawable.f,R.drawable.g,R.drawable.h, R.drawable.i};//定义并初始化保存图片IDde 数组 private ImageSwitcher imageSwitcher; //申明一个图像切换器对象 GridView gridview = (GridView) findViewById(R.id.gridview1); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); imageSwitcher = (ImageSwitcher) findViewById(R.id.imageSwitcher1); imageSwitcher.setInAnimation(AnimationUtils.loadAnimation(this,android.R.anim.fade_in));//设置淡入动画 imageSwitcher.setOutAnimation(AnimationUtils.loadAnimation(this,android.R.anim.fade_out));//淡出效果 imageSwitcher.setFactory(new ViewFactory() { @Override public View makeView() { // TODO Auto-generated method stub ImageView imageView = new ImageView(MainActivity.this);//实例化一个ImageView类的对象 imageView.setScaleType(ImageView.ScaleType.FIT_CENTER); imageView.setLayoutParams(new ImageSwitcher.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));//设置保持纵横比居中缩放图像 //是否导包错误???这是要导什么包,太多了 return imageView; } }); imageSwitcher.setImageResource(imageId[6]); BaseAdapter adapter = new BaseAdapter(){ @Override public int getCount() { // TODO Auto-generated method stub return imageId.length; } @Override public Object getItem(int position) { // TODO Auto-generated method stub return position; } @Override public long getItemId(int position) { // TODO Auto-generated method stub return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { // TODO Auto-generated method stub ImageView imageview; if(convertView==null){ imageview = new ImageView(MainActivity.this); imageview.setAdjustViewBounds(true); imageview.setMaxWidth(150);//设置长度宽度 imageview.setMaxHeight(113); imageview.setPadding(5,5, 5,5);//设置内边距 }else{ imageview=(ImageView) convertView; } imageview.setImageResource(imageId[position]);//设置要显示的图片 return imageview; } }; gridview.setAdapter(adapter); gridview.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // TODO Auto-generated method stub imageSwitcher.setImageResource(imageId[position]); } }); } @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; } } 布局文件 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MainActivity" > <GridView android:id="@+id/gridview1" android:layout_height="match_parent" android:layout_width="640dp" android:layout_marginTop="10dp" android:horizontalSpacing="3dp" android:verticalSpacing="3dp" android:numColumns="4" /> <ImageSwitcher android:id="@+id/imageSwitcher1" android:padding="20dp" android:layout_width="match_parent" android:layout_height="match_parent" /> </LinearLayout>
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 各位前辈,请指教
求大神指导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 gridview 空指针
vh.imageViewvh.setImageResource(getItem(i).dataicon);//这两句提示有空指针 vh.textViewvh.setText(getItem(i).dataName); package com.zhangyi.zyapp26_27; import android.app.Activity; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v7.app.AppCompatActivity; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.GridView; import android.widget.ImageView; import android.widget.TextView; import android.widget.ViewSwitcher; import java.util.ArrayList; /** * Created by me on 2016-11-3. */ public class BViewSwitcher extends Activity { public static final int NUMBER_PER_SCREEN = 12; public static class DataItem{ public String dataName; public int dataicon; } static class ViewHolder{ ImageView imageViewvh; TextView textViewvh; } private ArrayList<DataItem> items = new ArrayList<>(); private int screenNo = 1; private int screenCount; ViewSwitcher myviewswitcher; LayoutInflater inflater; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.b_viewswitcher); inflater = LayoutInflater.from(BViewSwitcher.this); for (int i = 0; i < 40; i++) { String dataname =""; int drawable =0; DataItem item=new DataItem(); switch ((int) (Math.random() * 3)) { case 0:dataname="Chrome "+i;drawable = R.mipmap.ic_launcher2;break; case 1:dataname="Picture "+i;drawable = R.mipmap.ic_launcher3;break; case 2:dataname="Shop "+i;drawable = R.mipmap.ic_launcher4;break; } item.dataName = dataname; item.dataicon = drawable; items.add(item); } screenCount = items.size() % NUMBER_PER_SCREEN == 0 ? items.size() / NUMBER_PER_SCREEN : items.size() / NUMBER_PER_SCREEN + 1; myviewswitcher = (ViewSwitcher) findViewById(R.id.myviewswitcher); myviewswitcher.setFactory(new ViewSwitcher.ViewFactory() { @Override public View makeView() { return inflater.inflate(R.layout.datagridview, null); } }); next(null); } public void previous(View view) { if (screenNo > 1) { screenNo--; myviewswitcher.setInAnimation(this, R.anim.push_left_in); ((GridView) myviewswitcher.getNextView()).setAdapter(adapter); myviewswitcher.showPrevious(); } } public void next(View view) { if (screenNo < screenCount) { screenNo++; myviewswitcher.setInAnimation(this, R.anim.push_right_in); ((GridView) myviewswitcher.getNextView()).setAdapter(adapter); myviewswitcher.showNext(); } } private BaseAdapter adapter = new BaseAdapter() { @Override public int getCount() { if (screenNo == screenCount && items.size() % NUMBER_PER_SCREEN != 0) { return items.size() % NUMBER_PER_SCREEN; } return NUMBER_PER_SCREEN; } @Override public DataItem getItem(int i) { return items.get((screenNo - 1) * NUMBER_PER_SCREEN + i); } @Override public long getItemId(int i) { return i; } @Override public View getView(int i, View view, ViewGroup viewGroup) { View view1 = view; ViewHolder vh=new ViewHolder(); ViewGroup viewGroup2=(ViewGroup) getLayoutInflater().inflate(R.layout.datagridview, null); vh.imageViewvh = (ImageView) viewGroup2.findViewById(R.id.imagedata); vh.textViewvh = (TextView) viewGroup2.findViewById(R.id.textdata); try { vh.imageViewvh.setImageResource(getItem(i).dataicon);//这两句提示有空指针 vh.textViewvh.setText(getItem(i).dataName); } catch (Exception e) { e.printStackTrace(); } // ViewGroup parent1 = (ViewGroup) vh.imageViewvh.getParent(); // if (parent1 != null) { // parent1.removeAllViews(); // } // // ViewGroup parent11 = (ViewGroup) vh.textViewvh.getParent(); // if (parent11 != null) { // parent11.removeAllViews(); // } // viewGroup2.addView(vh.imageViewvh); // viewGroup2.addView(vh.textViewvh); // if (view1 == null) { // view1 = inflater.inflate(R.layout.datagridview, viewGroup,false); // } // ImageView imageView = (ImageView) viewGroup2.findViewById(R.id.imagedata); // TextView textView = (TextView) viewGroup2.findViewById(R.id.textdata); // try { // // imageView.setImageResource(getItem(i).dataicon); // imageView.setImageResource(R.mipmap.ic_launcher2); // textView.setText(getItem(i).dataName); // }catch (Exception e){ // e.printStackTrace(); // } return viewGroup2; } }; }
相见恨晚的超实用网站
搞学习 知乎:www.zhihu.com 简答题:http://www.jiandati.com/ 网易公开课:https://open.163.com/ted/ 网易云课堂:https://study.163.com/ 中国大学MOOC:www.icourse163.org 网易云课堂:study.163.com 哔哩哔哩弹幕网:www.bilibili.com 我要自学网:www.51zxw
花了20分钟,给女朋友们写了一个web版群聊程序
参考博客 [1]https://www.byteslounge.com/tutorials/java-ee-html5-websocket-example
爬虫福利二 之 妹子图网MM批量下载
爬虫福利一:27报网MM批量下载    点击 看了本文,相信大家对爬虫一定会产生强烈的兴趣,激励自己去学习爬虫,在这里提前祝:大家学有所成! 目标网站:妹子图网 环境:Python3.x 相关第三方模块:requests、beautifulsoup4 Re:各位在测试时只需要将代码里的变量 path 指定为你当前系统要保存的路径,使用 python xxx.py 或IDE运行即可。
字节跳动视频编解码面经
引言 本文主要是记录一下面试字节跳动的经历。 三四月份投了字节跳动的实习(图形图像岗位),然后hr打电话过来问了一下会不会opengl,c++,shador,当时只会一点c++,其他两个都不会,也就直接被拒了。 七月初内推了字节跳动的提前批,因为内推没有具体的岗位,hr又打电话问要不要考虑一下图形图像岗,我说实习投过这个岗位不合适,不会opengl和shador,然后hr就说秋招更看重基础。我当时
开源一个功能完整的SpringBoot项目框架
福利来了,给大家带来一个福利。 最近想了解一下有关Spring Boot的开源项目,看了很多开源的框架,大多是一些demo或者是一个未成形的项目,基本功能都不完整,尤其是用户权限和菜单方面几乎没有完整的。 想到我之前做的框架,里面通用模块有:用户模块,权限模块,菜单模块,功能模块也齐全了,每一个功能都是完整的。 打算把这个框架分享出来,供大家使用和学习。 为什么用框架? 框架可以学习整体
Java学习的正确打开方式
在博主认为,对于入门级学习java的最佳学习方法莫过于视频+博客+书籍+总结,前三者博主将淋漓尽致地挥毫于这篇博客文章中,至于总结在于个人,实际上越到后面你会发现学习的最好方式就是阅读参考官方文档其次就是国内的书籍,博客次之,这又是一个层次了,这里暂时不提后面再谈。博主将为各位入门java保驾护航,各位只管冲鸭!!!上天是公平的,只要不辜负时间,时间自然不会辜负你。 何谓学习?博主所理解的学习,它
程序员必须掌握的核心算法有哪些?
由于我之前一直强调数据结构以及算法学习的重要性,所以就有一些读者经常问我,数据结构与算法应该要学习到哪个程度呢?,说实话,这个问题我不知道要怎么回答你,主要取决于你想学习到哪些程度,不过针对这个问题,我稍微总结一下我学过的算法知识点,以及我觉得值得学习的算法。这些算法与数据结构的学习大多数是零散的,并没有一本把他们全部覆盖的书籍。下面是我觉得值得学习的一些算法以及数据结构,当然,我也会整理一些看过
Python——画一棵漂亮的樱花树(不同种樱花+玫瑰+圣诞树喔)
最近翻到一篇知乎,上面有不少用Python(大多是turtle库)绘制的树图,感觉很漂亮,我整理了一下,挑了一些我觉得不错的代码分享给大家(这些我都测试过,确实可以生成喔~) one 樱花树 动态生成樱花 效果图(这个是动态的): 实现代码 import turtle as T import random import time # 画樱花的躯干(60,t) def Tree(branch
深深的码丨Java HashMap 透析
HashMap 相关概念 HashTab、HashMap、TreeMap 均以键值对像是存储或操作数据元素。HashTab继承自Dictionary,HashMap、TreeMap继承自AbstractMap,三者均实现Map接口 **HashTab:**同步哈希表,不支持null键或值,因为同步导致性能影响,很少被使用 **HashMap:**应用较多的非同步哈希表,支持null键或值,是键值对...
大学四年自学走来,这些私藏的实用工具/学习网站我贡献出来了
大学四年,看课本是不可能一直看课本的了,对于学习,特别是自学,善于搜索网上的一些资源来辅助,还是非常有必要的,下面我就把这几年私藏的各种资源,网站贡献出来给你们。主要有:电子书搜索、实用工具、在线视频学习网站、非视频学习网站、软件下载、面试/求职必备网站。 注意:文中提到的所有资源,文末我都给你整理好了,你们只管拿去,如果觉得不错,转发、分享就是最大的支持了。 一、电子书搜索 对于大部分程序员...
linux系列之常用运维命令整理笔录
本博客记录工作中需要的linux运维命令,大学时候开始接触linux,会一些基本操作,可是都没有整理起来,加上是做开发,不做运维,有些命令忘记了,所以现在整理成博客,当然vi,文件操作等就不介绍了,慢慢积累一些其它拓展的命令,博客不定时更新 顺便拉下票,我在参加csdn博客之星竞选,欢迎投票支持,每个QQ或者微信每天都可以投5票,扫二维码即可,http://m234140.nofollow.ax.
Python 基础(一):入门必备知识
目录1 标识符2 关键字3 引号4 编码5 输入输出6 缩进7 多行8 注释9 数据类型10 运算符10.1 常用运算符10.2 运算符优先级 1 标识符 标识符是编程时使用的名字,用于给变量、函数、语句块等命名,Python 中标识符由字母、数字、下划线组成,不能以数字开头,区分大小写。 以下划线开头的标识符有特殊含义,单下划线开头的标识符,如:_xxx ,表示不能直接访问的类属性,需通过类提供
程序员接私活怎样防止做完了不给钱?
首先跟大家说明一点,我们做 IT 类的外包开发,是非标品开发,所以很有可能在开发过程中会有这样那样的需求修改,而这种需求修改很容易造成扯皮,进而影响到费用支付,甚至出现做完了项目收不到钱的情况。 那么,怎么保证自己的薪酬安全呢? 我们在开工前,一定要做好一些证据方面的准备(也就是“讨薪”的理论依据),这其中最重要的就是需求文档和验收标准。一定要让需求方提供这两个文档资料作为开发的基础。之后开发
网页实现一个简单的音乐播放器(大佬别看。(⊙﹏⊙))
今天闲着无事,就想写点东西。然后听了下歌,就打算写个播放器。 于是乎用h5 audio的加上js简单的播放器完工了。 欢迎 改进 留言。 演示地点跳到演示地点 html代码如下`&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;music&lt;/title&gt; &lt;meta charset="utf-8"&gt
Python十大装B语法
Python 是一种代表简单思想的语言,其语法相对简单,很容易上手。不过,如果就此小视 Python 语法的精妙和深邃,那就大错特错了。本文精心筛选了最能展现 Python 语法之精妙的十个知识点,并附上详细的实例代码。如能在实战中融会贯通、灵活使用,必将使代码更为精炼、高效,同时也会极大提升代码B格,使之看上去更老练,读起来更优雅。 1. for - else 什么?不是 if 和 else 才
数据库优化 - SQL优化
前面一篇文章从实例的角度进行数据库优化,通过配置一些参数让数据库性能达到最优。但是一些“不好”的SQL也会导致数据库查询变慢,影响业务流程。本文从SQL角度进行数据库优化,提升SQL运行效率。 判断问题SQL 判断SQL是否有问题时可以通过两个表象进行判断: 系统级别表象 CPU消耗严重 IO等待严重 页面响应时间过长
2019年11月中国大陆编程语言排行榜
2019年11月2日,我统计了某招聘网站,获得有效程序员招聘数据9万条。针对招聘信息,提取编程语言关键字,并统计如下: 编程语言比例 rank pl_ percentage 1 java 33.62% 2 c/c++ 16.42% 3 c_sharp 12.82% 4 javascript 12.31% 5 python 7.93% 6 go 7.25% 7
通俗易懂地给女朋友讲:线程池的内部原理
餐厅的约会 餐盘在灯光的照耀下格外晶莹洁白,女朋友拿起红酒杯轻轻地抿了一小口,对我说:“经常听你说线程池,到底线程池到底是个什么原理?”我楞了一下,心里想女朋友今天是怎么了,怎么突然问出这么专业的问题,但做为一个专业人士在女朋友面前也不能露怯啊,想了一下便说:“我先给你讲讲我前同事老王的故事吧!” 大龄程序员老王 老王是一个已经北漂十多年的程序员,岁数大了,加班加不动了,升迁也无望,于是拿着手里
经典算法(5)杨辉三角
杨辉三角 是经典算法,这篇博客对它的算法思想进行了讲解,并有完整的代码实现。
腾讯算法面试题:64匹马8个跑道需要多少轮才能选出最快的四匹?
昨天,有网友私信我,说去阿里面试,彻底的被打击到了。问了为什么网上大量使用ThreadLocal的源码都会加上private static?他被难住了,因为他从来都没有考虑过这个问题。无独有偶,今天笔者又发现有网友吐槽了一道腾讯的面试题,我们一起来看看。 腾讯算法面试题:64匹马8个跑道需要多少轮才能选出最快的四匹? 在互联网职场论坛,一名程序员发帖求助到。二面腾讯,其中一个算法题:64匹
面试官:你连RESTful都不知道我怎么敢要你?
面试官:了解RESTful吗? 我:听说过。 面试官:那什么是RESTful? 我:就是用起来很规范,挺好的 面试官:是RESTful挺好的,还是自我感觉挺好的 我:都挺好的。 面试官:… 把门关上。 我:… 要干嘛?先关上再说。 面试官:我说出去把门关上。 我:what ?,夺门而去 文章目录01 前言02 RESTful的来源03 RESTful6大原则1. C-S架构2. 无状态3.统一的接
JDK12 Collectors.teeing 你真的需要了解一下
前言 在 Java 12 里面有个非常好用但在官方 JEP 没有公布的功能,因为它只是 Collector 中的一个小改动,它的作用是 merge 两个 collector 的结果,这句话显得很抽象,老规矩,我们先来看个图(这真是一个不和谐的图????): 管道改造经常会用这个小东西,通常我们叫它「三通」,它的主要作用就是将 downstream1 和 downstre...
为啥国人偏爱Mybatis,而老外喜欢Hibernate/JPA呢?
关于SQL和ORM的争论,永远都不会终止,我也一直在思考这个问题。昨天又跟群里的小伙伴进行了一番讨论,感触还是有一些,于是就有了今天这篇文。 声明:本文不会下关于Mybatis和JPA两个持久层框架哪个更好这样的结论。只是摆事实,讲道理,所以,请各位看官勿喷。 一、事件起因 关于Mybatis和JPA孰优孰劣的问题,争论已经很多年了。一直也没有结论,毕竟每个人的喜好和习惯是大不相同的。我也看
项目中的if else太多了,该怎么重构?
介绍 最近跟着公司的大佬开发了一款IM系统,类似QQ和微信哈,就是聊天软件。我们有一部分业务逻辑是这样的 if (msgType = "文本") { // dosomething } else if(msgType = "图片") { // doshomething } else if(msgType = "视频") { // doshomething } else { // doshom...
致 Python 初学者
欢迎来到“Python进阶”专栏!来到这里的每一位同学,应该大致上学习了很多 Python 的基础知识,正在努力成长的过程中。在此期间,一定遇到了很多的困惑,对未来的学习方向感到迷茫。我非常理解你们所面临的处境。我从2007年开始接触 python 这门编程语言,从2009年开始单一使用 python 应对所有的开发工作,直至今天。回顾自己的学习过程,也曾经遇到过无数的困难,也曾经迷茫过、困惑过。开办这个专栏,正是为了帮助像我当年一样困惑的 Python 初学者走出困境、快速成长。希望我的经验能真正帮到你
“狗屁不通文章生成器”登顶GitHub热榜,分分钟写出万字形式主义大作
一、垃圾文字生成器介绍 最近在浏览GitHub的时候,发现了这样一个骨骼清奇的雷人项目,而且热度还特别高。 项目中文名:狗屁不通文章生成器 项目英文名:BullshitGenerator 根据作者的介绍,他是偶尔需要一些中文文字用于GUI开发时测试文本渲染,因此开发了这个废话生成器。但由于生成的废话实在是太过富于哲理,所以最近已经被小伙伴们给玩坏了。 他的文风可能是这样的: 你发现,...
程序员:我终于知道post和get的区别
是一个老生常谈的话题,然而随着不断的学习,对于以前的认识有很多误区,所以还是需要不断地总结的,学而时习之,不亦说乎
《程序人生》系列-这个程序员只用了20行代码就拿了冠军
你知道的越多,你不知道的越多 点赞再看,养成习惯GitHub上已经开源https://github.com/JavaFamily,有一线大厂面试点脑图,欢迎Star和完善 前言 这一期不算《吊打面试官》系列的,所有没前言我直接开始。 絮叨 本来应该是没有这期的,看过我上期的小伙伴应该是知道的嘛,双十一比较忙嘛,要值班又要去帮忙拍摄年会的视频素材,还得搞个程序员一天的Vlog,还要写BU...
加快推动区块链技术和产业创新发展,2019可信区块链峰会在京召开
11月8日,由中国信息通信研究院、中国通信标准化协会、中国互联网协会、可信区块链推进计划联合主办,科技行者协办的2019可信区块链峰会将在北京悠唐皇冠假日酒店开幕。   区块链技术被认为是继蒸汽机、电力、互联网之后,下一代颠覆性的核心技术。如果说蒸汽机释放了人类的生产力,电力解决了人类基本的生活需求,互联网彻底改变了信息传递的方式,区块链作为构造信任的技术有重要的价值。   1...
程序员把地府后台管理系统做出来了,还有3.0版本!12月7号最新消息:已在开发中有github地址
第一幕:缘起 听说阎王爷要做个生死簿后台管理系统,我们派去了一个程序员…… 996程序员做的梦: 第一场:团队招募 为了应对地府管理危机,阎王打算找“人”开发一套地府后台管理系统,于是就在地府总经办群中发了项目需求。 话说还是中国电信的信号好,地府都是满格,哈哈!!! 经常会有外行朋友问:看某网站做的不错,功能也简单,你帮忙做一下? 而这次,面对这样的需求,这个程序员...
网易云6亿用户音乐推荐算法
网易云音乐是音乐爱好者的集聚地,云音乐推荐系统致力于通过 AI 算法的落地,实现用户千人千面的个性化推荐,为用户带来不一样的听歌体验。 本次分享重点介绍 AI 算法在音乐推荐中的应用实践,以及在算法落地过程中遇到的挑战和解决方案。 将从如下两个部分展开: AI算法在音乐推荐中的应用 音乐场景下的 AI 思考 从 2013 年 4 月正式上线至今,网易云音乐平台持续提供着:乐屏社区、UGC...
8年经验面试官详解 Java 面试秘诀
作者 |胡书敏 责编 | 刘静 出品 | CSDN(ID:CSDNnews) 本人目前在一家知名外企担任架构师,而且最近八年来,在多家外企和互联网公司担任Java技术面试官,前后累计面试了有两三百位候选人。在本文里,就将结合本人的面试经验,针对Java初学者、Java初级开发和Java开发,给出若干准备简历和准备面试的建议。 Java程序员准备和投递简历的实...
相关热词 c# clr dll c# 如何orm c# 固定大小的字符数组 c#框架设计 c# 删除数据库 c# 中文文字 图片转 c# 成员属性 接口 c#如何将程序封装 16进制负数转换 c# c#练手项目
立即提问