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;
}
});