Google Play の「クラッシュと ANR」から、ユーザーが以下のエラーになっていることがわかります。自分でエラーを再現できませんでした。別のアクティビティで listItem として使用されるArrayAdapter クラスpublic class DiscussArrayAdapter extends ArrayAdapter{があります。
まず、問題が ArrayAdaper クラスにあるのかアクティビティにあるのかわかりません。少なくとも、どこでエラーを探すべきかアドバイスしていただければ助かります。たとえばシェルでは、ArrayAdapter の getView メソッドに注目しますか?
ArrayAdaper の getView メソッドは以下です。
java.lang.NullPointerException
at com.castvast.DiscussArrayAdapter.getView(DiscussArrayAdapter.java:84)
at android.widget.AbsListView.obtainView(AbsListView.java:2461)
at android.widget.ListView.makeAndAddView(ListView.java:1775)
at android.widget.ListView.fillUp(ListView.java:712)
at android.widget.ListView.correctTooHigh(ListView.java:1401)
at android.widget.ListView.fillSpecific(ListView.java:1339)
at android.widget.ListView.layoutChildren(ListView.java:1618)
at android.widget.AbsListView.onLayout(AbsListView.java:2296)
at android.view.View.layout(View.java:14055)
at android.view.ViewGroup.layout(ViewGroup.java:4604)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1655)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1513)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1426)
at android.view.View.layout(View.java:14055)
at android.view.ViewGroup.layout(ViewGroup.java:4604)
at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
at android.view.View.layout(View.java:14055)
at android.view.ViewGroup.layout(ViewGroup.java:4604)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1655)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1513)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1426)
at android.view.View.layout(View.java:14055)
at android.view.ViewGroup.layout(ViewGroup.java:4604)
at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
at android.view.View.layout(View.java:14055)
at android.view.ViewGroup.layout(ViewGroup.java:4604)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1992)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1813)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1112)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4472)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
at android.view.Choreographer.doCallbacks(Choreographer.java:555)
at android.view.Choreographer.doFrame(Choreographer.java:525)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4898)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
at dalvik.system.NativeStart.main(Native Method)
取得方法:
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
if (row == null) {
LayoutInflater inflater = (LayoutInflater) this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = inflater.inflate(R.layout.listitem_discuss, parent, false);
}
wrapper = (LinearLayout) row.findViewById(R.id.wrapper);
OneMessage coment = getItem(position);
myactivity.itemPostin=position;
ImageView arrowImage = (ImageView) row.findViewById(R.id.aquaplayicon);
final ImageView arrowImageFinal=arrowImage;
final long seqf=coment.seq ;
final String userlinkF=coment.userlink ;
arrowImage.setOnClickListener(new OnClickListener(){
public void onClick(View view) {
;
myactivity.openContextMenu(arrowImageFinal);
myactivity.seq=seqf;
myactivity.userlink=userlinkF;
;
}});
arrowImage.setOnLongClickListener(new OnLongClickListener(){
@Override
public boolean onLongClick(View v) {
;
myactivity.openContextMenu(arrowImageFinal);
myactivity.seq=seqf;
myactivity.userlink=userlinkF;
return true;
}});
myactivity .registerForContextMenu(arrowImage);
msgTextView =(TextView)/*(EditText)*/ row.findViewById(R.id.comment);
myactivity .registerForContextMenu(msgTextView );
final TextView myTextViewFinal=msgTextView;
msgTextView.setOnClickListener(new OnClickListener(){
public void onClick(View view) {
;
myactivity.openContextMenu( myTextViewFinal);
myactivity.seq=seqf;
//copy funcation
//cast the received View to TextView so that you can get its text
TextView yourTextView = (TextView) view;
Activity host = (Activity) yourTextView.getContext();
//place your TextView's text in clipboard
android.text.ClipboardManager clipboard = ( android.text.ClipboardManager) host.getSystemService(host.CLIPBOARD_SERVICE );
clipboard.setText(yourTextView.getText());
;
}});
msgTextView.setOnLongClickListener(new OnLongClickListener(){
@Override
public boolean onLongClick(View v) {
;
myactivity.openContextMenu( myTextViewFinal);
myactivity.seq=seqf;
//copy funcation
//cast the received View to TextView so that you can get its text
TextView yourTextView = (TextView) v;
Activity host = (Activity) yourTextView.getContext();
//place your TextView's text in clipboard
android.text.ClipboardManager clipboard = ( android.text.ClipboardManager) host.getSystemService(host.CLIPBOARD_SERVICE );
clipboard.setText(yourTextView.getText());
return true;
}});
msgTextView.setText(coment.msgText);
//msgTextView.setGravity(!coment.sentbyuser ? Gravity.LEFT : Gravity.RIGHT) ;
sender = (TextView) row.findViewById(R.id.sender);
PrettyTime p = new PrettyTime();
String device_Lang= Locale.getDefault().getLanguage();//getDisplayLanguage();
String dateFormat=null;
if(device_Lang==null || !device_Lang.equals("ar") )
{
dateFormat= p.format(new Date( coment.msgDate.getTime() ));
}else
{ //just display numric
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy h:mm a", Locale.getDefault() );
long duration =coment.msgDate.getTime();
dateFormat=sdf.format(new Date(duration /*- TimeZone.getDefault().getRawOffset()*/ ));
}
if(coment.sentbyuser)
sender.setText(row.getContext().getResources().getString(R.string.sender_marker)+" @ "+dateFormat );
else
sender.setText(coment.senderName+" @ "+dateFormat );
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
RelativeLayout.LayoutParams params2 = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
params.setMargins(5, 5, 5, 0);
params2.setMargins(0, 0, 0, 0);
if(!coment.sentbyuser)
{
params.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
params2.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
params2.addRule(RelativeLayout.BELOW, msgTextView.getId());
// no need to show arrow image
arrowImage.setVisibility(View.VISIBLE);
}
else
{
params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE);
params2.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE);
params2.addRule(RelativeLayout.BELOW, msgTextView.getId());
arrowImage.setVisibility(View.GONE);
}
msgTextView.setLayoutParams(params);//msgTextView.setPadding(10, 0, 10, 0);
sender.setLayoutParams(params2);//sender.setPadding(10, 0, 10, 0);
msgTextView.setBackgroundResource(!coment.sentbyuser ? R.drawable.bubble_yellow : R.drawable.bubble_green);
wrapper.setGravity(!coment.sentbyuser ? Gravity.LEFT : Gravity.RIGHT);
return row;
}