Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8687133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:02:39+00:00 2026-06-12T23:02:39+00:00

The following code throws a NullPointerException and I do not know why. The problem

  • 0

The following code throws a NullPointerException and I do not know why. The problem seems that I am not referencing the EditText objects correctly. But I don’t know how to make it correct.

Here the interesting part of my code:

private static ArrayList<String> roomList = new ArrayList<String>();
    private static ArrayList<String> deviceList = new ArrayList<String>();

    private static String project_name;
    private static String router_ip;
    private static String port;
    private static String device_name;
    private static String room_name;
    private static String datatype;
    private static String grpaddr;
    private static boolean status;

    private EditText et_project_name;
    private EditText et_router_ip;
    private EditText et_port;

    private Spinner spinner_dpt; 
    private CheckBox cb_checkStatus;
    private EditText et_device_name;
    private EditText et_groupaddress;
    private View textEntryView;

    private static final String[] items={"1.001 (Lichtschalter)", "5.001 (Dimmer/Jalousien)",
          "9.001 (Temperaturanzeige)", "1.008 (Jalousien)"};

    private SectionsPagerAdapter mSectionsPagerAdapter;
    private ViewPager mViewPager;

    private static ManualConfigDBAdapter dbHelper;

    /**
     * OnCreate
     * */ 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_create_project_manually);

        setup();
    }

    /**
     * Setup
     * */ 
    public void setup(){

        //DATABASE
        // Add project to Database
        dbHelper = new ManualConfigDBAdapter(this);
        dbHelper.open();

        // 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 action bar.
        final ActionBar actionBar = getActionBar();
        // set the app icon as an action to go home
        actionBar.setDisplayHomeAsUpEnabled(true); 
        //enable tabs in actionbar
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

        // Set up the ViewPager with the sections adapter.
        mViewPager = (ViewPager) findViewById(R.id.pager);
        mViewPager.setAdapter(mSectionsPagerAdapter);

        // When swiping between different sections, select the corresponding tab.
        // We can also use ActionBar.Tab#select() to do this if we have a reference to the
        // Tab.
        mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
            @Override
            public void onPageSelected(int position) {
                actionBar.setSelectedNavigationItem(position);
            }
        });

        // For each of the sections in the app, add a tab to the action bar.
        for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
            // Create a tab with text corresponding to the page title defined by the adapter.
            // Also specify this Activity object, which implements the TabListener interface, as the
            // listener for when this tab is selected.
            actionBar.addTab(
                    actionBar.newTab()
                            .setText(mSectionsPagerAdapter.getPageTitle(i))
                            .setTabListener(this));
        }


        //get the controls from the layout
        et_project_name = (EditText) mViewPager.findViewById(R.id.project_name);
        et_router_ip = (EditText) mViewPager.findViewById(R.id.router_ip);
        et_port = (EditText) mViewPager.findViewById(R.id.port);

        //Use a input filter for the input of the IP adress
        InputFilter[] filters = new InputFilter[1];
        filters[0] = new InputFilter() {
            public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
                if (end > start) {
                    String destTxt = dest.toString();
                    String resultingTxt = destTxt.substring(0, dstart) + source.subSequence(start, end) + destTxt.substring(dend);
                    if (!resultingTxt.matches ("^\\d{1,3}(\\.(\\d{1,3}(\\.(\\d{1,3}(\\.(\\d{1,3})?)?)?)?)?)?")) { 
                        return "";
                    } else {
                        String[] splits = resultingTxt.split("\\.");
                        for (int i=0; i<splits.length; i++) {
                            if (Integer.valueOf(splits[i]) > 255) {
                                return "";
                            }
                        }
                    }
                }
            return null;
            }
        };

        et_router_ip.setFilters(filters);

    }

And LogCat:

02-16 20:09:25.755: E/AndroidRuntime(26658): FATAL EXCEPTION: main
02-16 20:09:25.755: E/AndroidRuntime(26658): java.lang.RuntimeException: Unable to start activity ComponentInfo{de.bertrandt.bertrandtknx/de.bertrandt.bertrandtknx.CreateProjectManually}: java.lang.NullPointerException
02-16 20:09:25.755: E/AndroidRuntime(26658):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1970)
02-16 20:09:25.755: E/AndroidRuntime(26658):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1995)
02-16 20:09:25.755: E/AndroidRuntime(26658):    at android.app.ActivityThread.access$600(ActivityThread.java:128)
02-16 20:09:25.755: E/AndroidRuntime(26658):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161)
02-16 20:09:25.755: E/AndroidRuntime(26658):    at android.os.Handler.dispatchMessage(Handler.java:99)
02-16 20:09:25.755: E/AndroidRuntime(26658):    at android.os.Looper.loop(Looper.java:137)
02-16 20:09:25.755: E/AndroidRuntime(26658):    at android.app.ActivityThread.main(ActivityThread.java:4514)
02-16 20:09:25.755: E/AndroidRuntime(26658):    at java.lang.reflect.Method.invokeNative(Native Method)
02-16 20:09:25.755: E/AndroidRuntime(26658):    at java.lang.reflect.Method.invoke(Method.java:511)
02-16 20:09:25.755: E/AndroidRuntime(26658):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:993)
02-16 20:09:25.755: E/AndroidRuntime(26658):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760)
02-16 20:09:25.755: E/AndroidRuntime(26658):    at dalvik.system.NativeStart.main(Native Method)
02-16 20:09:25.755: E/AndroidRuntime(26658): Caused by: java.lang.NullPointerException
02-16 20:09:25.755: E/AndroidRuntime(26658):    at de.bertrandt.bertrandtknx.CreateProjectManually.setup(CreateProjectManually.java:152)
02-16 20:09:25.755: E/AndroidRuntime(26658):    at de.bertrandt.bertrandtknx.CreateProjectManually.onCreate(CreateProjectManually.java:75)
02-16 20:09:25.755: E/AndroidRuntime(26658):    at android.app.Activity.performCreate(Activity.java:4562)
02-16 20:09:25.755: E/AndroidRuntime(26658):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1053)
02-16 20:09:25.755: E/AndroidRuntime(26658):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1934)
02-16 20:09:25.755: E/AndroidRuntime(26658):    ... 11 more
02-16 20:09:25.770: D/dalvikvm(26658): GC_CONCURRENT freed 396K, 4% free 14704K/15303K, paused 2ms+3ms

The used xml-file:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/black" >




    <RelativeLayout
        android:id="@+id/project_save_text"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:background="@color/black"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:layout_marginTop="10dp"
            android:text="@string/project_name"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <EditText
            android:id="@+id/project_name"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/textView2"
            android:ems="10"
            android:hint="@string/project_name_hint" >
        </EditText>

        <TextView
            android:id="@+id/textView4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/project_name"
            android:layout_marginTop="10dp"
            android:text="@string/router_ip"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <EditText
            android:id="@+id/router_ip"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/textView4"
            android:digits="0123456789."
            android:ems="10"
            android:hint="@string/router_adress_info"
            android:inputType="numberDecimal|phone" />

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:contentDescription="@string/placeholder"
            android:src="@drawable/bertrandtlogoinv" />

        <TextView
            android:id="@+id/info_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_above="@+id/imageView1"
            android:layout_alignParentLeft="true"
            android:gravity="center"
            android:text="@string/info_settings"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:textSize="16dp" />

        <ImageView
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/ImageView1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_above="@+id/info_text"
            android:layout_alignParentLeft="true"
            android:contentDescription="@string/placeholder"
            android:paddingBottom="2dp"
            android:paddingLeft="5dp"
            android:paddingRight="5dp"
            android:paddingTop="2dp"
            android:scaleType="fitXY"
            android:src="@color/ics_blue" />

        <ImageView
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/ImageView01"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignTop="@+id/imageView1"
            android:contentDescription="@string/placeholder"
            android:paddingBottom="2dp"
            android:paddingLeft="5dp"
            android:paddingRight="5dp"
            android:paddingTop="2dp"
            android:scaleType="fitXY"
            android:src="@color/ics_blue" />


        <TextView
            android:id="@+id/textView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/router_ip"
            android:layout_marginTop="10dp"
            android:text="@string/Port"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <EditText
            android:id="@+id/port"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/textView3"
            android:digits="0123456789"
            android:ems="10"
            android:hint="@string/port_hint"
            android:inputType="number"
            android:maxLength="5" />

    </RelativeLayout>

</RelativeLayout>

The following line throws the error:

et_router_ip.setFilters(filters);

SOLUTION

To create a 3 different fragments with view pager you should:

1)Create FragmentActivity with view pager and view pager adapter.

2)Create 3 Fragments with static instance

public final class Fragment1 extends Fragment
{   
    public static Fragment1 newInstance() {
        return new Fragment1();
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        LinearLayout layout = new LinearLayout(getActivity());
// your fragment xml view
        return view;
    }
}

3)Fill view pager adapter with it;

public class FragmentAdapter extends FragmentPagerAdapter

{    
    public InstallFragmentAdapter(FragmentManager fm) {
        super(fm);
    }
    @Override
    public Fragment getItem(int position) {     
        switch (position) {
            case 0:
                return Fragment1.newInstance();
            case 1:
                return Fragment2.newInstance();
            case 2:
                return Fragment3.newInstance();
        }
        return null;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T23:02:40+00:00Added an answer on June 12, 2026 at 11:02 pm

    R.id.router_ip exists but it does not exist within a ViewPager element with the id of pager according to all the code you have posted. By calling findViewById() on the reference to your ViewPager you are only looking within that ViewPager object for R.id.router_ip and not globally within all inflated XML elements.

    If the above XML file called is not called activity_create_project_manually.xml, then your problem extends from not having inflated the required XML into memory before using elements within it.

    setContentView() inflates an XML file into memory. You can also do it with a LayoutInflater but I don’t think this solution is for you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following code does not work, and throws a RuntimeException caused by NullPointerException public
The following code works fine on Linux but throws an exception on OS X
The following code throws NullPointerException : int num = Integer.getInteger(123); Is my compiler invoking
The following code throws a NullPointerException . import java.io.*; public class NullFinalTest { public
I do not understand why a java.lang.NullPointerException is thrown with the following code (at
I have the following code for iAds. [_iAdAdView setCurrentContentSizeIdentifier:ADBannerContentSizeIdentifierPortrait]; But this code throws EXC_BAD_ACCESSS
I'm getting a strange NullPointerException, evidently thrown by the following line of code: Iterator<Note>
The following code throws an compile-time error like Cannot convert type 'string' to 'int'
The following code throws System.UriFormatException: var uri = new UriBuilder(ftp://user:pass#word@ftp.somewhere.com:21/fu/bar.zip); System.UriFormatException: Invalid URI: A
The following code throws a TransactionAbortedException with message The transaction has aborted and an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.