I've decided after using HTML5 for so long and having got a reasonable
understanding of it to wade in to Java for Android. Using the Wizard in
Eclipse ( Scrollable Tabs + Swipe ) and the ADT I've created a basic tabbed
menu.
My problem is that I have been attempting to take that example further so I
can refer to different layouts on each tab. I've refereed to two different
threads on here the results of which you can see as attached code.
Application opens up fine until I slide to the next screen/fragment.
I'm still finding my feet with the log cat but to me the attached log
doesnt point to a specific error place only that the error occurs.
I would love to get some advice on where to look, if you can see the issue
or some general pointers to send me in the right direction.
Thanks In Advance
10-28 23:20:17.002: W/dalvikvm(1432): threadid=1: thread exiting with
uncaught exception (group=0x40a13300) 10-28 23:20:17.064:
E/AndroidRuntime(1432): FATAL EXCEPTION: main 10-28 23:20:17.064:
E/AndroidRuntime(1432): java.lang.NullPointerException 10-28 23:20:17.064:
E/AndroidRuntime(1432): at
android.support.v4.app.BackStackRecord.doAddOp(BackStackRecord.java:394)
10-28 23:20:17.064: E/AndroidRuntime(1432): at
android.support.v4.app.BackStackRecord.add(BackStackRecord.java:389) 10-28
23:20:17.064: E/AndroidRuntime(1432): at
android.support.v4.app.FragmentPagerAdapter.instantiateItem(FragmentPagerAdapter.java:99)
10-28 23:20:17.064: E/AndroidRuntime(1432): at
android.support.v4.view.ViewPager.addNewItem(ViewPager.java:800) 10-28
23:20:17.064: E/AndroidRuntime(1432): at
android.support.v4.view.ViewPager.populate(ViewPager.java:991) 10-28
23:20:17.064: E/AndroidRuntime(1432): at
android.support.v4.view.ViewPager.populate(ViewPager.java:880) 10-28
23:20:17.064: E/AndroidRuntime(1432): at
android.support.v4.view.ViewPager$3.run(ViewPager.java:238) 10-28
23:20:17.064: E/AndroidRuntime(1432): at
android.view.Choreographer$CallbackRecord.run(Choreographer.java:725) 10-28
23:20:17.064: E/AndroidRuntime(1432): at
android.view.Choreographer.doCallbacks(Choreographer.java:555) 10-28
23:20:17.064: E/AndroidRuntime(1432): at
android.view.Choreographer.doFrame(Choreographer.java:524) 10-28
23:20:17.064: E/AndroidRuntime(1432): at
android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
10-28 23:20:17.064: E/AndroidRuntime(1432): at
android.os.Handler.handleCallback(Handler.java:615) 10-28 23:20:17.064:
E/AndroidRuntime(1432): at
android.os.Handler.dispatchMessage(Handler.java:92) 10-28 23:20:17.064:
E/AndroidRuntime(1432): at android.os.Looper.loop(Looper.java:137) 10-28
23:20:17.064: E/AndroidRuntime(1432): at
android.app.ActivityThread.main(ActivityThread.java:4745) 10-28
23:20:17.064: E/AndroidRuntime(1432): at
java.lang.reflect.Method.invokeNative(Native Method) 10-28 23:20:17.064:
E/AndroidRuntime(1432): at java.lang.reflect.Method.invoke(Method.java:511)
10-28 23:20:17.064: E/AndroidRuntime(1432): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
10-28 23:20:17.064: E/AndroidRuntime(1432): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 10-28
23:20:17.064: E/AndroidRuntime(1432): at
dalvik.system.NativeStart.main(Native Method)
import java.util.Locale;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
public class DodActivity extends FragmentActivity {
/**
* The {@link android.support.v4.view.PagerAdapter} that will provide
* fragments for each of the sections. We use a
* {@link android.support.v4.app.FragmentPagerAdapter} derivative, which
* will keep every loaded fragment in memory. If this becomes too memory
* intensive, it may be best to switch to a
* {@link android.support.v4.app.FragmentStatePagerAdapter}.
*/
SectionsPagerAdapter mSectionsPagerAdapter;
/**
* The {@link ViewPager} that will host the section contents.
*/
ViewPager mViewPager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dod);
// Create the adapter that will return a fragment for each of the three
// primary sections of the app.
mSectionsPagerAdapter = new SectionsPagerAdapter(
getSupportFragmentManager());
// Set up the ViewPager with the sections adapter.
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(mSectionsPagerAdapter);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.dod, menu);
return true;
}
/**
* A {@link FragmentPagerAdapter} that returns a fragment corresponding to
* one of the sections/tabs/pages.
*/
public class SectionsPagerAdapter extends FragmentPagerAdapter {
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int i) {
// getItem is called to instantiate the fragment for the given
page.
//
http://stackoverflow.com/questions/15591087/android-navigation-type-fixed-tabs-swipe/15591125#15591125
//
http://stackoverflow.com/questions/11708937/how-can-i-create-a-ui-for-each-tab-of-a-tabbed-activity
// FOCUS ON EDITING HERE
Fragment fragment = null;
switch(i){
case 0:
fragment = new dod_mainpage_SectionFragment();
break;
case 1:
fragment = new dod_events_SectionFragment();
break;
case 3:
fragment = new dod_map_SectionFragment();
break;
default:
//
}
return fragment;
}
@Override
public int getCount() {
// Show 3 total pages.
return 3;
}
@Override
public CharSequence getPageTitle(int position) {
Locale l = Locale.getDefault();
switch (position) {
case 0:
return getString(R.string.title_section1).toUpperCase(l);
case 1:
return getString(R.string.title_section2).toUpperCase(l);
case 2:
return getString(R.string.title_section3).toUpperCase(l);
}
return null;
}
}
public static class dod_mainpage_SectionFragment extends Fragment {
public dod_mainpage_SectionFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_dod_mainpage, null);
return v;
}
}
public static class dod_events_SectionFragment extends Fragment {
public dod_events_SectionFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_dod_events, null);
return v;
}
}
public static class dod_eventsdetail_SectionFragment extends Fragment {
public dod_eventsdetail_SectionFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_dod_eventsdetail, null);
return v;
}
}
public static class dod_map_SectionFragment extends Fragment {
public dod_map_SectionFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_dod_map, null);
return v;
}
}
public static class dod_settings_SectionFragment extends Fragment {
public dod_settings_SectionFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_dod_settings, null);
return v;
}
}
}
--
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
---
You received this message because you are subscribed to the Google Groups
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.