Question

E/AndroidRuntime(8477): FATAL EXCEPTION: main
E/AndroidRuntime(8477): java.lang.NullPointerException
E/AndroidRuntime(8477):     at android.content.ComponentName.<init>(ComponentName.java:75)
E/AndroidRuntime(8477):     at android.content.Intent.<init>(Intent.java:3518)
E/AndroidRuntime(8477):     at com.package.name.library.AllTab$1.onItemClick(AllTab.java:66)
E/AndroidRuntime(8477):     at android.widget.AdapterView.performItemClick(AdapterView.java:298)
E/AndroidRuntime(8477):     at android.widget.AbsListView.performItemClick(AbsListView.java:1102)
E/AndroidRuntime(8477):     at android.widget.AbsListView$PerformClick.run(AbsListView.java:2751)
E/AndroidRuntime(8477):     at android.widget.AbsListView$1.run(AbsListView.java:3426)
E/AndroidRuntime(8477):     at android.os.Handler.handleCallback(Handler.java:725)
E/AndroidRuntime(8477):     at android.os.Handler.dispatchMessage(Handler.java:92)
E/AndroidRuntime(8477):     at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(8477):     at android.app.ActivityThread.main(ActivityThread.java:5229)
E/AndroidRuntime(8477):     at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(8477):     at java.lang.reflect.Method.invoke(Method.java:525)
E/AndroidRuntime(8477):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:799)
E/AndroidRuntime(8477):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:566)
E/AndroidRuntime(8477):     at dalvik.system.NativeStart.main(Native Method)

The gridview has an image and one line of text for each item. The error is in the onItemClick here, I set up a test layout and class to see if it would send information there.

Can't figure out why it is throwing this error since I'm pretty sure I have the correct practice. Here is my code, is it something to do with using a SherlockFragment?:

public class AllTab extends SherlockFragment {

GridView gridView;
TextView itemLabel;
Context mContext;
static final String[] mobile_os = new String[] {
lots of string here };

@Override
public SherlockFragmentActivity getSherlockActivity() {
    return super.getSherlockActivity();
}

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstaceState) {
    View view = inflater.inflate(R.layout.gridview_alltab, container, false);

    gridView = (GridView) view.findViewById(R.id.AllTabGridView);
    itemLabel = (TextView) view.findViewById(R.id.item_label);
    gridView.setAdapter(new AllTabImageAdapter(getSherlockActivity(), mobile_os));

    gridView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View view, int position,
                long arg3) {

            switch(position) {
            case 0:
                Intent one = new Intent(mContext, Test.class);
                one.putExtra("databaseUrl", "SELECT * FROM stuffs");
                startActivity(one);
                break;
            }
        }

    });

    return view;
}

@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    setUserVisibleHint(true);
} 

All help appreciated thanks.

Was it helpful?

Solution

You have mContext listed as a variable, but it is never set.

try :

mContext = this;

or maybe mContext = getActivity(); // for a fragment

somewhere within OnCreateView()

OTHER TIPS

your line

static final String[] mobile_os = "lots and lots of strings here"
};

should be

static final String[] mobile_os = { "lots and lots of strings here"
};

i think the missing opening bracket is what's breaking your app

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top