安卓开发,加载数据显示ListView ListAdapter 问题

安卓开发,加载数据显示ListView正常

listview = FindViewById(Resource.Id.lvKcxx);
//加载数据
datas = new List();
//datas.Add(new JxglList { title = "Elephant1", postman = "Big and Gray, but what the hey", addtime = "2015-11-12 12:12:12" });
//datas.Add(new JxglList { title = "Elephant2", postman = "Big and Gray, but what the hey", addtime = "2015-11-12 12:12:12" });
//datas.Add(new JxglList { title = "Elephant3", postman = "Big and Gray, but what the hey", addtime = "2015-11-12 12:12:12" });

        //listview.Adapter = new DataListAdapter(this, datas); 

连接数据库后,换
datas.Add(new JxglList { title = list[i]["Title"].ToString(), postman = list[i]["PostMan"].ToString(), addtime = list[i]["AddTime"].ToString() });
出错

1个回答

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
Android ListView的adapter中如何重用不同类型的item

如题,我要做的效果是一个listView中能显示不同类型的item,而且我希望同一类的item能够在滑动时候进行重用。 比如说,我一个listView中,会显示纯文字的item、纯图片的item、纯视屏的item,我在滑动的时候会根据我的数据类型进行选择加载,我希望我除了开始的时候为它们创建view以外,之后滑动下去以后都是重用之前的item,纯文字的item重用之前显示过的纯文字的item、纯图片的item重用之前显示过的纯图片的item、纯视屏的item重用之前显示过的纯视屏的item

删除后android刷新Listview

在我的item删除后我想要刷新我的listview。但是好像不起作用,我是少了什么东西了么?我用了`listAdapter.notifyDataSetChanged();`也不起作用。有没有人能帮帮我?谢谢。 @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); getActivity().setContentView(R.layout.dl_listview); View empty = getActivity().findViewById(R.id.empty); DLListView = (ListView) getActivity().findViewById(R.id.DLListView); DLListView.setEmptyView(empty); if (!Environment.getExternalStorageState().equals( Environment.MEDIA_MOUNTED)) { Toast.makeText(getActivity(), "Error! No SDCARD Found!", Toast.LENGTH_LONG).show(); } else { File directory = new File(Environment.getExternalStorageDirectory() + File.separator + "St"); directory.mkdirs(); } DLListView = (ListView) getActivity().findViewById(R.id.DLListView); myList = new ArrayList<String>(); File sdCard = Environment.getExternalStorageDirectory(); file = new File(sdCard.getAbsolutePath() + "/St/"); File list[] = file.listFiles(); for (int i = 0; i < list.length; i++) { String fileName = list[i].getName(); fileName = fileName.replace(".txt", ""); myList.add(fileName); } listAdapter = new ArrayAdapter<String>(getActivity(), R.layout.simplerow, myList); DLListView.setAdapter(listAdapter); DLListView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // TODO Auto-generated method stub String textToPass = myList.get(position); Intent i = new Intent(getActivity(), ViewActivity.class); textToPass = textToPass.replace(textToPass + "", textToPass + ".txt"); i.putExtra("textToPass", textToPass); startActivity(i); } }); DLListView.setOnItemLongClickListener(new OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { // TODO Auto-generated method stub registerForContextMenu(DLListView); return false; } }); } public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo; String name = ((TextView) info.targetView).getText().toString(); menu.setHeaderTitle(name); menu.add(0, v.getId(), 0, "Delete"); } @Override public boolean onContextItemSelected(MenuItem item) { deletefunc(item.getItemId()); return true; } public void deletefunc(int id) { String filenamec = fileName1; filenamec = filenamec.replace(filenamec + "", filenamec + ".txt"); File folder = Environment.getExternalStorageDirectory(); String fileName = folder.getPath() + "/St/" + filenamec; File myFile = new File(fileName); if (myFile.exists()) myFile.delete(); Toast.makeText(getActivity(), fileName1+" Deleted", Toast.LENGTH_SHORT) .show(); listAdapter.remove(listAdapter.getItem(id)); } LogCat : 12-26 11:57:27.334: E/AndroidRuntime(5576): FATAL EXCEPTION: main 12-26 11:57:27.334: E/AndroidRuntime(5576): java.lang.IndexOutOfBoundsException: Invalid index 2131034154, size is 1 12-26 11:57:27.334: E/AndroidRuntime(5576): at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:251) 12-26 11:57:27.334: E/AndroidRuntime(5576): at java.util.ArrayList.get(ArrayList.java:304) 12-26 11:57:27.334: E/AndroidRuntime(5576): at android.widget.ArrayAdapter.getItem(ArrayAdapter.java:337) 12-26 11:57:27.334: E/AndroidRuntime(5576): at free.st.app.MyDownloads.deletefunc(MyDownloads.java:137) 12-26 11:57:27.334: E/AndroidRuntime(5576): at free.st.app.MyDownloads.onContextItemSelected(MyDownloads.java:118) 12-26 11:57:27.334: E/AndroidRuntime(5576): at android.support.v4.app.FragmentManagerImpl.dispatchContextItemSelected(FragmentManager.java:1933) 12-26 11:57:27.334: E/AndroidRuntime(5576): at android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:360) 12-26 11:57:27.334: E/AndroidRuntime(5576): at com.actionbarsherlock.app.SherlockFragmentActivity.onMenuItemSelected(SherlockFragmentActivity.java:200) 12-26 11:57:27.334: E/AndroidRuntime(5576): at com.android.internal.policy.impl.PhoneWindow$DialogMenuCallback.onMenuItemSelected(PhoneWindow.java:3691) 12-26 11:57:27.334: E/AndroidRuntime(5576): at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:735) 12-26 11:57:27.334: E/AndroidRuntime(5576): at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:149) 12-26 11:57:27.334: E/AndroidRuntime(5576): at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:874) 12-26 11:57:27.334: E/AndroidRuntime(5576): at com.android.internal.view.menu.MenuDialogHelper.onClick(MenuDialogHelper.java:167) 12-26 11:57:27.334: E/AndroidRuntime(5576): at com.android.internal.app.AlertController$AlertParams$3.onItemClick(AlertController.java:929) 12-26 11:57:27.334: E/AndroidRuntime(5576): at android.widget.AdapterView.performItemClick(AdapterView.java:292) 12-26 11:57:27.334: E/AndroidRuntime(5576): at android.widget.AbsListView.performItemClick(AbsListView.java:1185) 12-26 11:57:27.334: E/AndroidRuntime(5576): at android.widget.AbsListView$PerformClick.run(AbsListView.java:2713) 12-26 11:57:27.334: E/AndroidRuntime(5576): at android.widget.AbsListView$1.run(AbsListView.java:3468) 12-26 11:57:27.334: E/AndroidRuntime(5576): at android.os.Handler.handleCallback(Handler.java:605) 12-26 11:57:27.334: E/AndroidRuntime(5576): at android.os.Handler.dispatchMessage(Handler.java:92) 12-26 11:57:27.334: E/AndroidRuntime(5576): at android.os.Looper.loop(Looper.java:137) 12-26 11:57:27.334: E/AndroidRuntime(5576): at android.app.ActivityThread.main(ActivityThread.java:4512) 12-26 11:57:27.334: E/AndroidRuntime(5576): at java.lang.reflect.Method.invokeNative(Native Method) 12-26 11:57:27.334: E/AndroidRuntime(5576): at java.lang.reflect.Method.invoke(Method.java:511) 12-26 11:57:27.334: E/AndroidRuntime(5576): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:982) 12-26 11:57:27.334: E/AndroidRuntime(5576): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:749) 12-26 11:57:27.334: E/AndroidRuntime(5576): at dalvik.system.NativeStart.main(Native Method)

ListView.setAdapter问题

cannot make a static reference to the non-static method setAdapter(listAdapter) from the type ListVuew![图片](https://img-ask.csdn.net/upload/201511/20/1448020493_479899.jpg)

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)

怎么给Fragment中的ListView绑定数据

急求指点!我的Fragment加载的布局里有一个ListView控件,ListView内行有一个lmageView 我想给这个ImageVieW绑定数据 求大神指点怎么弄啊,我老报错

求大神帮助,使用Bmob服务器,获取数据解析数据???我还使用异步加载

//我建立了Bean,里面有一个ImageView,两个TextView, //ImageView id=imgView; //TextView id=tittle; //TextView id=content; //BaseAdapter在最下面列出来; //ListView布局是activity_main; //item布局是item_layout; 我都是按照视频写的,基础差,请见谅 ``` package com.bmoblist; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.List; import org.json.JSONArray; import org.json.JSONObject; import org.json.JSONStringer; import android.app.Activity; import android.os.AsyncTask; import android.os.Bundle; import android.widget.BaseAdapter; import android.widget.ListAdapter; import android.widget.ListView; import android.widget.Toast; import cn.bmob.v3.Bmob; import cn.bmob.v3.BmobQuery; import cn.bmob.v3.listener.FindListener; import cn.volley.toolbox.JsonObjectRequest; public class MainActivity extends Activity { private ListView listView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // 初始化 Bmob SDK // 使用时请将第二个参数Application ID替换成你在Bmob服务器端创建的Application ID Bmob.initialize(this, "这里是就不透露了"); ZhinengBean zhinengBean = new ZhinengBean(); ListView listView = (ListView)findViewById(R.layout.activity_main); } //这一步完全不知道怎么弄 private List<ZhinengBean> getJsonData(){ //bmobString不知道写啥 List<ZhinengBean> zhinengBeanList = new ArrayList<>(); String jsonString = readStream(ZhinengBean.openStream()); return null; } private String readStream(InputStream is){ InputStreamReader isr; String result = ""; try { String line =""; isr = new InputStreamReader(is,"utf-8"); BufferedReader br = new BufferedReader(isr); while ((line=br.readLine()) != null){ result += line; } } catch (UnsupportedEncodingException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } catch (IOException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } return result; } class NewsAsyncTask extends AsyncTask<String,Void,List<ZhinengBean>>{ @Override protected List<ZhinengBean> doInBackground(String... params) { // TODO 自动生成的方法存根 return getJsonData(params[0]); //不知道怎么写 } } } ``` ``` package com.bmoblist; import java.util.List; import android.content.Context; import android.media.Image; import android.view.LayoutInflater; 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<ZhinengBean> mList; private LayoutInflater mInflater; public MyAdapter (Context context,List<ZhinengBean> list){ mList = list; mInflater = LayoutInflater.from(context); } //》》》》》》》 //表示显示多少条数据 @Override public int getCount() { // TODO 自动生成的方法存根 return mList.size(); } @Override public Object getItem(int position) { // TODO 自动生成的方法存根 return mList.get(position); } @Override public long getItemId(int position) { // TODO 自动生成的方法存根 return position; } @Override public View getView(int position, View converView, ViewGroup parent) { // TODO 自动生成的方法存根 ViewHolder viewHolder; if(converView == null){ viewHolder = new ViewHolder(); converView = mInflater.inflate(R.layout.iten_layout,null); viewHolder.znImage = (ImageView) converView.findViewById(R.id.tv_icon); viewHolder.znTittle = (TextView) converView.findViewById(R.id.tv_tittle); viewHolder.znTittle2 = (TextView) converView.findViewById(R.id.tv_content); converView.setTag(viewHolder); }else{ viewHolder = (ViewHolder) converView.getTag(); } viewHolder.znImage.setImageResource(R.id.tv_icon); viewHolder.znTittle.setText(mList.get(position).getZntittle()); viewHolder.znTittle2.setText(mList.get(position).getZntittle2()); return converView; } class ViewHolder { public ImageView znImage; public TextView znTittle; public TextView znTittle2; } } ```

新手请教ListView 刷新问题

这是显示ListView的界面 package com.security.phonepolice.view; import java.util.ArrayList; import java.util.List; import org.apache.http.Header; import org.json.JSONException; import org.json.JSONObject; import com.loopj.android.http.AsyncHttpResponseHandler; import com.loopj.android.http.RequestParams; import com.security.phonepolice.ContantValues; import com.security.phonepolice.R; import com.security.phonepolice.entity.Msgbean; import com.security.phonepolice.http.MyHttpclient; import com.security.phonepolice.util.SharedPreferenceUtil; import com.security.phonepolice.view.MessageManager.NotificationAdapter; import com.security.phonepolice.view.OAFileFragment.FileViewHolder; import com.security.phonepolice.view.widget.MyListView; import com.security.phonepolice.view.widget.MyListView.RefreshListener; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.support.v4.app.Fragment; import android.util.Log; import android.view.LayoutInflater; 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.ImageView; import android.widget.TextView; import android.widget.Toast; public class OANotifyFragment extends Fragment implements OnClickListener, OnItemClickListener{ private View view; private ImageView mPreIv; private MyListView mNotifyLv; private LayoutInflater mInflater; private NotifyAdapter adapter = null; private TextView notifyUpload; private List<Msgbean> mList; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { view = inflater.inflate(R.layout.oa_notify_ui, container, false); mInflater = inflater; init(); initEvent(); return view; } private void init() { mNotifyLv = (MyListView) view.findViewById(R.id.oa_notify_lv); } private void initEvent() { mList = new ArrayList<Msgbean>(); adapter = new NotifyAdapter(mList); mNotifyLv.setOnItemClickListener(this); mNotifyLv.setAdapter(adapter); mNotifyLv.setOnRefreshListener(new RefreshListener() { @Override public Object refreshing() { RequestParams params = new RequestParams(); params.put("action", "Message"); String serverAdd = SharedPreferenceUtil.getServerStringSP(getActivity(), "config", "serverAdd"); MyHttpclient.post(serverAdd+ContantValues.IDCARD_URL, params, new AsyncHttpResponseHandler(){ @Override public void onSuccess( int statusCode, Header[] headers, String content) { super.onSuccess(statusCode, headers, content); if (!content.equals("failed")) { Msgbean msgBean = new Msgbean(); try { JSONObject jsonObject=new JSONObject(content); msgBean.setTitle(jsonObject.getString("TITLE")); msgBean.setContent(jsonObject.getString("CONTENT")); Log.i("-----------", jsonObject.getString("TITLE")); List<Msgbean> list = new ArrayList<Msgbean>(); list.add(msgBean); mList = list; adapter.notifyDataSetChanged(); } catch (JSONException e) { e.printStackTrace(); } }else { Toast.makeText(getActivity(), "刷新失败", Toast.LENGTH_LONG).show(); } } @Override public void onFailure( Throwable error, String content) { Toast.makeText(getActivity(), "连接失败", Toast.LENGTH_LONG).show(); super.onFailure(error, content); } } ); return null; } @Override public void refreshed(Object obj) { Toast.makeText(getActivity(), "刷新完毕", Toast.LENGTH_LONG).show(); } @Override public void more() { Toast.makeText(getActivity(), "正在加载", Toast.LENGTH_LONG).show(); } }); } class NotifyAdapter extends BaseAdapter{ private List<Msgbean> list; public NotifyAdapter(List<Msgbean> list) { this.list = list; } @Override public int getCount() { return list.size(); } @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 0; } @Override public View getView(int position, View convertView, ViewGroup parent) { NotifyViewHolder viewHolder = null; if (convertView == null) { convertView = mInflater.inflate(R.layout.oa_item, null); viewHolder = new NotifyViewHolder(); viewHolder.itemIv = (ImageView) convertView.findViewById(R.id.oa_item_iv); viewHolder.itemTitle = (TextView) convertView.findViewById(R.id.oa_item_title); viewHolder.itemContent = (TextView) convertView.findViewById(R.id.oa_item_content); convertView.setTag(viewHolder); }else { viewHolder = (NotifyViewHolder) convertView.getTag(); } viewHolder.itemIv.setImageResource(R.drawable.notification_small); viewHolder.itemTitle.setText(list.get(position).getTitle()); viewHolder.itemContent.setText(list.get(position).getContent()); return convertView; } } public static class NotifyViewHolder{ public ImageView itemIv; public TextView itemTitle; public TextView itemContent; } @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Intent intent = null; if (position > 0) { //去服务器拉取警情的详细信息 intent = new Intent(); intent.putExtra("InfoTag", "OANotify"); intent.setClass(getActivity(), MessageDetail.class); startActivity(intent); } } } 这是在网上找到的自定义的ListView package com.security.phonepolice.view.widget; import java.text.SimpleDateFormat; import java.util.Date; import com.security.phonepolice.R; import android.content.Context; import android.os.Handler; import android.os.Message; import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.widget.AbsListView; import android.widget.AbsListView.OnScrollListener; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.ListAdapter; import android.widget.ListView; import android.widget.ProgressBar; import android.widget.TextView; /** * 下拉刷新,底部更多 * */ public class MyListView extends ListView implements OnScrollListener{ private float mDownY; private float mMoveY; private int mHeaderHeight; private int mCurrentScrollState; private final static int NONE_PULL_REFRESH = 0; //正常状态 private final static int ENTER_PULL_REFRESH = 1; //进入下拉刷新状态 private final static int OVER_PULL_REFRESH = 2; //进入松手刷新状态 private final static int EXIT_PULL_REFRESH = 3; //松手后反弹和加载状态 private int mPullRefreshState = 0; //记录刷新状态 private final static int REFRESH_BACKING = 0; //反弹中 private final static int REFRESH_BACED = 1; //达到刷新界限,反弹结束后 private final static int REFRESH_RETURN = 2; //没有达到刷新界限,返回 private final static int REFRESH_DONE = 3; //加载数据结束 private LinearLayout mHeaderLinearLayout = null; private LinearLayout mFooterLinearLayout = null; private TextView mHeaderTextView = null; private TextView mHeaderUpdateText = null; private ImageView mHeaderPullDownImageView = null; private ImageView mHeaderReleaseDownImageView = null; private ProgressBar mHeaderProgressBar = null; private TextView mFooterTextView = null; private ProgressBar mFooterProgressBar = null; private SimpleDateFormat mSimpleDateFormat; private Object mRefreshObject = null; private RefreshListener mRefreshListener = null; public void setOnRefreshListener(RefreshListener refreshListener) { this.mRefreshListener = refreshListener; } public MyListView(Context context) { this(context, null); } public MyListView(Context context, AttributeSet attrs) { super(context, attrs); init(context); } void init(final Context context) { mHeaderLinearLayout = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.refresh_list_header, null); addHeaderView(mHeaderLinearLayout); mHeaderTextView = (TextView) findViewById(R.id.refresh_list_header_text); mHeaderUpdateText = (TextView) findViewById(R.id.refresh_list_header_last_update); mHeaderPullDownImageView = (ImageView) findViewById(R.id.refresh_list_header_pull_down); mHeaderReleaseDownImageView = (ImageView) findViewById(R.id.refresh_list_header_release_up); mHeaderProgressBar = (ProgressBar) findViewById(R.id.refresh_list_header_progressbar); mFooterLinearLayout = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.refresh_list_footer, null); addFooterView(mFooterLinearLayout); mFooterProgressBar = (ProgressBar) findViewById(R.id.refresh_list_footer_progressbar); mFooterTextView = (TextView) mFooterLinearLayout.findViewById(R.id.refresh_list_footer_text); mFooterLinearLayout.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if ("加载更多".equals(mFooterTextView.getText())) { mFooterTextView.setText("正在加载"); mFooterProgressBar.setVisibility(View.VISIBLE); if (mRefreshListener != null) { mRefreshListener.more(); } } } }); setSelection(1); setOnScrollListener(this); measureView(mHeaderLinearLayout); mHeaderHeight = mHeaderLinearLayout.getMeasuredHeight(); mSimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm"); mHeaderUpdateText.setText("下拉刷新"+ mSimpleDateFormat.format(new Date())); } @Override public boolean onTouchEvent(MotionEvent ev) { switch (ev.getAction()) { case MotionEvent.ACTION_DOWN: mDownY = ev.getY(); break; case MotionEvent.ACTION_MOVE: mMoveY = ev.getY(); if (mPullRefreshState == OVER_PULL_REFRESH) { mHeaderLinearLayout.setPadding(mHeaderLinearLayout.getPaddingLeft(), (int)((mMoveY - mDownY)/3), mHeaderLinearLayout.getPaddingRight(), mHeaderLinearLayout.getPaddingBottom()); } break; case MotionEvent.ACTION_UP: //when you action up, it will do these: //1. roll back util header topPadding is 0 //2. hide the header by setSelection(1) if (mPullRefreshState == OVER_PULL_REFRESH || mPullRefreshState == ENTER_PULL_REFRESH) { new Thread() { public void run() { Message msg; while(mHeaderLinearLayout.getPaddingTop() > 1) { msg = mHandler.obtainMessage(); msg.what = REFRESH_BACKING; mHandler.sendMessage(msg); try { sleep(5); } catch (InterruptedException e) { e.printStackTrace(); } } msg = mHandler.obtainMessage(); if (mPullRefreshState == OVER_PULL_REFRESH) { msg.what = REFRESH_BACED; } else { msg.what = REFRESH_RETURN; } mHandler.sendMessage(msg); }; }.start(); } break; } return super.onTouchEvent(ev); } @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (mCurrentScrollState == SCROLL_STATE_TOUCH_SCROLL && firstVisibleItem == 0 && (mHeaderLinearLayout.getBottom() >= 0 && mHeaderLinearLayout.getBottom() < mHeaderHeight)) { //进入且仅进入下拉刷新状态 if (mPullRefreshState == NONE_PULL_REFRESH) { mPullRefreshState = ENTER_PULL_REFRESH; } } else if (mCurrentScrollState == SCROLL_STATE_TOUCH_SCROLL && firstVisibleItem == 0 && (mHeaderLinearLayout.getBottom() >= mHeaderHeight)) { //下拉达到界限,进入松手刷新状态 if (mPullRefreshState == ENTER_PULL_REFRESH || mPullRefreshState == NONE_PULL_REFRESH) { mPullRefreshState = OVER_PULL_REFRESH; mDownY = mMoveY; //为下拉1/3折扣效果记录开始位置 mHeaderTextView.setText("松手刷新");//显示松手刷新 mHeaderPullDownImageView.setVisibility(View.GONE);//隐藏"下拉刷新" mHeaderReleaseDownImageView.setVisibility(View.VISIBLE);//显示向上的箭头 } } else if (mCurrentScrollState == SCROLL_STATE_TOUCH_SCROLL && firstVisibleItem != 0) { //不刷新了 if (mPullRefreshState == ENTER_PULL_REFRESH) { mPullRefreshState = NONE_PULL_REFRESH; } } else if (mCurrentScrollState == SCROLL_STATE_FLING && firstVisibleItem == 0) { //飞滑状态,不能显示出header,也不能影响正常的飞滑 //只在正常情况下才纠正位置 if (mPullRefreshState == NONE_PULL_REFRESH) { setSelection(1); } } } @Override public void onScrollStateChanged(AbsListView view, int scrollState) { mCurrentScrollState = scrollState; } @Override public void setAdapter(ListAdapter adapter) { super.setAdapter(adapter); setSelection(1); } private void measureView(View child) { ViewGroup.LayoutParams p = child.getLayoutParams(); if (p == null) { p = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); } int childWidthSpec = ViewGroup.getChildMeasureSpec(0, 0 + 0, p.width); int lpHeight = p.height; int childHeightSpec; if (lpHeight > 0) { childHeightSpec = MeasureSpec.makeMeasureSpec(lpHeight, MeasureSpec.EXACTLY); } else { childHeightSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED); } child.measure(childWidthSpec, childHeightSpec); } private Handler mHandler = new Handler(){ @Override public void handleMessage(Message msg) { switch (msg.what) { case REFRESH_BACKING: mHeaderLinearLayout.setPadding(mHeaderLinearLayout.getPaddingLeft(), (int) (mHeaderLinearLayout.getPaddingTop()*0.75f), mHeaderLinearLayout.getPaddingRight(), mHeaderLinearLayout.getPaddingBottom()); break; case REFRESH_BACED: mHeaderTextView.setText("正在加载..."); mHeaderProgressBar.setVisibility(View.VISIBLE); mHeaderPullDownImageView.setVisibility(View.GONE); mHeaderReleaseDownImageView.setVisibility(View.GONE); mPullRefreshState = EXIT_PULL_REFRESH; new Thread() { public void run() { if (mRefreshListener != null) { mRefreshObject = mRefreshListener.refreshing(); } Message msg = mHandler.obtainMessage(); msg.what = REFRESH_DONE; mHandler.sendMessage(msg); }; }.start(); break; case REFRESH_RETURN: mHeaderTextView.setText("下拉刷新"); mHeaderProgressBar.setVisibility(View.INVISIBLE); mHeaderPullDownImageView.setVisibility(View.VISIBLE); mHeaderReleaseDownImageView.setVisibility(View.GONE); mHeaderLinearLayout.setPadding(mHeaderLinearLayout.getPaddingLeft(), 0, mHeaderLinearLayout.getPaddingRight(), mHeaderLinearLayout.getPaddingBottom()); mPullRefreshState = NONE_PULL_REFRESH; setSelection(1); break; case REFRESH_DONE: mHeaderTextView.setText("下拉刷新"); mHeaderProgressBar.setVisibility(View.INVISIBLE); mHeaderPullDownImageView.setVisibility(View.VISIBLE); mHeaderReleaseDownImageView.setVisibility(View.GONE); mHeaderUpdateText.setText("最新更新"+ mSimpleDateFormat.format(new Date())); mHeaderLinearLayout.setPadding(mHeaderLinearLayout.getPaddingLeft(), 0, mHeaderLinearLayout.getPaddingRight(), mHeaderLinearLayout.getPaddingBottom()); mPullRefreshState = NONE_PULL_REFRESH; setSelection(1); if (mRefreshListener != null) { mRefreshListener.refreshed(mRefreshObject); } break; default: break; } } }; public interface RefreshListener { Object refreshing(); void refreshed(Object obj); void more(); } public void finishFootView() { mFooterProgressBar.setVisibility(View.GONE); mFooterTextView.setText("更多"); } public void addFootView() { if (getFooterViewsCount() == 0) { addFooterView(mFooterLinearLayout); } } public void removeFootView() { removeFooterView(mFooterLinearLayout); } } 这是实体类: package com.security.phonepolice.entity; public class Msgbean { private int id; private String title; private String content; private String relName; private String relTime; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getContent() { return content; } public void setContent(String content) { this.content = content; } public String getRelName() { return relName; } public void setRelName(String relName) { this.relName = relName; } public String getRelTime() { return relTime; } public void setRelTime(String relTime) { this.relTime = relTime; } } 走到这一步法mNotifyLv.setOnRefreshListener(new RefreshListener() 就停了 为什么刷新的时候就是不走接口中的refreshing()方法。求大神指教啊!

将图像加载到 Bitmap 对象时出现内存不足的问题

<div class="post-text" itemprop="text"> <p>I have a list view with a couple of image buttons on each row. When you click the list row, it launches a new activity. I have had to build my own tabs because of an issue with the camera layout. The activity that gets launched for result is a map. If I click on my button to launch the image preview (load an image off the SD card) the application returns from the activity back to the <code>listview</code> activity to the result handler to relaunch my new activity which is nothing more than an image widget. </p> <p>The image preview on the list view is being done with the cursor and <code>ListAdapter</code>. This makes it pretty simple, but I am not sure how I can put a resized image (I.e. Smaller bit size not pixel as the <code>src</code> for the image button on the fly. So I just resized the image that came off the phone camera.</p> <p>The issue is that I get an out of memory error when it tries to go back and re-launch the 2nd activity.</p> <ul> <li>Is there a way I can build the list adapter easily row by row, where I can resize on the fly (<em>bit wise</em>)? </li> </ul> <p>This would be preferable as I also need to make some changes to the properties of the widgets/elements in each row as I am unable to select a row with touch screen because of focus issue. (<em>I can use roller ball.</em>)</p> <ul> <li>I know I can do an out of band resize and save of my image, but that is not really what I want to do, but some sample code for that would be nice.</li> </ul> <p>As soon as I disabled the image on the list view it worked fine again.</p> <p>FYI: This is how I was doing it:</p> <pre><code>String[] from = new String[] { DBHelper.KEY_BUSINESSNAME,DBHelper.KEY_ADDRESS,DBHelper.KEY_CITY,DBHelper.KEY_GPSLONG,DBHelper.KEY_GPSLAT,DBHelper.KEY_IMAGEFILENAME + ""}; int[] to = new int[] {R.id.businessname,R.id.address,R.id.city,R.id.gpslong,R.id.gpslat,R.id.imagefilename }; notes = new SimpleCursorAdapter(this, R.layout.notes_row, c, from, to); setListAdapter(notes); </code></pre> <p>Where <code>R.id.imagefilename</code> is a <code>ButtonImage</code>.</p> <p>Here is my LogCat:</p> <pre><code>01-25 05:05:49.877: ERROR/dalvikvm-heap(3896): 6291456-byte external allocation too large for this process. 01-25 05:05:49.877: ERROR/(3896): VM wont let us allocate 6291456 bytes 01-25 05:05:49.877: ERROR/AndroidRuntime(3896): Uncaught handler: thread main exiting due to uncaught exception 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): java.lang.OutOfMemoryError: bitmap size exceeds VM budget 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): at android.graphics.BitmapFactory.nativeDecodeStream(Native Method) 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:304) 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:149) 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:174) 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): at android.graphics.drawable.Drawable.createFromPath(Drawable.java:729) 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): at android.widget.ImageView.resolveUri(ImageView.java:484) 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): at android.widget.ImageView.setImageURI(ImageView.java:281) 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): at android.widget.SimpleCursorAdapter.setViewImage(SimpleCursorAdapter.java:183) 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): at android.widget.SimpleCursorAdapter.bindView(SimpleCursorAdapter.java:129) 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): at android.widget.CursorAdapter.getView(CursorAdapter.java:150) 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): at android.widget.AbsListView.obtainView(AbsListView.java:1057) 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): at android.widget.ListView.makeAndAddView(ListView.java:1616) 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): at android.widget.ListView.fillSpecific(ListView.java:1177) 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): at android.widget.ListView.layoutChildren(ListView.java:1454) 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): at android.widget.AbsListView.onLayout(AbsListView.java:937) 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): at android.view.View.layout(View.java:5611) 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1119) 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): at android.widget.LinearLayout.layoutHorizontal(LinearLayout.java:1108) 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): at android.widget.LinearLayout.onLayout(LinearLayout.java:922) 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): at android.view.View.layout(View.java:5611) 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): at android.widget.FrameLayout.onLayout(FrameLayout.java:294) 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): at android.view.View.layout(View.java:5611) 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1119) 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:999) 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): at android.widget.LinearLayout.onLayout(LinearLayout.java:920) 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): at android.view.View.layout(View.java:5611) 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): at android.widget.FrameLayout.onLayout(FrameLayout.java:294) 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): at android.view.View.layout(View.java:5611) 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): at android.view.ViewRoot.performTraversals(ViewRoot.java:771) 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): at android.view.ViewRoot.handleMessage(ViewRoot.java:1103) 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): at android.os.Handler.dispatchMessage(Handler.java:88) 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): at android.os.Looper.loop(Looper.java:123) 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): at android.app.ActivityThread.main(ActivityThread.java:3742) 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): at java.lang.reflect.Method.invokeNative(Native Method) 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): at java.lang.reflect.Method.invoke(Method.java:515) 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739) 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:497) 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): at dalvik.system.NativeStart.main(Native Method) 01-25 05:10:01.127: ERROR/AndroidRuntime(3943): ERROR: thread attach failed </code></pre> <p>I also have a new error when displaying an image: </p> <pre><code>01-25 22:13:18.594: DEBUG/skia(4204): xxxxxxxxxxx jpeg error 20 Improper call to JPEG library in state %d 01-25 22:13:18.604: INFO/System.out(4204): resolveUri failed on bad bitmap uri: 01-25 22:13:18.694: ERROR/dalvikvm-heap(4204): 6291456-byte external allocation too large for this process. 01-25 22:13:18.694: ERROR/(4204): VM won't let us allocate 6291456 bytes 01-25 22:13:18.694: DEBUG/skia(4204): xxxxxxxxxxxxxxxxxxxx allocPixelRef failed </code></pre> </div> <p>转载于:https://stackoverflow.com/questions/477572/strange-out-of-memory-issue-while-loading-an-image-to-a-bitmap-object</p>

Android中怎样用自定义的adapter加载日期列表

想实现以下的效果,因为自己技术大白,不知道怎么处理,贴出代码: 我是用ViewPager + Fragment实现页面切换的,其中在fragmentB中有个按钮button,fragmentA中有个listview,现在想实现的是,通过点击B中的button,在A中的listview中显示一个item,item的名字用当前时间来设置。我用的是自定义的adapter, ``` private class DateAdapter extends ArrayAdapter<Date_item> { private int resourceId; public DateAdapter(Context context, int dateresourceId, List<Date_item> objects){ super(context, dateresourceId,objects); resourceId = dateresourceId; } @Override public View getView(int position,View convertView, ViewGroup parent){ Date_item date_item = getItem(position);//获取当前项的date实例 View view; ViewHolder viewHolder; if(convertView == null){ view = LayoutInflater.from(getContext()).inflate(resourceId,null); viewHolder = new ViewHolder(); viewHolder.date = (TextView)view.findViewById(R.id.chart_date); view.setTag(viewHolder);//将viewHolder缓存到view中 }else { view = convertView; viewHolder = (ViewHolder)view.getTag(); } return view; } class ViewHolder{ TextView date; } } ``` 我将A中列表的item也设置在了B中: ``` //列表item的时间形式 //设置时间格式 SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd/HH:mm:ss"); //获取当前时间 long time = System.currentTimeMillis(); //将long转化为Date Date date = new Data(time); String timeSave = format.format(date); ``` 在B中的button的监听事件里面: ``` btn.setOnClickListener(new View.OnClickListener(){ @Override public void onClick(View v){ DateAdapter dateAdapter =new DateAdapter(getActivity(),R.layout.item_layout,dateList); listView.setAdapter(dateAdapter); } }) ``` 程序一运行就闪退,错误是NullPointerException:Attempt to invoke virtual method'void android widget.ListView.setAdapter(android.widget.ListAdapter)'on a null object reference. 请问这是什么情况,这问题困了我很久了,在线等,感谢各位

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

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

为什么这个应用程序停留在加载json内容?

<div class="post-text" itemprop="text"> <p>I'm trying to use this <a href="https://github.com/CreatorB/Android-MySQL-CRUD-creatorb" rel="nofollow">Github example</a> to <strong>learn</strong> how to <strong>GET</strong> and <strong>POST</strong> data from a <code>PHP</code>/<code>MySQL</code> server using <code>json</code> requests.</p> <p>I've been able to run the <code>pendaftaran</code> database perfectly on my browser using <code>XAMPP</code>.</p> <p>However, when the following application class is trying to fetch data from the <code>MySQL</code> db, it becomes stucked displaying the <code>ProgressDialog</code>.</p> <pre><code>package id.creatorb.bukutamu; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import org.apache.http.NameValuePair; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import android.app.ListActivity; import android.app.ProgressDialog; import android.content.Intent; import android.os.AsyncTask; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ListAdapter; import android.widget.ListView; import android.widget.SimpleAdapter; import android.widget.TextView; public class SemuaBukuTamu extends ListActivity { // Progress Dialog private ProgressDialog pDialog; // buat json object JSONParser jParser = new JSONParser(); ArrayList&lt;HashMap&lt;String, String&gt;&gt; bukutamuList; // url untuk get semua buku tamu private static String url_semua_bukutamu = "http://192.168.1.22/lab-tutor/pendaftaran/get_all_pendaftaran.php"; // JSON Node private static final String TAG_SUCCESS = "success"; private static final String TAG_PENDAFTARAN = "pendaftaran"; private static final String TAG_PID = "pid"; private static final String TAG_NAME = "name"; // pendaftaran JSONArray JSONArray pendaftaran = null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.semua_bukutamu); // Hashmap untuk ListView bukutamuList = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;(); // Loading products in Background Thread new LoadSemuaBukuTamu().execute(); // Get listview ListView lv = getListView(); // select single bukutamu // Jalankan tampilan edit buku tamu lv.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) { // dapatkan nilai dari list pendaftaran String pid = ((TextView) view.findViewById(R.id.pid)).getText() .toString(); // Memulai aktifitas baru Intent in = new Intent(getApplicationContext(), EditBukuTamu.class); // kirimkan pid ke activity selanjutnya in.putExtra(TAG_PID, pid); // memulai activity baru dengan mnghrap bbrapa kembalian response startActivityForResult(in, 100); } }); } // response dari edit bukutamu @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); // jika kode hasil sama dengan 100 if (resultCode == 100) { // maka diterima // ketika user ngedit atau menghapus data // reload screen Intent intent = getIntent(); finish(); startActivity(intent); } } /** * Background Async Task untuk menampilkan semua daftar bukutamu menggunakan http request * */ class LoadSemuaBukuTamu extends AsyncTask&lt;String, String, String&gt; { /** * sebelum melakukan thread di background maka jalankan progres dialog * */ @Override protected void onPreExecute() { super.onPreExecute(); pDialog = new ProgressDialog(SemuaBukuTamu.this); pDialog.setMessage("Mohon tunggu, Loading Data..."); pDialog.setIndeterminate(false); pDialog.setCancelable(false); pDialog.show(); } /** * dapetkan semua produk dari get url di background * */ protected String doInBackground(String... args) { // Buat Parameter List&lt;NameValuePair&gt; params = new ArrayList&lt;NameValuePair&gt;(); // ambil json dari url JSONObject json = jParser.makeHttpRequest(url_semua_bukutamu, "GET", params); // cek logcat untuk response dari json Log.d("Semua Buku Tamu: ", json.toString()); try { // cek jika tag success int success = json.getInt(TAG_SUCCESS); if (success == 1) { // data ditemukan // ambil array dari bukutamu pendaftaran = json.getJSONArray(TAG_PENDAFTARAN); // tampilkan perulangan semua produk for (int i = 0; i &lt; pendaftaran.length(); i++) { JSONObject c = pendaftaran.getJSONObject(i); // simpan pada variabel String id = c.getString(TAG_PID); String name = c.getString(TAG_NAME); // buat new hashmap HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;(); // key =&gt; value map.put(TAG_PID, id); map.put(TAG_NAME, name); // masukan HashList ke ArrayList bukutamuList.add(map); } } else { // jika tidak ada data // maka jalankan tambahkan buku tamu Intent i = new Intent(getApplicationContext(), TambahBukuTamu.class); // tutup semua proses sebelumnya i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(i); } } catch (JSONException e) { e.printStackTrace(); } return null; } /** * jika pekerjaan di belakang layar selesai maka hentikan progress dialog * **/ protected void onPostExecute(String file_url) { // hentikan progress ketika semua data didapat pDialog.dismiss(); // perbarui screen runOnUiThread(new Runnable() { public void run() { /** * perbarui json ke arraylist * */ ListAdapter adapter = new SimpleAdapter( SemuaBukuTamu.this, bukutamuList, R.layout.list_pendaftaran, new String[] { TAG_PID, TAG_NAME}, new int[] { R.id.pid, R.id.name }); // perbarui list pendaftaran setListAdapter(adapter); } }); } } } </code></pre> <h2><strong>EDIT</strong></h2> <p>I've found out after some debugging that if I switch the local IP to <code>localhost</code> it will throw an Exception on the <a href="https://github.com/CreatorB/Android-MySQL-CRUD-creatorb/blob/master/BukuTamu/src/id/creatorb/bukutamu/JSONParser.java" rel="nofollow">JSONParser.class</a> at</p> <pre><code>HttpResponse httpResponse = httpClient.execute(httpGet); </code></pre> <p>What could possibly be going on?</p> </div>

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

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

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

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

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

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

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

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

你以为这样写Java代码很6,但我看不懂

为了提高 Java 编程的技艺,我最近在 GitHub 上学习一些高手编写的代码。下面这一行代码(出自大牛之手)据说可以征服你的朋友,让他们觉得你写的代码很 6,来欣赏一下吧。 IntStream.range(1, 5).boxed().map(i -&gt; { System.out.print("Happy Birthday "); if (i == 3) return "dear NAME"...

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

最近有个老铁,告诉我说,上班一个月,后悔当初着急入职现在公司了。他之前在美图做手机研发,今年美图那边今年也有一波组织优化调整,他是其中一个,在协商离职后,当时捉急找工作上班,因为有房贷供着,不能没有收入来源。所以匆忙选了一家公司,实际上是一个大型外包公司,主要派遣给其他手机厂商做外包项目。**当时承诺待遇还不错,所以就立马入职去上班了。但是后面入职后,发现薪酬待遇这块并不是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、简历的本质 作为简历的撰写者,你必须要搞清楚一点,简历的本质是什么,它就是为了来销售你的价值主张的。往深...

程序员写出这样的代码,能不挨骂吗?

当你换槽填坑时,面对一个新的环境。能够快速熟练,上手实现业务需求是关键。但是,哪些因素会影响你快速上手呢?是原有代码写的不够好?还是注释写的不够好?昨夜...

带了6个月的徒弟当了面试官,而身为高级工程师的我天天修Bug......

即将毕业的应届毕业生一枚,现在只拿到了两家offer,但最近听到一些消息,其中一个offer,我这个组据说客户很少,很有可能整组被裁掉。 想问大家: 如果我刚入职这个组就被裁了怎么办呢? 大家都是什么时候知道自己要被裁了的? 面试软技能指导: BQ/Project/Resume 试听内容: 除了刷题,还有哪些技能是拿到offer不可或缺的要素 如何提升面试软实力:简历, 行为面试,沟通能...

优雅的替换if-else语句

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

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

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

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

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

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

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

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

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

程序员为什么千万不要瞎努力?

本文作者用对比非常鲜明的两个开发团队的故事,讲解了敏捷开发之道 —— 如果你的团队缺乏统一标准的环境,那么即使勤劳努力,不仅会极其耗时而且成果甚微,使用...

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

二哥,有个事想询问下您的意见,您觉得应届生值得去外包吗?公司虽然挺大的,中xx,但待遇感觉挺低,马上要报到,挺纠结的。

当HR压你价,说你只值7K,你该怎么回答?

当HR压你价,说你只值7K时,你可以流畅地回答,记住,是流畅,不能犹豫。 礼貌地说:“7K是吗?了解了。嗯~其实我对贵司的面试官印象很好。只不过,现在我的手头上已经有一份11K的offer。来面试,主要也是自己对贵司挺有兴趣的,所以过来看看……”(未完) 这段话主要是陪HR互诈的同时,从公司兴趣,公司职员印象上,都给予对方正面的肯定,既能提升HR的好感度,又能让谈判气氛融洽,为后面的发挥留足空间。...

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

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

Python爬虫,高清美图我全都要(彼岸桌面壁纸)

爬取彼岸桌面网站较为简单,用到了requests、lxml、Beautiful Soup4

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

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

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

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

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

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

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

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

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

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

大牛都会用的IDEA调试技巧!!!

导读 前天面试了一个985高校的实习生,问了他平时用什么开发工具,他想也没想的说IDEA,于是我抛砖引玉的问了一下IDEA的调试用过吧,你说说怎么设置断点...

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

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

程序员是做全栈工程师好?还是专注一个领域好?

昨天,有位大一的同学私信我,说他要做全栈工程师。 我一听,这不害了孩子么,必须制止啊。 谁知,讲到最后,更确定了他做全栈程序员的梦想。 但凡做全栈工程师的,要么很惨,要么很牛! 但凡很牛的,绝不是一开始就是做全栈的! 全栈工程师听起来好听,但绝没有你想象的那么简单。 今天听我来给你唠,记得帮我点赞哦。 一、全栈工程师的职责 如果你学习编程的目的只是玩玩,那随意,想怎么学怎么学。...

不要再到处使用 === 了

我们知道现在的开发人员都使用 === 来代替 ==,为什么呢?我在网上看到的大多数教程都认为,要预测 JavaScript 强制转换是如何工作这太复杂了,因此建议总是使用===。这些都...

终于,月薪过5万了!

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

MySQL性能优化(五):为什么查询速度这么慢

前期回顾: MySQL性能优化(一):MySQL架构与核心问题 MySQL性能优化(二):选择优化的数据类型 MySQL性能优化(三):深入理解索引的这点事 MySQL性能优化(四):如何高效正确的使用索引 前面章节我们介绍了如何选择优化的数据类型、如何高效的使用索引,这些对于高性能的MySQL来说是必不可少的。但这些还完全不够,还需要合理的设计查询。如果查询写的很糟糕,即使表结构再合理、索引再...

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

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

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

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

前端还能这么玩?(女朋友生日,用前端写了一个好玩的送给了她,高兴坏了)

前端还能这么玩?(女朋友生日,用前端写了一个好玩的送给了她,高兴坏了)

爬虫(101)爬点重口味的

小弟最近在学校无聊的很哪,浏览网页突然看到一张图片,都快流鼻血。。。然后小弟冥思苦想,得干一点有趣的事情python 爬虫库安装https://s.taobao.com/api?_ks...

立即提问
相关内容推荐