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

  • SEARCH
  • Home
  • 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 8229123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:41:39+00:00 2026-06-07T16:41:39+00:00

I’ve got a problem which makes me crazy because it looks like a simple

  • 0

I’ve got a problem which makes me crazy because it looks like a simple one …
When I try to getting a view by it’s ressources (a simple operation that i’ve done multiples times before ) with findRessourcesById, it throwns a NullPointerException when I access in onCreate of my main activity, or a RessourcesNotFoundException when I do this in my PagerAdapter.
In facts it doesn’t work anywhere …
Here my mainActivity :

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.NavUtils;
import android.support.v4.view.ViewPager;

public class MainActivity extends Activity {
ViewPager myPager;
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Fiche f = new Fiche();
    FicheAdapter adapter;
    adapter = new FicheAdapter(f);
    myPager = (ViewPager) findViewById(R.id.pager);
    myPager.setAdapter(adapter);
    myPager.setCurrentItem(0);

    TextView tv = (TextView) findViewById(R.id.nom);
    // HERE IT THROWNS EXCEPTION
    tv.setText("Hello ?");
}

my R.java file :

public final class R {
        .. ...
public static final class id {
    ... ... ...
    public static final int matricule=0x7f080019;
    public static final int menu_settings=0x7f08001d;
    public static final int nom=0x7f08001a;
    public static final int pager=0x7f080001;
    public static final int prenom=0x7f08001b;
    ... ... 
    }
}

I dont think I need to show you my layout , because Eclipse would have seen it if there was a wrong id … 😉 (it’s ok)
I’ve tried “clean”, but no effects … I’ve had a similar error before with an import of R of another project but here no imports of R are made…

I’d appreciate any help, because i’m stuck here . !!

Thanks a lot

Nico

EDIT : my log => where there is CausedBy NUll Pointer Exception at mainactivity : 27 , this is the line i’ve marked on my code above …
07-15 19:54:56.460: E/AndroidRuntime(22836): FATAL EXCEPTION: main
07-15 19:54:56.460: E/AndroidRuntime(22836): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.main.courante.e/com.example.main.courante.e.MainActivity}: java.lang.NullPointerException
07-15 19:54:56.460: E/AndroidRuntime(22836): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1751)
07-15 19:54:56.460: E/AndroidRuntime(22836): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1767)
07-15 19:54:56.460: E/AndroidRuntime(22836): at android.app.ActivityThread.access$1500(ActivityThread.java:122)
07-15 19:54:56.460: E/AndroidRuntime(22836): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1005)
07-15 19:54:56.460: E/AndroidRuntime(22836): at android.os.Handler.dispatchMessage(Handler.java:99)
07-15 19:54:56.460: E/AndroidRuntime(22836): at android.os.Looper.loop(Looper.java:132)
07-15 19:54:56.460: E/AndroidRuntime(22836): at android.app.ActivityThread.main(ActivityThread.java:4028)
07-15 19:54:56.460: E/AndroidRuntime(22836): at java.lang.reflect.Method.invokeNative(Native Method)
07-15 19:54:56.460: E/AndroidRuntime(22836): at java.lang.reflect.Method.invoke(Method.java:491)
07-15 19:54:56.460: E/AndroidRuntime(22836): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:844)
07-15 19:54:56.460: E/AndroidRuntime(22836): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
07-15 19:54:56.460: E/AndroidRuntime(22836): at dalvik.system.NativeStart.main(Native Method)
07-15 19:54:56.460: E/AndroidRuntime(22836): Caused by: java.lang.NullPointerException
07-15 19:54:56.460: E/AndroidRuntime(22836): at com.example.main.courante.e.MainActivity.onCreate(MainActivity.java:27)
07-15 19:54:56.460: E/AndroidRuntime(22836): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
07-15 19:54:56.460: E/AndroidRuntime(22836): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1715)

and my main_layout.xml :

<LinearLayout 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:orientation="horizontal" >

 <fragment android:name="com.example.main.courante.e.DateList"
 android:id="@+id/list_frag"
 android:tag="list"
 android:layout_width="0dip"
 android:layout_height="fill_parent"
 android:layout_weight="1"/> 

<android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="0dip"
        android:layout_height="match_parent"
        android:layout_weight="3" />

</LinearLayout>

This is InstantiateItem method from my pageAdapter :

    public Object instantiateItem(View collection, int position) {

    LayoutInflater inflater = (LayoutInflater) collection.getContext()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    int resId = 0;
    switch (position) {
    case 0:
        resId = R.layout.checks_matin;
        break;
    case 1:
        resId = R.layout.checks_soir;
        break;
    }

    View view = inflater.inflate(resId, null);
    TextView tv = (TextView) view.findViewById(R.id.matricule);    
    tv.setText(fiche.getMatricule());
    tv = (TextView) view.findViewById(R.id.nom);
    tv.setText(fiche.getNom());
    ((ViewPager) collection).addView(view, 0);

    return view;
}

Even here it thowns an exception whereas in both of my layout checks_matin/soir, the id nom/matricule etc exists …

  • 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-07T16:41:40+00:00Added an answer on June 7, 2026 at 4:41 pm

    OK I’ve found some useful links here : Android ViewPager findViewById not working – Always returning null

    so here is the starting of my checks_matin.xml

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:gravity="center"
    android:id="@+id/linear" >
    
    
    
    <!--  <include xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        layout="@layout/top_layout"
        android:id="@+id/inc_top" /> -->
    
    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:gravity="center"
        android:id="@+id/top_lin" >
    
    
    
        <TextView
            android:id="@+id/matricule"
            style="@style/textview_info"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="matricule"
            android:layout_marginLeft="25dip" 
            android:layout_marginRight="25dip" />
    

    i’ve commented the include to test…
    and here my new java code in instantiateItem :

     LinearLayout view = (LinearLayout)inflater.inflate(resId, null);
        LinearLayout v1 = (LinearLayout)view.findViewById(R.id.linear);
        LinearLayout v2 = (LinearLayout)v1.findViewById(R.id.top_lin);
        TextView tv = (TextView) v2.findViewById(R.id.matricule);    
        tv.setText(fiche.getMatricule());
    

    But it STILL doesn’t work !!! I’m out of ideas here … :/

    EDIT : IT does work !! juste remove this line from above :

    LinearLayout v1 = (LinearLayout)view.findViewById(R.id.linear);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to run a str_replace or preg_replace which looks for certain words
I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm making a simple page using Google Maps API 3. My first. One marker
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small

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.