Click here to Skip to main content
15,902,860 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
The code of first activity is here:
Java
public class FirstActivity extends Activity {
	TextView welcomeText;
    Button goToWishListButton;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_first);

        welcomeText= (TextView) findViewById(R.id.welcomeText);
        goToWishListButton = (Button) findViewById(R.id.goToWishButton);

        goToWishListButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(FirstActivity.this, WishListActivity.class);
                startActivity(intent);

            }
        });

The target activity code:
Java
public class WishListActivity extends Activity {

    EditText inputText;
    Button addWishButton;
    ListView wishListView;
    ArrayList<item> arrayList;
    BaseAdapter adapter;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_wish_list);
        initializeAll();
        arrayList = new ArrayList<item>();
	}
    private  void initializeAll()
    {
        inputText = (EditText) findViewById(R.id.wishNameEdit);
        addWishButton = (Button) findViewById(R.id.saveWishButton);
        wishListView = (ListView) findViewById(R.id.listView);
        adapter = new BaseAdapter() {
            LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

            @Override
            public View getView(int position, View view, ViewGroup viewGroup) {
                if (view==null)
                {
                    view= inflater.inflate(R.layout.wish_list, null);
                }

                TextView wishTextView = (TextView) view.findViewById(R.id.wishTextView);
                TextView wishDateView = (TextView) view.findViewById(R.id.wishDateView);

                wishTextView.setText(arrayList.get(position).getWishString());
                Date date = arrayList.get(position).getDate();
                wishDateView.setText(DateFormat.format("dd/MM/yyyy HH/mm/ss a", date));

                return view;
            }


            @Override
            public long getItemId(int position) {
                return 0;
            }

            @Override
            public int getCount() {
                return arrayList.size();
            }

            @Override
            public Object getItem(int position) {
                return arrayList.get(position);
            }


        };

        wishListView.setAdapter(adapter);


AndroidManifest.xml file:

XML
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
    package="com.misbah.wishlistapp"
    android:versionCode="1"
    android:versionName="1.0" &gt;

    <uses-sdk>
        android:minSdkVersion="16"
        android:targetSdkVersion="19" /&gt;

    <application>
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" &gt;

        <activity>
            android:name=".FirstActivity"
            android:label="@string/app_name" &gt;

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" /&gt;
            </intent-filter>
        </activity>
    </application>
</uses-sdk></manifest></item></item>
Posted
Updated 8-Nov-15 5:15am
v5
Comments
Mohibur Rashid 8-Nov-15 11:16am    
make sure goToWishListButton is not null
Patrice T 8-Nov-15 11:35am    
CP is getting complicated in the XML code :(
Should have been 1 revision, not 5
Mohibur Rashid 9-Nov-15 2:51am    
lol
Richard MacCutchan 8-Nov-15 12:16pm    
Where does the error occur?
Arindam Tewary 9-Nov-15 6:39am    
Put a try-catch block first and identify where is the error. That would help you understand null exception.

1 solution

maybe show your xml layout file
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900