Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Android
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Android
nullpointer when i try to initiate onclicklistener
ian myers
Greenhorn
Posts: 7
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
here is the code
package com.format; import android.app.Activity; import android.os.Bundle; import android.widget.Button; import android.widget.EditText; import android.view.View; import android.view.View.OnClickListener; public class Add extends Activity implements OnClickListener { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main2); Button ba=(Button)findViewById(R.id.buttona); Button bb=(Button)findViewById(R.id.buttonb); ba.setOnClickListener(this); bb.setOnClickListener(this); } public void onClick(View v) { EditText eta=(EditText)findViewById(R.id.editTexta); EditText etb=(EditText)findViewById(R.id.editTextb); EditText etd=(EditText)findViewById(R.id.editTextd); String word=eta.getText().toString(); String scramble = etb.getText().toString(); WordData teaData = new WordData(this); String delete = etd.getText().toString(); // TODO Auto-generated method stub switch(v.getId()){ case R.id.buttona:teaData.insert(word,scramble); break; case R.id.buttonb:teaData.delete(delete);break;} }}
here is the xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical"> <LinearLayout android:orientation="horizontal" android:id="@+id/linearLayouta" android:layout_height="wrap_content" android:layout_width="fill_parent"> <EditText android:layout_height="wrap_content" android:layout_width="fill_parent" android:id="@+id/editTexta" android:text="Enter Word"></EditText> </LinearLayout> <LinearLayout android:id="@+id/linearLayoutb" android:layout_height="wrap_content" android:layout_width="fill_parent"> <EditText android:layout_height="wrap_content" android:layout_width="fill_parent" android:id="@+id/editTextb" android:text="Enter Scrambled Form"></EditText> </LinearLayout> <LinearLayout android:id="@+id/linearLayoutc" android:layout_height="wrap_content" android:layout_width="fill_parent"> <Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/buttona" android:text="Add"></Button> </LinearLayout> <LinearLayout android:id="@+id/linearLayoutd" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_gravity="bottom"> <EditText android:layout_height="wrap_content" android:layout_width="fill_parent" android:id="@+id/editTextc" android:text="@string/app_name"></EditText> </LinearLayout> <LinearLayout android:id="@+id/linearLayoute" android:layout_height="wrap_content" android:layout_width="fill_parent"> <EditText android:layout_height="wrap_content" android:id="@+id/editTextd" android:text="Enter Word To Be Deleted" android:layout_width="fill_parent"></EditText> </LinearLayout> <LinearLayout android:id="@+id/linearLayoutf" android:layout_height="wrap_content" android:layout_width="fill_parent"> <Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/buttonb" android:text="Delete"></Button> </LinearLayout> </LinearLayout>
the problem is line 18 but I dont know why im getting null pointer exceptions
Pramod P Deore
Ranch Hand
Posts: 633
I like...
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
show the logcat errors.
Life is easy because we write the source code.....
zoheb hassan
Ranch Hand
Posts: 154
I like...
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
There is absolutely no problem with the button clicks here or the code, the problem might be with your WordData class
ian myers
Greenhorn
Posts: 7
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
found the problem. there was something wrong with the emulator, I made a new one and it works, but whenever it runs on the old one it just force closes
weird
zoheb hassan
Ranch Hand
Posts: 154
I like...
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Yeah there are instances of even weirder behaviour
Don't get me started about those stupid
light bulbs
.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
How to retrieve string from EditText?
regarding layout
Keyboard events for EditText not reaching my event handler.
how to get a longitude & latitude from a given address
Layouts, bottom position
More...