0

I am getting a null pointer exception error at runtime.I am mentioned the error line in below coding.I am posted the codes relevant to that.I am unable to solve this.Anybody can help me if you know how to solve these.Thank You.

StackTrace:

11-03 05:14:58.729: E/AndroidRuntime(18247): java.lang.NullPointerException
11-03 05:14:58.729: E/AndroidRuntime(18247):    at com.qrme.FragmentPage.highlightCell(FragmentPage.java:473)
11-03 05:14:58.729: E/AndroidRuntime(18247):    at com.qrme.FragmentPage.moveToNext(FragmentPage.java:455)
11-03 05:14:58.729: E/AndroidRuntime(18247):    at com.qrme.FragmentPage$10.onItemClick(FragmentPage.java:351)
11-03 05:14:58.729: E/AndroidRuntime(18247):    at android.widget.AdapterView.performItemClick(AdapterView.java:299)
11-03 05:14:58.729: E/AndroidRuntime(18247):    at android.widget.AbsListView.performItemClick(AbsListView.java:1113)
11-03 05:14:58.729: E/AndroidRuntime(18247):    at android.widget.AbsListView$PerformClick.run(AbsListView.java:2904)
11-03 05:14:58.729: E/AndroidRuntime(18247):    at android.widget.AbsListView$3.run(AbsListView.java:3638)
11-03 05:14:58.729: E/AndroidRuntime(18247):    at android.os.Handler.handleCallback(Handler.java:733)
11-03 05:14:58.729: E/AndroidRuntime(18247):    at android.os.Handler.dispatchMessage(Handler.java:95)
11-03 05:14:58.729: E/AndroidRuntime(18247):    at android.os.Looper.loop(Looper.java:136)
11-03 05:14:58.729: E/AndroidRuntime(18247):    at android.app.ActivityThread.main(ActivityThread.java:5017)
11-03 05:14:58.729: E/AndroidRuntime(18247):    at java.lang.reflect.Method.invokeNative(Native Method)
11-03 05:14:58.729: E/AndroidRuntime(18247):    at java.lang.reflect.Method.invoke(Method.java:515)
11-03 05:14:58.729: E/AndroidRuntime(18247):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
11-03 05:14:58.729: E/AndroidRuntime(18247):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
11-03 05:14:58.729: E/AndroidRuntime(18247):    at dalvik.system.NativeStart.main(Native Method)

FragmentPage.java:

public class FragmentPage extends Fragment {

    GridView gridTable;
static LinearLayout ll;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {

         rootView = inflater.inflate(R.layout.fragmentxml, container, false);

        initialize(rootView);
        clickEvents();

        return rootView;

    }


    @Override
    public void onResume() {
        // TODO Auto-generated method stub
        super.onResume();

    tablelist = DatabaseQueryHelper.getInstance().getContentTable(pageId);
        System.out.println(tablelist);
        System.out.println(pageId);
        if (tablelist != null && !tablelist.isEmpty()) {
            CustomeTableAdapter tableAdapter = new CustomeTableAdapter(
                    getActivity(), R.layout.frame_table, tablelist);
            gridTable.setAdapter(tableAdapter);

        } else {
            ll.setVisibility(View.GONE);
            if(tableVisible && !getactivitytable)
            {
                if (tablelist == null
                        || tablelist.isEmpty()
                        && sharedpreference.get_sharedvalue(
                                QRMConstants.VERSION).equals("1.0")) {
                    showDialog();


                }

            }
        }

    }


public void initialize(View v) {


        gridTable = (GridView) rootView.findViewById(R.id.gridViewTable);
        ll.setVisibility(View.GONE);

        gridTable.setDrawSelectorOnTop(true);

    }

public void moveToNext(int nextposition) {

        highlightCell(nextposition); --->455 th line error
        ispaused = false;
        play(nextposition);

    }

gridTable.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                    final int position, long id) {
                if (tablelist != null && !tablelist.isEmpty()) {
                    ll.setVisibility(View.VISIBLE);
                    player.reset();
                    currentSelection = position;
                    moveToNext(currentSelection); --->351 th line error
                } else {
                    ll.setVisibility(View.GONE);
                }
            }
        });

public void highlightCell(int position) {

        for (int i = 1; i < tablelist.size(); i++) {

            gridTable.getChildAt(i - 1)
                    .setBackgroundResource(R.drawable.border); ---->473 rd line Error

        }

        gridTable.getChildAt(position).setBackgroundColor(
                getResources().getColor(R.color.dusty_grey));

    }

fragmentxml.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/relativeLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <LinearLayout
    android:id="@+id/linearlayoutControll"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:background="@color/light_grey"
    android:gravity="center"
    android:orientation="horizontal" >

    <ImageButton
        android:id="@+id/imagebuttonLast"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:background="@drawable/ic_action_previous"
        android:scaleType="fitXY" />
      </LinearLayout>
      <GridView
        android:id="@+id/gridViewTable"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/linearlayoutControll"
        android:layout_alignParentTop="true"
        android:layout_margin="15dp"
        android:listSelector="#00000000"
        android:numColumns="2"
        android:rotationY="180" >
    </GridView>

</RelativeLayout>
User 10
  • 129
  • 5
  • 11
  • possible duplicate of [What is a Null Pointer Exception, and how do I fix it?](http://stackoverflow.com/questions/218384/what-is-a-null-pointer-exception-and-how-do-i-fix-it) – Robby Cornelissen Nov 04 '14 at 03:20
  • Looks like `gridTable.getChildAt(i - 1)` is `null` for some value of `i`. Start by checking there. –  Nov 04 '14 at 03:22
  • try this ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.fragmentxml, container, false); – M S Gadag Nov 04 '14 at 04:14

0 Answers0