-4

I maked a G class:

public class G extends Application {

    public static Context                  context;
    public static LayoutInflater           inflater;
    public static Activity                 currentActivity;
    public static ArrayList<StructAnatomy> notes = new ArrayList<StructAnatomy>();


    @Override
    public void onCreate() {
        super.onCreate();
        context = getApplicationContext();
        inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }
}

and defined G class in AndroidManifest.xml :

<application
    android:name=".G"  //******************************** here
    android:icon="@drawable/icon"
    android:label="@string/app_name" >
    <activity
        android:name=".Home"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".Activity1"
        android:label="@string/app_name" >
    </activity>
</application>

I make a list in Activity1 class and it's activity1.xml (contain list). No Error when program starting by Activity1, but when program starting by Home Activity and then go in Anatomy1 Activity, makeing an Error (NullPointerException). What solution to this problem exists???

this is my Anatomy1 Activity:

public class Anatomy1 extends Activity {

    public ArrayList<StructAnatomy> anatomys1 = new ArrayList<StructAnatomy>();

    public ArrayAdapter             adapter;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.anatomy1);

        ListView listAnatomy1 = (ListView) findViewById(R.id.listAnatomy1);

        adapter = new AdapterAnatomy(anatomys1);
        listAnatomy1.setAdapter(adapter);

        for (int i = 0; i < 10; i++) {
            StructAnatomy anatomy1 = new StructAnatomy();
            anatomy1.title = "ANTERIOR VIEW" + i;

            anatomys1.add(anatomy1);
        }

        adapter.notifyDataSetChanged();
    }
}

LogCat Error: 03-14 12:54:16.288: E/AndroidRuntime(1753): at m.k.Home$1.onTouch(Home.java:45)

Home Activity (some codes):

anatomy1_1.setOnTouchListener(new OnTouchListener() {

    final ImageView anatomy1_1 = (ImageView) findViewById(R.id.anatomy1_1);

        @Override
        public boolean onTouch(View arg0, MotionEvent arg1) {
            anatomy1_1.setImageResource(R.drawable.anatomy1_2);
            Intent intent = new Intent(Home.this, Anatomy1.class);
            Home.this.startActivity(intent);
            return false;
        }
    });
gadolf
  • 1,035
  • 11
  • 19
  • Please post your `logcat` showing your `NullPointerException` also i can't see a call to `setContentView(R.id.your_layout);` – Hughzi Mar 14 '16 at 12:51
  • Logcat stack trace please. – Rohit5k2 Mar 14 '16 at 12:51
  • 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) – 323go Mar 14 '16 at 12:53
  • LogCat Error: 03-14 12:54:16.288: E/AndroidRuntime(1753): at m.k.Home$1.onTouch(Home.java:45) – gadolf Mar 14 '16 at 13:00
  • For what we can see in the post I have found one issue but still there might be others too and we would need **full** crash stacktrace. – Rohit5k2 Mar 14 '16 at 13:08
  • I need an answer for my coding. when I touching the imageView, I expect that show me list view in anatomy1.xml that defined in Anatomy1.class. after getting answer, I will delete this post. – gadolf Mar 14 '16 at 13:16
  • 1
    @gadolf: Why would you delete the post? You should never do that. – Rohit5k2 Mar 14 '16 at 13:31
  • I thought my question was more specific. My language is not very good and did not have the time to read other posts. Please return my scores :( – gadolf Mar 14 '16 at 13:37

1 Answers1

1

Although the error statement is posted is not complete hence useless for debugging, I can see that you are trying to open Anatomy1 but this is not defined in manifest file.

Add this in manifest

<activity
    android:name=".Anatomy1"
    android:label="@string/app_name" >
</activity>
Rohit5k2
  • 17,948
  • 8
  • 45
  • 57
  • thank you very ... , Instead Anatomy1, Activity1 I had written. – gadolf Mar 14 '16 at 13:30
  • Glad it works for you. As you said you will delete the post but you should not. People help you in problems not to find the post being deleted. – Rohit5k2 Mar 14 '16 at 13:33