I am trying to write an application that starts off from a main menu (a gridview) and then creates a new activity based on the icon that is clicked by the user. Right now I am trying to simply display a blank screen for one of the icons to make sure I can successfully create a new activity. My main activity is called HomeScreen and the new activity which should be launched when I click on the first icon is called CulpaActivity. I am posting HomeScreen, CulpaActivity, and the Manifest.
public class HomeScreen extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
GridView gridview = (GridView) findViewById(R.id.gridview);
gridview.setAdapter(new ImageAdapter(this));
Drawable background = this.getResources().getDrawable(R.drawable.bg);
gridview.setBackgroundDrawable(background);
gridview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
Toast.makeText(HomeScreen.this, "" + position, Toast.LENGTH_SHORT).show();
Intent cuAppIntent = null;
switch (position){
case 0:
cuAppIntent.setClass(HomeScreen.this, CulpaActivity.class);
}
}
});
}
}
public class CulpaActivity extends Activity{
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
GridView gridview = (GridView) findViewById(R.id.gridview);
gridview.setAdapter(new ImageAdapter(this));
gridview.setBackgroundDrawable(null);
}
}
And here is the Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="columbia.android"
android:versionCode="1"
android:versionName="1.0" >
<supports-screens
android:anyDensity="true"
android:largeScreens="true"
android:normalScreens="true"
android:resizeable="true"
android:smallScreens="true" />
<application
android:debuggable="true"
android:icon="@drawable/icon"
android:label="@string/app_name" >
<activity
android:label="@string/app_name"
android:name=".HomeScreen" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".CulpaActivity" >
</activity>
</application>
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
I think this is your problem:
You define
cuAppIntentasnullyet you directly accesscuAppIntent.setClass()without initializingcuAppIntentfirst.To fix it, try to initialize first:
and then add:
right after calling
cuAppIntent.setClass()