nullpointerexception

What is a NullPointerException, and how do I fix it?

主宰稳场 提交于 2020-01-26 04:03:07
问题 This question's answers are a community effort . Edit existing answers to improve this post. It is not currently accepting new answers or interactions. What are Null Pointer Exceptions ( java.lang.NullPointerException ) and what causes them? What methods/tools can be used to determine the cause so that you stop the exception from causing the program to terminate prematurely? 回答1: When you declare a reference variable (i.e. an object) you are really creating a pointer to an object. Consider

Listvew with textview and checkbox

浪尽此生 提交于 2020-01-26 03:51:52
问题 I want to have a listview with textview + check box. I was able to create the listview. I can capture listview item select. However when I try to capture check box select, unselect I get a null pointer exception. How to write the setOnCheckedChangeListener() for the check box.. public class LocationActivity extends Activity{ @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.locationmain

What is causing the Exception in thread “pool-1-thread-2” (NullPointerException) [duplicate]

◇◆丶佛笑我妖孽 提交于 2020-01-25 22:18:09
问题 This question already has answers here : What is a NullPointerException, and how do I fix it? (12 answers) Closed 2 years ago . I am creating a multi-threaded web server. When I run the client I receive a NullPointException. Why is this happening and what can be done to solve it? Concerning the suggestions that I should read the mentioned tutorial. I have tried to solve the problem with the help of it. I created a constructor, but then I didn't know how to call the class: theExecutor.execute

How do I use setText from within a callback?

你离开我真会死。 提交于 2020-01-25 20:19:28
问题 In my code below I am able to edit a text from my first setText() call but not from within the callback. The error I receive is a NullPointerException for title in the callback. How do I set this up so I can edit the text from within the callback? public class ListingActivity extends AppCompatActivity { final String TAG = "ListingActivity"; TextView title; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); title = (TextView)findViewById(R.id

Context being passed into method for getAssets() is null

你离开我真会死。 提交于 2020-01-25 11:34:10
问题 In the code below, the getPieceTextFile() method takes an Activity context parameter, however when used, the context passed in appears to be null and leads to a NPE. Any suggestions why would be greatly appreciated. The LogCat output and code listing are shown below. LogCat 01-03 13:48:47.223: I/dalvikvm(571): threadid=3: reacting to signal 3 01-03 13:48:47.233: I/dalvikvm(571): Wrote stack traces to '/data/anr/traces.txt' 01-03 13:49:30.073: I/System.out(571): Asset Manager/IS not work. 01

java.lang.NullPointerException on super.paintComponent(g);

你离开我真会死。 提交于 2020-01-25 10:52:05
问题 I'm getting a java.lang.NullPointerException on my super.paintComponent(e) line, I have looked at a few tutorials but I'm unsure of what I'm doing wrong. Heres my Main class: package pack; public class Main { public static void main(String[] args){ @SuppressWarnings("unused") Display display = new Display("The JFrame", 510, 510); Game game = new Game(); game.start(); } } Display class: package pack; import java.awt.Dimension; import javax.swing.JFrame; import javax.swing.JPanel; public class

Android: Nullpointer Exception Error in Activity

你。 提交于 2020-01-25 09:45:10
问题 I have this getView method inside my ListViewAdapter: public static class ViewHolder{ public TextView textTitle; public ImageView image; } public View getView(int position, View convertView, ViewGroup parent) { Project pro = getItem(position); View vi=convertView; ViewHolder holder; if(convertView==null){ vi = inflater.inflate(R.layout.listitems, null); holder=new ViewHolder(); holder.textTitle=(TextView)vi.findViewById(R.id.txt_title);; holder.image=(ImageView)vi.findViewById(R.id.image); vi

NullPointerException When Trying to place Marker on Google Map V2

落花浮王杯 提交于 2020-01-24 19:32:06
问题 when I try to place Marker on google map with placeMarker method I get NullPointerException NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources android.content.Context.getResources()' on a null object reference` I/DpmTcmClient: RegisterTcmMonitor from: org.apache.http.impl.conn.TcmIdleTimerMonitor W/DynamiteModule: Local module descriptor class for com.google.android.gms.googlecertificates not found. I/DynamiteModule: Considering local module com.google

How do I retrieve shared preferences data in a Widget Service class without passing in incorrect default values or getting null pointer errors?

我只是一个虾纸丫 提交于 2020-01-24 17:05:25
问题 I am trying to run a widget in my app. The widget data (sync frequency, username, etc) is decided in the WidgetConfig class. It then opens a widget provider, which creates the widget, and lastly a service updates the views and makes the server calls to update data. Here is some of my code: //First Widget config is called: public class WidgetConfig extends Activity{ //Stuff happens here to get data from EditTexts and spinners and converts //them to strings. //Eventually a button is pressed

How do I retrieve shared preferences data in a Widget Service class without passing in incorrect default values or getting null pointer errors?

心不动则不痛 提交于 2020-01-24 17:05:14
问题 I am trying to run a widget in my app. The widget data (sync frequency, username, etc) is decided in the WidgetConfig class. It then opens a widget provider, which creates the widget, and lastly a service updates the views and makes the server calls to update data. Here is some of my code: //First Widget config is called: public class WidgetConfig extends Activity{ //Stuff happens here to get data from EditTexts and spinners and converts //them to strings. //Eventually a button is pressed