-2

I want to move from Fragment Activity is as Splash Screen to another Fragment Activity has tabs but I get NullPointerException when run on device rather than it run on emulator correctly any help? thanks.

Edit : this is logcat

09-10 00:24:05.139: E/AndroidRuntime(20107): FATAL EXCEPTION: main
09-10 00:24:05.139: E/AndroidRuntime(20107): java.lang.RuntimeException: Unable to start activity ComponentInfo{inet.firstproject/inet.firstproject.MainViewActivity}: java.lang.NullPointerException
09-10 00:24:05.139: E/AndroidRuntime(20107):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2255)
09-10 00:24:05.139: E/AndroidRuntime(20107):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2309)
09-10 00:24:05.139: E/AndroidRuntime(20107):    at android.app.ActivityThread.access$700(ActivityThread.java:157)
09-10 00:24:05.139: E/AndroidRuntime(20107):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1289)
09-10 00:24:05.139: E/AndroidRuntime(20107):    at android.os.Handler.dispatchMessage(Handler.java:99)
09-10 00:24:05.139: E/AndroidRuntime(20107):    at android.os.Looper.loop(Looper.java:176)
09-10 00:24:05.139: E/AndroidRuntime(20107):    at android.app.ActivityThread.main(ActivityThread.java:5317)
09-10 00:24:05.139: E/AndroidRuntime(20107):    at java.lang.reflect.Method.invokeNative(Native Method)
09-10 00:24:05.139: E/AndroidRuntime(20107):    at java.lang.reflect.Method.invoke(Method.java:511)
09-10 00:24:05.139: E/AndroidRuntime(20107):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
09-10 00:24:05.139: E/AndroidRuntime(20107):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
09-10 00:24:05.139: E/AndroidRuntime(20107):    at dalvik.system.NativeStart.main(Native Method)
09-10 00:24:05.139: E/AndroidRuntime(20107): Caused by: java.lang.NullPointerException
09-10 00:24:05.139: E/AndroidRuntime(20107):    at inet.firstproject.MainPageActivity.onCreateView(MainPageActivity.java:64)
09-10 00:24:05.139: E/AndroidRuntime(20107):    at android.support.v4.app.Fragment.performCreateView(Fragment.java:1460)
09-10 00:24:05.139: E/AndroidRuntime(20107):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:911)
09-10 00:24:05.139: E/AndroidRuntime(20107):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1088)
09-10 00:24:05.139: E/AndroidRuntime(20107):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1070)
09-10 00:24:05.139: E/AndroidRuntime(20107):    at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:1861)
09-10 00:24:05.139: E/AndroidRuntime(20107):    at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:547)
09-10 00:24:05.139: E/AndroidRuntime(20107):    at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1181)
09-10 00:24:05.139: E/AndroidRuntime(20107):    at android.app.Activity.performStart(Activity.java:5336)
09-10 00:24:05.139: E/AndroidRuntime(20107):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2227)
09-10 00:24:05.139: E/AndroidRuntime(20107):    ... 11 more

this is oncreateView

   public View onCreateView(LayoutInflater inflater, ViewGroup container,
         Bundle savedInstanceState) {
      if (container == null) {
         return null;
     }
     String []athathTypes={"ggg","lll"};
     Bundle bundle = this.getArguments();
   int type = 0; ;
     if(bundle!=null)
        type= (int) bundle.getLong("Type");


     if(isOnline()){
            con.delegate= this;
            if(isOnline()){
                //con.execute(" http://google.com");
            }
            else
            {
                toast("off line ");
            }
     }
     LinearLayout l= (LinearLayout)inflater.inflate(R.layout.activity_main_page, container, false);
     athathList=(ListView) l.findViewById(R.id.listView1);
   //  athathType=(TextView) l.findViewById(R.id.athathtype);
    // athathType.setText(athathTypes[type]);
     String []images={"a","b"};;
     String[] details={"a","b"};;
     String [] discountedprice={"a","b"};;
     String [] price={"a","b"};;
     String []discount={"a","b"};;
     athathList.setAdapter(new MainAdapter(getActivity(),images,details,discountedprice,price,discount));
     ImageButton deps=(ImageButton) l.findViewById(R.id.departments);
     deps.setOnClickListener(new OnClickListener() {//this is line #64

        @Override
        public void onClick(View arg0) {
            Intent selctionAct=new Intent(getActivity(), SelectionActivity.class);
            startActivity(selctionAct);

        }
    });
     return l;
 }
Hosny
  • 821
  • 1
  • 13
  • 25
  • 2
    @Hosny where is the code?? – diyoda_ Sep 09 '15 at 22:02
  • 2
    @Hosny post your `onCreateView` method code from `MainPageActivity.java` and please mark which line in it is #64 – Jon Sep 09 '15 at 22:56
  • 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) – Selvin Sep 09 '15 at 23:19

1 Answers1

0
 ImageButton deps=(ImageButton) l.findViewById(R.id.departments);

Is returning null.

The reason you are seeing this when you run it on an actual device and not the emulator is, I suspect, because you have multiple layout defined for activity_main_page. Check all versions of this file (landscape/portrait/large/etc..) and make sure they contain the image button with id "departments".

Jon
  • 9,156
  • 9
  • 56
  • 73