I myself study some Android application development, and I follow the video tutorial on how to make a simple ToDo list application. However, I got into a compilation error and from what I have, everything seems to be in order. Below are both the main class and the layout:
Main.java: http://pastebin.com/vfuANx0p
package com.example.exampletodo; import android.R; import android.os.Bundle; import android.app.Activity; import android.view.KeyEvent; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.view.View.OnKeyListener; import android.widget.EditText; import android.widget.Button; import android.widget.ListView; import java.util.ArrayList; import android.widget.ArrayAdapter; public class Main extends Activity implements OnClickListener, OnKeyListener { EditText txtItem; Button btnAdd; ListView listItems; ArrayList<String> toDoItems; ArrayAdapter<String> aa; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); txtItem = (EditText)findViewById(R.id.txtItem); btnAdd = (Button)findViewById(R.id.btnAdd); listItems = (ListView)findViewById(R.id.listItems); btnAdd.setOnClickListener(this); txtItem.setOnKeyListener(this); toDoItems = new ArrayList<String>(); aa = new ArrayAdapter<String>(this, R.layout.simple_list_item_1, toDoItems); listItems.setAdapter(aa); } private void addItem(String item){ if(item.length() > 0){ this.toDoItems.add(item); this.aa.notifyDataSetChanged(); this.txtItem.setText(""); } } @Override public boolean onCreateOptionsMenu(Menu menu) {
main.xml: http://pastebin.com/WcWg692v
<RelativeLayout 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:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".Main"> <EditText android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/txtItem" android:layout_alignParentTop="true" android:layout_alignParentRight="true" android:layout_alignParentLeft="true" android:focusable="true"/> <Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/add" android:id="@+id/btnAdd" android:layout_below="@+id/txtItem" android:layout_alignRight="@+id/txtItem" android:layout_alignLeft="@+id/txtItem"/> <ListView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/listItems" android:layout_alignParentRight="true" android:layout_alignParentLeft="true" android:layout_alignParentBottom="true" android:layout_below="@+id/btnAdd"/> </RelativeLayout>
Error:
/home/rohan/ExampleToDo/ExampleToDo/src/main/java/com/example/exampletodo/Main.java Gradle: cannot find symbol variable main Gradle: cannot find symbol variable txtItem Gradle: cannot find symbol variable btnAdd Gradle: cannot find symbol variable listItems Gradle: cannot find symbol variable main
Thank you very much to everyone who is ready to help!
source share