如何处理NullPointerException异常的机器人? [英] How to Handle NullPointerException in android?
问题描述
2月1日至18日:08:05.271:E / AndroidRuntime(24688):致命异常:主要
2月1号至18日:08:05.271:E / AndroidRuntime(24688):显示java.lang.NullPointerException
2月1号至18日:08:05.271:E / AndroidRuntime(24688):在com.example.tava.EchangingMessage $ LoadData.onPostExecute(EchangingMessage.java:178)
2月1号至18日:08:05.271:E / AndroidRuntime(24688):在com.example.tava.EchangingMessage $ LoadData.onPostExecute(EchangingMessage.java:1)
2月1号至18日:08:05.271:E / AndroidRuntime(24688):在android.os.AsyncTask.finish(AsyncTask.java:602)
2月1号至18日:08:05.271:E / AndroidRuntime(24688):在android.os.AsyncTask.access $ 600(AsyncTask.java:156)
2月1号至18日:08:05.271:E / AndroidRuntime(24688):在android.os.AsyncTask $ InternalHandler.handleMessage(AsyncTask.java:615)
2月1号至18日:08:05.271:E / AndroidRuntime(24688):在android.os.Handler.dispatchMessage(Handler.java:99)
2月1号至18日:08:05.271:E / AndroidRuntime(24688):在android.os.Looper.loop(Looper.java:154)
2月1号至18日:08:05.271:E / AndroidRuntime(24688):在android.app.ActivityThread.main(ActivityThread.java:4945)
2月1号至18日:08:05.271:E / AndroidRuntime(24688):在java.lang.reflect.Method.invokeNative(本机方法)
2月1号至18日:08:05.271:E / AndroidRuntime(24688):在java.lang.reflect.Method.invoke(Method.java:511)
2月1号至18日:08:05.271:E / AndroidRuntime(24688):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:784)
2月1号至18日:08:05.271:E / AndroidRuntime(24688):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
2月1号至18日:08:05.271:E / AndroidRuntime(24688):在dalvik.system.NativeStart.main(本机方法)
这是我的code活性code:
公共类EchangingMessage扩展活动实现OnClickListener {
私人ProgressDialog pDialog;
JSONParser jParser =新JSONParser();
ArrayList的< HashMap的<字符串,字符串>> DaftarRS;
的EditText textToSend;
ArrayList的< HashMap的<字符串,字符串>> ArrayList的;
私有静态字符串url_daftar_rs =http://192.168.137.1/www/Android_Login_Secure/detailMessage.php;
私有静态字符串url_daftar_rs1 =http://192.168.137.1/www/Android_Login_Secure/myFriends.php;
公共静态最后弦乐TAG_SUCCESS =成功;
公共静态最后弦乐TAG_DAFTAR_RS =daftar_rs;
公共静态最后弦乐TAG_ID_RS =id_rs;
公共静态最后弦乐TAG_NAMA_RS =用户名;
公共静态最后弦乐TAG_LINK_IMAGE_RS =形象;
公共静态最后弦乐TAG_MESSAGE_RS =的MessageText;
公共静态最后弦乐TAG_TIME_RS =sendAt;
公共静态最后弦乐TAG_SEEN_RS =readStatus;
JSONArray daftar_rs = NULL;
ListAdapterUserOnile adapterFirends;
ImageView的showOnline;
@覆盖
保护无效的onCreate(包savedInstanceState){
// TODO自动生成方法存根
super.onCreate(savedInstanceState);
的setContentView(R.layout.exchange_message);
ArrayList的=新的ArrayList< HashMap的<字符串,字符串>>();
}
@覆盖
公共无效的onClick(视图v){
// TODO自动生成方法存根
开关(v.getId()){
案例R.id.userOnline:
userOnlineWindow();
打破;
}
}
私人无效userOnlineWindow(){
// TODO自动生成方法存根
LayoutInflater layoutInflater =(LayoutInflater)getBaseContext()
.getSystemService(LAYOUT_INFLATER_SERVICE);
查看popupView = layoutInflater.inflate(R.layout.popup,NULL);
最后PopupWindow popupWindow =新PopupWindow(popupView,
LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
按钮btnDismiss =(按钮)popupView.findViewById(R.id.dismiss);
btnDismiss.setOnClickListener(新Button.OnClickListener(){
@覆盖
公共无效的onClick(视图v){
// TODO自动生成方法存根
popupWindow.dismiss();
}
});
popupWindow.showAsDropDown(showOnline,-190,-90);
新LoadData()执行();
popupWindow.setFocusable(真正的);
popupWindow.update();
}
类LoadData扩展的AsyncTask<字符串,字符串,字符串> {
@覆盖
在preExecute保护无效(){
super.on preExecute();
pDialog =新ProgressDialog(EchangingMessage.this);
pDialog.setMessage(加载信息......);
pDialog.setIndeterminate(假);
pDialog.setCancelable(假);
pDialog.show();
}
@覆盖
保护字符串doInBackground(字符串...为arg0){
名单<的NameValuePair> params1 =新的ArrayList<的NameValuePair>();
params1.add(新BasicNameValuePair(我,52));
JSONObject的JSON = jParser.makeHtt prequest(url_daftar_rs1,POST,
params1);
尝试 {
INT成功= json.getInt(TAG_SUCCESS);
Log.i(成功,+成功);
如果(成功== 1){
daftar_rs = json.getJSONArray(TAG_DAFTAR_RS);
的for(int i = 0; I< daftar_rs.length();我++){
JSONObject的C = daftar_rs.getJSONObject(我);
字符串id_rs = c.getString(TAG_ID_RS);
字符串nama_rs = c.getString(TAG_NAMA_RS);
字符串link_image_rs = c.getString(TAG_LINK_IMAGE_RS);
HashMap的<字符串,字符串>图=新的HashMap<字符串,字符串>();
map.put(TAG_ID_RS,id_rs);
map.put(TAG_NAMA_RS,nama_rs);
map.put(TAG_LINK_IMAGE_RS,
http://192.168.137.1/www/Android_Login_Secure/Images/upload/big/
+ link_image_rs);
arraylist.add(图)
}
} 其他 {
}
}赶上(例外五){
Log.e(错误,连接:+ e.toString());
}
返回null;
}
保护无效onPostExecute(字符串file_url){
pDialog.dismiss();
ListView控件listUserOnline =(ListView控件)findViewById(R.id.listOfUserOnline);
adapterFirends =新ListAdapterUserOnile(EchangingMessage.this,
数组列表);
listUserOnline.setAdapter(adapterFirends);
}
}
}
我创造了这个应用程序,但是当我点击顶部的按钮我得到这个错误 这是弹出窗口,这是跟PHP
请如何处理这种错误怎么办?
和这是我EchangeMesssage.xml文件
< XML版本=1.0编码=UTF-8&GT?;
< RelativeLayout的的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:背景=@可绘制/ backgroudnformain
机器人:方向=垂直>
<的LinearLayout
机器人:layout_width =match_parent
机器人:layout_height =40dp
机器人:后台=#99CC00
机器人:重力=中心
>
< ImageView的
机器人:ID =@ + ID / userOnline
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_gravity =中心
机器人:SRC =@可绘制/ userimages/>
< / LinearLayout中>
<的LinearLayout
机器人:ID =@ + ID / bottom_write_bar
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_alignParentBottom =真
机器人:背景=@可绘制/ message_bar>
<的EditText
机器人:ID =@ + ID / messageToSend
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:layout_margin =5SP
机器人:layout_weight =1
机器人:背景=@可绘制/ message_field
机器人:提示=写在这里
机器人:填充=5SP
机器人:文字颜色=@色/ textFieldColor/>
<按钮
机器人:ID =@ + ID / sendButton
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =FILL_PARENT
机器人:layout_margin =5SP
机器人:背景=@可绘制/ send_button的
机器人:的onClick =的sendMessage
机器人:paddingBottom会=5SP
机器人:以下属性来=15sp
机器人:paddingRight =15sp
机器人:paddingTop =5SP
机器人:文=发送
机器人:文字颜色=#FFF/>
< / LinearLayout中>
<的ListView
机器人:ID =@ + ID / listSend
机器人:layout_width =FILL_PARENT
机器人:layout_height =0dip
机器人:layout_marginTop =40dp
机器人:layout_above =@ ID / bottom_write_bar
机器人:layout_alignParentTop =真
机器人:cacheColorHint =#00000000
机器人:分隔=#00000000
机器人:stackFromBottom =真
机器人:可点击=假
机器人:滚动条=无
机器人:transcriptMode =alwaysScroll
机器人:listSelector =#00000000>
< / ListView控件>
<的TextView
机器人:ID =@ + ID / you_id
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:文本=大文本
机器人:textAppearance =机器人:ATTR / textAppearanceLarge
机器人:能见度=水涨船高/>
<的TextView
机器人:ID =@ + ID / me_id
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:文本=大文本
机器人:textAppearance =机器人:ATTR / textAppearanceLarge
机器人:能见度=水涨船高/>
< / RelativeLayout的>
这是我的popup.xml文件:
< XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:背景=@可绘制/ windowwww
机器人:方向=垂直>
<按钮
机器人:ID =@ + ID /解雇
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_marginLeft =240dp
机器人:layout_marginTop =60dp
机器人:文本=EXIT/>
<的ListView
机器人:ID =@ + ID / listOfUserOnline
机器人:layout_width =match_parent
机器人:layout_height =330dp
机器人:layout_marginTop =30dp>
< / ListView控件>
< / LinearLayout中>
这是我ListAdapter类:
公共类ListAdapterUserOnile扩展了BaseAdapter {
公共字符串POST_TEXT;
私人活动的活动;
私人的ArrayList< HashMap的<字符串,字符串>>数据;
私有静态LayoutInflater吹气= NULL;
公共ImageLoader的ImageLoader的;
公共最后静态字符串you_id = NULL;
诠释计数= 0;
公共ListAdapterUserOnile(活动一,ArrayList的< HashMap的<字符串,字符串>> D){
活性= A;
数据= D;
充气=(LayoutInflater)活动
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
ImageLoader的=新ImageLoader的(activity.getApplicationContext());
}
公众诠释getCount将(){
// TODO自动生成方法存根
返回data.size();
}
公共对象的getItem(INT位置){
返回的位置;
}
众长getItemId(INT位置){
返回的位置;
}
公共查看getView(INT位置,查看convertView,ViewGroup中父){
查看VI = convertView;
如果(convertView == NULL){
VI = inflater.inflate(R.layout.item_list_friends,NULL);
}
TextView的name_rs =(TextView中)vi.findViewById(R.id.myFriendUsername);
ImageView的thumb_image =(ImageView的)六
.findViewById(R.id.myFriendImage);
TextView的状态=(TextView中)vi.findViewById(R.id.status);
ImageView的上=(ImageView的)vi.findViewById(R.id.online);
ImageView的关闭=(ImageView的)vi.findViewById(R.id.offline);
HashMap的<字符串,字符串> daftar_rs =新的HashMap<字符串,字符串>();
daftar_rs = data.get(位置);
最终诠释为getPosition =位置;
name_rs.setText(daftar_rs.get(EchangingMessage.TAG_NAMA_RS));
Log.e(形象,daftar_rs.get(EchangingMessage.TAG_LINK_IMAGE_RS));
imageLoader.DisplayImage(daftar_rs.get(EchangingMessage.TAG_LINK_IMAGE_RS)
thumb_image);
如果(status.getText()。的toString()。等于(1)){
off.setVisibility(View.INVISIBLE);
on.setVisibility(View.VISIBLE);
status.setVisibility(View.INVISIBLE);
}
其他
{
off.setVisibility(View.VISIBLE);
on.setVisibility(View.INVISIBLE);
status.setVisibility(View.INVISIBLE);
}
vi.setOnClickListener(新OnClickListener(){
@覆盖
公共无效的onClick(查看为arg0){
// TODO自动生成方法存根
Toast.makeText(
活动,
你点击
+ data.get(为getPosition)
获得(MyFriends.TAG_ID_RS)的ToString()
Toast.LENGTH_SHORT).show();
意图I =新的意图(活动,EchangingMessage.class);
i.putExtra(you_id,data.get(为getPosition)
获得(MyFriends.TAG_ID_RS)的ToString());
activity.startActivity(ⅰ);
}
});
返回六;
}
}
在使用的setContentView(R.layout.exchange_message)
,布局 R.layout.exchange_message
将被虚增,并关联到你的活动。如果要检索从布局视图,你只需要调用 findViewById(R.id.MyId);
。
但如果你的看法并不布局中,你将有一个NPException。
要检索另一个布局的意见,你必须首先它充气,然后调用 myView.findViewById(R.id.MyId)
。
例如,根据你的情况,如果你想使用的ListView
从 popup.xml
布局文件:
查看popupView = layoutInflater.inflate(R.layout.popup,NULL);
ListView控件列表= popupView.findViewById(R.id.listOfUserOnline);
01-18 02:08:05.271: E/AndroidRuntime(24688): FATAL EXCEPTION: main
01-18 02:08:05.271: E/AndroidRuntime(24688): java.lang.NullPointerException
01-18 02:08:05.271: E/AndroidRuntime(24688): at com.example.tava.EchangingMessage$LoadData.onPostExecute(EchangingMessage.java:178)
01-18 02:08:05.271: E/AndroidRuntime(24688): at com.example.tava.EchangingMessage$LoadData.onPostExecute(EchangingMessage.java:1)
01-18 02:08:05.271: E/AndroidRuntime(24688): at android.os.AsyncTask.finish(AsyncTask.java:602)
01-18 02:08:05.271: E/AndroidRuntime(24688): at android.os.AsyncTask.access$600(AsyncTask.java:156)
01-18 02:08:05.271: E/AndroidRuntime(24688): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:615)
01-18 02:08:05.271: E/AndroidRuntime(24688): at android.os.Handler.dispatchMessage(Handler.java:99)
01-18 02:08:05.271: E/AndroidRuntime(24688): at android.os.Looper.loop(Looper.java:154)
01-18 02:08:05.271: E/AndroidRuntime(24688): at android.app.ActivityThread.main(ActivityThread.java:4945)
01-18 02:08:05.271: E/AndroidRuntime(24688): at java.lang.reflect.Method.invokeNative(Native Method)
01-18 02:08:05.271: E/AndroidRuntime(24688): at java.lang.reflect.Method.invoke(Method.java:511)
01-18 02:08:05.271: E/AndroidRuntime(24688): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
01-18 02:08:05.271: E/AndroidRuntime(24688): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
01-18 02:08:05.271: E/AndroidRuntime(24688): at dalvik.system.NativeStart.main(Native Method)
And this is my Code Activity Code :
public class EchangingMessage extends Activity implements OnClickListener {
private ProgressDialog pDialog;
JSONParser jParser = new JSONParser();
ArrayList<HashMap<String, String>> DaftarRS;
EditText textToSend;
ArrayList<HashMap<String, String>> arraylist;
private static String url_daftar_rs = "http://192.168.137.1/www/Android_Login_Secure/detailMessage.php";
private static String url_daftar_rs1 = "http://192.168.137.1/www/Android_Login_Secure/myFriends.php";
public static final String TAG_SUCCESS = "success";
public static final String TAG_DAFTAR_RS = "daftar_rs";
public static final String TAG_ID_RS = "id_rs";
public static final String TAG_NAMA_RS = "username";
public static final String TAG_LINK_IMAGE_RS = "image";
public static final String TAG_MESSAGE_RS = "messageText";
public static final String TAG_TIME_RS = "sendAt";
public static final String TAG_SEEN_RS = "readStatus";
JSONArray daftar_rs = null;
ListAdapterUserOnile adapterFirends;
ImageView showOnline;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.exchange_message);
arraylist = new ArrayList<HashMap<String, String>>();
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.userOnline:
userOnlineWindow();
break;
}
}
private void userOnlineWindow() {
// TODO Auto-generated method stub
LayoutInflater layoutInflater = (LayoutInflater) getBaseContext()
.getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.popup, null);
final PopupWindow popupWindow = new PopupWindow(popupView,
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
Button btnDismiss = (Button) popupView.findViewById(R.id.dismiss);
btnDismiss.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
popupWindow.dismiss();
}
});
popupWindow.showAsDropDown(showOnline, -190, -90);
new LoadData().execute();
popupWindow.setFocusable(true);
popupWindow.update();
}
class LoadData extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(EchangingMessage.this);
pDialog.setMessage("Loading Information...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();
}
@Override
protected String doInBackground(String... arg0) {
List<NameValuePair> params1 = new ArrayList<NameValuePair>();
params1.add(new BasicNameValuePair("me", "52"));
JSONObject json = jParser.makeHttpRequest(url_daftar_rs1, "POST",
params1);
try {
int success = json.getInt(TAG_SUCCESS);
Log.i("success :", "" + success);
if (success == 1) {
daftar_rs = json.getJSONArray(TAG_DAFTAR_RS);
for (int i = 0; i < daftar_rs.length(); i++) {
JSONObject c = daftar_rs.getJSONObject(i);
String id_rs = c.getString(TAG_ID_RS);
String nama_rs = c.getString(TAG_NAMA_RS);
String link_image_rs = c.getString(TAG_LINK_IMAGE_RS);
HashMap<String, String> map = new HashMap<String, String>();
map.put(TAG_ID_RS, id_rs);
map.put(TAG_NAMA_RS, nama_rs);
map.put(TAG_LINK_IMAGE_RS,
"http://192.168.137.1/www/Android_Login_Secure/Images/upload/big/"
+ link_image_rs);
arraylist.add(map);
}
} else {
}
} catch (Exception e) {
Log.e("Error", "COnnection:" + e.toString());
}
return null;
}
protected void onPostExecute(String file_url) {
pDialog.dismiss();
ListView listUserOnline = (ListView) findViewById(R.id.listOfUserOnline);
adapterFirends = new ListAdapterUserOnile(EchangingMessage.this,
arraylist);
listUserOnline.setAdapter(adapterFirends);
}
}
}
I created this app but when I click the top button I got this error and this is the popup window , and this is connect with php
please how to handle this error what should I do ?
and this my EchangeMesssage.xml file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/backgroudnformain"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="#99cc00"
android:gravity="center"
>
<ImageView
android:id="@+id/userOnline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="@drawable/userimages" />
</LinearLayout>
<LinearLayout
android:id="@+id/bottom_write_bar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@drawable/message_bar" >
<EditText
android:id="@+id/messageToSend"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="5sp"
android:layout_weight="1"
android:background="@drawable/message_field"
android:hint="Write here"
android:padding="5sp"
android:textColor="@color/textFieldColor" />
<Button
android:id="@+id/sendButton"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_margin="5sp"
android:background="@drawable/send_button"
android:onClick="sendMessage"
android:paddingBottom="5sp"
android:paddingLeft="15sp"
android:paddingRight="15sp"
android:paddingTop="5sp"
android:text="Send"
android:textColor="#FFF" />
</LinearLayout>
<ListView
android:id="@+id/listSend"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_marginTop="40dp"
android:layout_above="@id/bottom_write_bar"
android:layout_alignParentTop="true"
android:cacheColorHint="#00000000"
android:divider="#00000000"
android:stackFromBottom="true"
android:clickable="false"
android:scrollbars="none"
android:transcriptMode="alwaysScroll"
android:listSelector="#00000000" >
</ListView>
<TextView
android:id="@+id/you_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge"
android:visibility="gone" />
<TextView
android:id="@+id/me_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge"
android:visibility="gone" />
</RelativeLayout>
and this is my popup.xml file :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/windowwww"
android:orientation="vertical" >
<Button
android:id="@+id/dismiss"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="240dp"
android:layout_marginTop="60dp"
android:text="EXIT" />
<ListView
android:id="@+id/listOfUserOnline"
android:layout_width="match_parent"
android:layout_height="330dp"
android:layout_marginTop="30dp" >
</ListView>
</LinearLayout>
And this is my ListAdapter class :
public class ListAdapterUserOnile extends BaseAdapter {
public String POST_TEXT;
private Activity activity;
private ArrayList<HashMap<String, String>> data;
private static LayoutInflater inflater = null;
public ImageLoader imageLoader;
public final static String you_id=null;
int count = 0;
public ListAdapterUserOnile(Activity a, ArrayList<HashMap<String, String>> d) {
activity = a;
data = d;
inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
imageLoader = new ImageLoader(activity.getApplicationContext());
}
public int getCount() {
// TODO Auto-generated method stub
return data.size();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
View vi = convertView;
if (convertView == null) {
vi = inflater.inflate(R.layout.item_list_friends, null);
}
TextView name_rs = (TextView) vi.findViewById(R.id.myFriendUsername);
ImageView thumb_image = (ImageView) vi
.findViewById(R.id.myFriendImage);
TextView status = (TextView) vi.findViewById(R.id.status);
ImageView on=(ImageView) vi.findViewById(R.id.online);
ImageView off=(ImageView) vi.findViewById(R.id.offline);
HashMap<String, String> daftar_rs = new HashMap<String, String>();
daftar_rs = data.get(position);
final int getPosition = position;
name_rs.setText(daftar_rs.get(EchangingMessage.TAG_NAMA_RS));
Log.e("IMage", daftar_rs.get(EchangingMessage.TAG_LINK_IMAGE_RS));
imageLoader.DisplayImage(daftar_rs.get(EchangingMessage.TAG_LINK_IMAGE_RS),
thumb_image);
if (status.getText().toString().equals("1")) {
off.setVisibility(View.INVISIBLE);
on.setVisibility(View.VISIBLE);
status.setVisibility(View.INVISIBLE);
}
else
{
off.setVisibility(View.VISIBLE);
on.setVisibility(View.INVISIBLE);
status.setVisibility(View.INVISIBLE);
}
vi.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Toast.makeText(
activity,
" You click"
+ data.get(getPosition)
.get(MyFriends.TAG_ID_RS).toString(),
Toast.LENGTH_SHORT).show();
Intent i=new Intent(activity,EchangingMessage.class);
i.putExtra(you_id, data.get(getPosition)
.get(MyFriends.TAG_ID_RS).toString());
activity.startActivity(i);
}
});
return vi;
}
}
When you use setContentView(R.layout.exchange_message)
, the layout R.layout.exchange_message
will be inflated and associated to your activity. If you want to retrieve a View from that layout, you just call findViewById(R.id.MyId);
.
But if your View is not inside the layout, you will have a NPException.
To retrieve views from another layout, you have to inflate it first, and then call myView.findViewById(R.id.MyId)
.
For instance, according to your case, if you want to use the ListView
from the popup.xml
layout file :
View popupView = layoutInflater.inflate(R.layout.popup, null);
ListView list = popupView.findViewById(R.id.listOfUserOnline);
这篇关于如何处理NullPointerException异常的机器人?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!