This is my MainActivity. public class MainActivity extends ActionBarActivity {

public Button ok;
public EditText name;
public ListView listView;
BaseAdapter baseAdapter;
ArrayList<item> arrayList;
View view;
DataBaseHelper dBaseHelper;
item item;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 0);
    setContentView(R.layout.activity_main);
    InitializedAll();

    ok.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            save(view);
            show(view);
        }
    });
}

private void InitializedAll() {
    dBaseHelper = new DataBaseHelper(this);
    item item = new item();
    name = (EditText) findViewById(R.id.nameeditText);
    ok = (Button) findViewById(R.id.okbutton);
    listView = (ListView) findViewById(R.id.listView);
    arrayList = new ArrayList<item>();
    baseAdapter = new BaseAdapter() {
        LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

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

            }

            TextView name = (TextView) view.findViewById(R.id.nametextView);
            TextView pass = (TextView) view
                    .findViewById(R.id.passwordtextView);
            name.setText(arrayList.get(position).getName());
            Date date = arrayList.get(position).getDate();
            pass.setText(DateFormat.format("dd/MM/yyyy HH:mm:ss a", date));
            return view;
        }

        @Override
        public long getItemId(int position) {
            // TODO Auto-generated method stub
            return 0;
        }

        @Override
        public Object getItem(int position) {
            // TODO Auto-generated method stub
            return arrayList.get(position);
        }

        @Override
        public int getCount() {
            // TODO Auto-generated method stub
            return arrayList.size();
        }
    };
    listView.setAdapter(baseAdapter);

}

public void save(View view) {

    String na = name.getText().toString();
    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss a");
    String dateString = sdf.format(item.getDate());

    item listItem = new item(na, dateString);
    arrayList.add(listItem);
    long inserted = dBaseHelper.insertItem(listItem);
    if (inserted >= 0) {
        Toast.makeText(getApplicationContext(), "Data Inserted",
                Toast.LENGTH_SHORT).show();
    } else {
        Toast.makeText(getApplicationContext(), "Data not Inserted",
                Toast.LENGTH_SHORT).show();
    }

    baseAdapter.notifyDataSetChanged();
}

public void show(View view) {
    ArrayList<item> items = dBaseHelper.getAllDate();
    if (items != null && items.size() > 0) {
        baseAdapter.notifyDataSetChanged();

    }
}

}

And This is my Log cat Error 09-28 15:28:46.667: E/AndroidRuntime(21150): FATAL EXCEPTION: main

09-28 15:28:46.667: E/AndroidRuntime(21150): java.lang.NullPointerException

09-28 15:28:46.667: E/AndroidRuntime(21150): at com.example.text.MainActivity.save(MainActivity.java:110)

09-28 15:28:46.667: E/AndroidRuntime(21150): at com.example.text.MainActivity$1.onClick(MainActivity.java:48)

09-28 15:28:46.667: E/AndroidRuntime(21150): at android.view.View.performClick(View.java:4102)

09-28 15:28:46.667: E/AndroidRuntime(21150): at android.view.View$PerformClick.run(View.java:17085)

09-28 15:28:46.667: E/AndroidRuntime(21150): at android.os.Handler.handleCallback(Handler.java:615)

09-28 15:28:46.667: E/AndroidRuntime(21150): at android.os.Handler.dispatchMessage(Handler.java:92)

09-28 15:28:46.667: E/AndroidRuntime(21150): at android.os.Looper.loop(Looper.java:155)

09-28 15:28:46.667: E/AndroidRuntime(21150): at android.app.ActivityThread.main(ActivityThread.java:5511)

09-28 15:28:46.667: E/AndroidRuntime(21150): at java.lang.reflect.Method.invokeNative(Native Method) 09-28 15:28:46.667: E/AndroidRuntime(21150): at java.lang.reflect.Method.invoke(Method.java:511)

09-28 15:28:46.667: E/AndroidRuntime(21150): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1029)

09-28 15:28:46.667: E/AndroidRuntime(21150): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:796)

09-28 15:28:46.667: E/AndroidRuntime(21150): at dalvik.system.NativeStart.main(Native Method)

I want to show my date in ListView and save this in my Sqlite database. But when i run this apps it's turn to stop. It say's null point exception. How to solve it.

Related posts

Recent Viewed