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
Tim Cooke
Liutauras Vilda
Jeanne Boyarsky
paul wheaton
Sheriffs:
Ron McLeod
Devaka Cooray
Henry Wong
Saloon Keepers:
Tim Holloway
Stephan van Hulst
Carey Brown
Tim Moores
Mikalai Zaikin
Bartenders:
Frits Walraven
Forum:
Android
getting null pointer
shawn peter
Ranch Hand
Posts: 1325
1
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
this is my main class
package com.android; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class Welcome extends Activity implements OnClickListener{ /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.welcome); Button online=(Button)findViewById(R.id.online); Button offline=(Button)findViewById(R.id.offline); Button about_us=(Button)findViewById(R.id.aboutus); online.setOnClickListener(this); offline.setOnClickListener(this); about_us.setOnClickListener(this); } @Override public void onClick(View v) { if(v.getId()==R.id.online){ Intent myIntent =new Intent(this, Online.class); startActivity(myIntent); } if(v.getId()==R.id.offline){ Intent myIntent =new Intent(this, Offline.class); startActivity(myIntent); } if(v.getId()==R.id.aboutus){ //Intent myIntent =new Intent(this, .class); } } }
this is online class
package com.android; import android.app.Activity; import android.app.ListActivity; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.BaseAdapter; import android.widget.Button; import android.widget.ImageView; import android.widget.ListView; import android.widget.TextView; import android.widget.AdapterView.OnItemClickListener; import android.widget.Toast; public class Online extends Activity implements OnClickListener{ private CustomRowAdapter customRowAdapter; //private ListView lv1; private ListView listView; //public String lv_class_names[]= {View.class.getName()}; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.common); String[] upcomingEventData = new String[]{"Init Libraries Upcoming", "Init Components Upcoming", "Init Application Upcoming", "Channel Opened Upcoming", "Data Arrived Upcoming"}; customRowAdapter = new CustomRowAdapter(upcomingEventData); listView = (ListView) findViewById(R.id.listView1); listView.setAdapter(customRowAdapter); listView.setTextFilterEnabled(true); listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View view, int position, long arg3) { // TODO Auto-generated method stub Toast.makeText(getApplicationContext(), "AAAAAAAAAAAAAAAAAAAAA "+position, Toast.LENGTH_LONG).show(); Bundle bundle = new Bundle(); bundle.putString("itemname", listView.getItemAtPosition(position).toString()); Intent intent = new Intent(view.getContext(), View.class); intent.putExtras(bundle); view.getContext().startActivity(intent); // //USED TO SHOW POPUP MESSAGE // AlertDialog.Builder adb=new AlertDialog.Builder(ListviewOnclickExample.this); // adb.setTitle("LVSelectedItemExample"); // adb.setMessage("Selected Item is = "+lv1.getItemAtPosition(position)); // adb.setPositiveButton("Ok", null); // adb.show(); } }); Button back=(Button)findViewById(R.id.Back); back.setOnClickListener(this); } private class CustomRowAdapter extends BaseAdapter { private String[] data; private int[] images; public CustomRowAdapter(String[] data) { this.data = data; //this.images = images; } @Override public int getCount() { // TODO Auto-generated method stub return data.length; } @Override public Object getItem(int position) { // TODO Auto-generated method stub return null; } @Override public long getItemId(int position) { // TODO Auto-generated method stub return 0; } @Override public View getView(int position, View convertView, ViewGroup parent) { // TODO Auto-generated method stub //This is the Generic view of the row, //so if we need to do some changes , we need to do them to this view. //First check whether we need to create view/initialize if(convertView == null) { //View is null, which means this is the first time ListView //getting the data LayoutInflater vi =(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE); convertView = vi.inflate(R.layout.list_row, null); } TextView txtView = (TextView)convertView.findViewById(R.id.textView1); txtView.setText(data[position]); //ImageView imgView = (ImageView)convertView.findViewById(R.id.imgPicture); //imgView.setImageResource(images[position]); return convertView; } } @Override public void onClick(View v) { if(v.getId()==R.id.Back){ Intent myIntent =new Intent(this, Welcome.class); startActivity(myIntent); } }}
when i click the links it gives this error
09-03 16:00:46.875: ERROR/AndroidRuntime(577): FATAL EXCEPTION: main 09-03 16:00:46.875: ERROR/AndroidRuntime(577): java.lang.NullPointerException 09-03 16:00:46.875: ERROR/AndroidRuntime(577): at com.android.Online$1.onItemClick(Online.java:52) 09-03 16:00:46.875: ERROR/AndroidRuntime(577): at android.widget.AdapterView.performItemClick(AdapterView.java:284) 09-03 16:00:46.875: ERROR/AndroidRuntime(577): at android.widget.ListView.performItemClick(ListView.java:3382) 09-03 16:00:46.875: ERROR/AndroidRuntime(577): at android.widget.AbsListView$PerformClick.run(AbsListView.java:1696) 09-03 16:00:46.875: ERROR/AndroidRuntime(577): at android.os.Handler.handleCallback(Handler.java:587) 09-03 16:00:46.875: ERROR/AndroidRuntime(577): at android.os.Handler.dispatchMessage(Handler.java:92) 09-03 16:00:46.875: ERROR/AndroidRuntime(577): at android.os.Looper.loop(Looper.java:123) 09-03 16:00:46.875: ERROR/AndroidRuntime(577): at android.app.ActivityThread.main(ActivityThread.java:4627) 09-03 16:00:46.875: ERROR/AndroidRuntime(577): at java.lang.reflect.Method.invokeNative(Native Method) 09-03 16:00:46.875: ERROR/AndroidRuntime(577): at java.lang.reflect.Method.invoke(Method.java:521) 09-03 16:00:46.875: ERROR/AndroidRuntime(577): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 09-03 16:00:46.875: ERROR/AndroidRuntime(577): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 09-03 16:00:46.875: ERROR/AndroidRuntime(577): at dalvik.system.NativeStart.main(Native Method)
but whe i print position it gives values.
so how it gives null pointer?
Ulf Dittmer
Rancher
Posts: 43081
77
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Which object is null?
shawn peter
Ranch Hand
Posts: 1325
1
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I also need to know ?
Ulf Dittmer
Rancher
Posts: 43081
77
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
We are not in a position to figure that out - you are. For example, you can print relevant values to the Log.
Also, in which line does the exception occur, meaning, which one is line 52 - the one labelled 52 in your post?
shawn peter
Ranch Hand
Posts: 1325
1
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
It gives null pointer in this line
Toast.makeText(getApplicationContext(), "AAAAAAAAAAAAAAAAAAAAA "+position, Toast.LENGTH_LONG).show();
but the position value is not null.
Ulf Dittmer
Rancher
Posts: 43081
77
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
What does getApplicationContext() return?
What does Toast.makeText(...) return?
The longest recorded flight time of a chicken is 13 seconds. But that was done without this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
external allocation too large for this process,Error inflating class, bitmap size exceeds VM budget
is there any way to trigger onLocationChanged other than moving
unable to create the service ,it gives null pointer exception
how to add a google search option
Android CustomListView getView() getting nullpointerexception
More...