-2
我想從Fragment Activity移動到另一個Fragment Activity,但是我在設備上運行時得到NullPointerException,而不是在模擬器上正確運行任何幫助?謝謝。當從FragmentActivity移動到另一個FragmentActivity時出現NullPointerException
編輯:這是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
這是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;
}
logcat。發表它。 – poss
@Hosny代碼在哪裏? –
@Hosny從'MainPageActivity.java'發佈你的'onCreateView'方法代碼,並且請標記它的哪一行是#64 – Jon