Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android ArrayAdapter中的java.lang.NullPointerException_Android - Fatal编程技术网

Android ArrayAdapter中的java.lang.NullPointerException

Android ArrayAdapter中的java.lang.NullPointerException,android,Android,从Google Play“Crash&ANR”中,我看到我的用户在错误下面。我自己无法重现这个错误。 我有ArrayAdapter类公共类讨论ArrayAdapter扩展ArrayAdapter{,它被用作另一个活动中的列表项: 首先,我不知道问题是在ArrayAdapter类中还是在活动中。如果您建议在哪里查找错误,至少会有所帮助。例如,shell将重点放在ArrayAdapter的getView方法上 下面是ArrayAdaper的getView方法 java.lang.NullPointe

从Google Play“Crash&ANR”中,我看到我的用户在错误下面。我自己无法重现这个错误。 我有ArrayAdapter类公共类讨论ArrayAdapter扩展ArrayAdapter{,它被用作另一个活动中的列表项:

首先,我不知道问题是在ArrayAdapter类中还是在活动中。如果您建议在哪里查找错误,至少会有所帮助。例如,shell将重点放在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;
    }

那么第84行是哪一行呢?我打赌myactivity是null:D我开玩笑的..你的适配器是在单独的类中还是在内部类中?第84行:最终长seqf=coment.seq;@user836026
coment
可能是null。。。