when I run the programme I get a runtime error. Unable to instantiate activity component info.
Here is the code I use, I tried to write a listner for spinner.
public void addListenerlist() {
spinner1.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
String s = arg0.getItemAtPosition(arg2).toString();
if (s.equals("Malaysia")) {
message = getResources().getString(R.string.listdesc1);
} else if (s.equals("United States")) {
message = getResources().getString(R.string.listdesc1);
} else if (s.equals("Sri Lanka")) {
message = getResources().getString(R.string.listdesc2);
} else if (s.equals("Indonesia")) {
message = getResources().getString(R.string.listdesc3);
} else if (s.equals("France")) {
message = getResources().getString(R.string.listdesc4);
} else if (s.equals("Italy")) {
message = getResources().getString(R.string.listdesc5);
} else if (s.equals("Singapore")) {
message = getResources().getString(R.string.listdesc6);
} else if (s.equals("New Zealand")) {
message = getResources().getString(R.string.listdesc7);
} else if (s.equals("India")) {
message = getResources().getString(R.string.listdesc8);
} else {
message = getResources().getString(R.string.listdesc9);
}
String listtitle1 = getResources().getString(
R.string.listtitle1);
// String message =
// getResources().getString(R.string.listdesc1);
// txtview.setText(message);
// txtview2.setText(listtitle1);
Toast.makeText(Page5SubActivity.this,
"OnClickListener : " + message , Toast.LENGTH_SHORT)
.show();
}
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
}
I am new to java, another problem is that , can't I use message as local variable instead of a class variable. I have use message varable as a Class variable since using it as a local variable shows errors.
10-31 05:18:04.605: E/AndroidRuntime(854): FATAL EXCEPTION: main
10-31 05:18:04.605: E/AndroidRuntime(854): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.xxx.xx/com.xxx.xx.Page5SubActivity}: java.lang.NullPointerException
10-31 05:18:04.605: E/AndroidRuntime(854): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1569)
10-31 05:18:04.605: E/AndroidRuntime(854): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
10-31 05:18:04.605: E/AndroidRuntime(854): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
10-31 05:18:04.605: E/AndroidRuntime(854): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
10-31 05:18:04.605: E/AndroidRuntime(854): at android.os.Handler.dispatchMessage(Handler.java:99)
10-31 05:18:04.605: E/AndroidRuntime(854): at android.os.Looper.loop(Looper.java:123)
10-31 05:18:04.605: E/AndroidRuntime(854): at android.app.ActivityThread.main(ActivityThread.java:3683)
10-31 05:18:04.605: E/AndroidRuntime(854): at java.lang.reflect.Method.invokeNative(Native Method)
10-31 05:18:04.605: E/AndroidRuntime(854): at java.lang.reflect.Method.invoke(Method.java:507)
10-31 05:18:04.605: E/AndroidRuntime(854): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
10-31 05:18:04.605: E/AndroidRuntime(854): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
10-31 05:18:04.605: E/AndroidRuntime(854): at dalvik.system.NativeStart.main(Native Method)
10-31 05:18:04.605: E/AndroidRuntime(854): Caused by: java.lang.NullPointerException
10-31 05:18:04.605: E/AndroidRuntime(854): at android.app.Activity.findViewById(Activity.java:1647)
10-31 05:18:04.605: E/AndroidRuntime(854): at com.meegua.zakat.Page5SubActivity.<init>(Page5SubActivity.java:17)
10-31 05:18:04.605: E/AndroidRuntime(854): at java.lang.Class.newInstanceImpl(Native Method)
10-31 05:18:04.605: E/AndroidRuntime(854): at java.lang.Class.newInstance(Class.java:1409)
10-31 05:18:04.605: E/AndroidRuntime(854): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
10-31 05:18:04.605: E/AndroidRuntime(854): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561)
10-31 05:18:04.605: E/AndroidRuntime(854): ... 11 more
I could find the proble after spending several hours on this.
I hadnt declared class variables properly. it was the reason to error "unable to instantiate activity component info"
private Spinner spinner1;
private TextView txtv ;
I had n't declared private keyword.
think this will be helpful to someone.
Related
Other stuck posts unfortunately couldn't help me.
When I clicked button while easy radiobutton is checked, the app stops working. I couldn't go and see another activity.
Sender Side:
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
if(radiobutton_arm_triceps_easy.isChecked()) {
String dene = "my example test";
int myValue=2;
Intent intent = new Intent(getApplicationContext(), exercise_arm_triceps_execute.class);
intent.putExtra("attempt1", myValue );
startActivity(intent);
}
}
});
Receiver Side:
int receiveValue=getIntent().getIntExtra("attempt1",0);
textshow.setText(receiveValue);
LOGCAT
04-26 16:52:06.320 31527-31527/com.example.kerem.tutorial_project E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.kerem.tutorial_project, PID: 31527
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.kerem.tutorial_project/com.example.kerem.tutorial_project.exercise_arm_triceps_execute}: android.content.res.Resources$NotFoundException: String resource ID #0x2
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x2
at android.content.res.Resources.getText(Resources.java:244)
at android.support.v7.widget.ResourcesWrapper.getText(ResourcesWrapper.java:52)
at android.widget.TextView.setText(TextView.java:3888)
at com.example.kerem.tutorial_project.exercise_arm_triceps_execute.onCreate(exercise_arm_triceps_execute.java:28)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Use
textshow.setText(String.valueOf(receiveValue));
i am trying to get a button from another layout in fragment.this fragment have another inflate another layout.i get a java.lang.NullPointerException. how to solve this problem?
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.add_to_cart_display, container, false);
myAdapter=new MyAdapter(getActivity());
Button remove=(Button) view.findViewById(R.id.remove_cart_items);
RecyclerView recyclerView=(RecyclerView)view.findViewById(R.id.recyclerView);
recyclerView.setHasFixedSize(true);
ch=new CartHelper(getActivity());
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
rc=new RCadapter(getDataset());
recyclerView.setAdapter(rc);
return view;
}
from above pgm the remove button not in the add_cart_display xml file. it locate in another layout file. here i am accessing this button.it give the following error.
10-31 12:38:20.484 13886-13886/com.infizoom.infishopping
E/AndroidRuntime: FATAL EXCEPTION: main 10-31 12:38:20.484
13886-13886/com.infizoom.infishopping E/AndroidRuntime: Process:
com.infizoom.infishopping, PID: 13886 10-31 12:38:20.484
13886-13886/com.infizoom.infishopping E/AndroidRuntime:
java.lang.NullPointerException 10-31 12:38:20.484
13886-13886/com.infizoom.infishopping E/AndroidRuntime: at
com.infizoom.infishopping.add_cart_class.onStart(add_cart_class.java:75)
10-31 12:38:20.484 13886-13886/com.infizoom.infishopping
E/AndroidRuntime: at
android.app.Fragment.performStart(Fragment.java:1724) 10-31
12:38:20.484 13886-13886/com.infizoom.infishopping E/AndroidRuntime:
at
android.app.FragmentManagerImpl.moveToState(FragmentManager.java:918)
10-31 12:38:20.484 13886-13886/com.infizoom.infishopping
E/AndroidRuntime: at
android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1062)
10-31 12:38:20.484 13886-13886/com.infizoom.infishopping
E/AndroidRuntime: at
android.app.BackStackRecord.run(BackStackRecord.java:698) 10-31
12:38:20.484 13886-13886/com.infizoom.infishopping E/AndroidRuntime:
at
android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1447)
10-31 12:38:20.484 13886-13886/com.infizoom.infishopping
E/AndroidRuntime: at
android.app.FragmentManagerImpl$1.run(FragmentManager.java:443) 10-31
12:38:20.484 13886-13886/com.infizoom.infishopping E/AndroidRuntime:
at android.os.Handler.handleCallback(Handler.java:808) 10-31
12:38:20.484 13886-13886/com.infizoom.infishopping E/AndroidRuntime:
at android.os.Handler.dispatchMessage(Handler.java:103) 10-31
12:38:20.484 13886-13886/com.infizoom.infishopping E/AndroidRuntime:
at android.os.Looper.loop(Looper.java:193) 10-31 12:38:20.484
13886-13886/com.infizoom.infishopping E/AndroidRuntime: at
android.app.ActivityThread.main(ActivityThread.java:5341) 10-31
12:38:20.484 13886-13886/com.infizoom.infishopping E/AndroidRuntime:
at java.lang.reflect.Method.invokeNative(Native Method) 10-31
12:38:20.484 13886-13886/com.infizoom.infishopping E/AndroidRuntime:
at java.lang.reflect.Method.invoke(Method.java:515) 10-31 12:38:20.484
13886-13886/com.infizoom.infishopping E/AndroidRuntime: at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:825)
10-31 12:38:20.484 13886-13886/com.infizoom.infishopping
E/AndroidRuntime: at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:641) 10-31
12:38:20.484 13886-13886/com.infizoom.infishopping E/AndroidRuntime:
at dalvik.system.NativeStart.main(Native Method)
add_to_cart_display.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_marginTop="#dimen/abc_action_bar_default_height_material"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/recyclerView"
android:layout_width="fill_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
/>
Remove Button inside the CardView
final View view = inflater.inflate(R.layout.add_to_cart_display, container, false);
Button remove=(Button) view.findViewById(R.id.remove_cart_items);
you are looking for a Button with id remove_cart_items inside add_to_cart_display. But in layout may be there is no Button with id remove_cart_items. That`s way you get null
I got an answer. i can access the button inside the cardview by recyclerAdapter onBindViewHolder(). but i dnot know how to call toast in side this function.
public static class ViewHolder extends RecyclerView.ViewHolder{
public TextView product_name_at_cart;
public Button remove;
public ViewHolder(View layoutview) {
super(layoutview);
remove =(Button) layoutview.findViewById(R.id.remove_cart_items);
product_name_at_cart=(TextView)layoutview.findViewById(R.id.add_cart_item_name);
}
}
OnBindViewHolder
public void onBindViewHolder(ViewHolder viewholder, int position) {
viewholder.product_name_at_cart.setText(mDataset.get(position).getProduct_name());
viewholder.remove.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Log.w("gopal", "Gopal btn click");
Cursor m=ch.getcurrent_id();
if(m.moveToFirst()){
do{
int id=m.getInt(5);
Toast.makeText(???????, "Gopal id " + id, Toast.LENGTH_SHORT).show();
}while (m.moveToNext());
}
}
});
}
What function will came in the Toast Msg.????
In RecyclerAdapter, I have defined a private Activity context.
Then, you can call the Toast.makeText(context, "your message", ...),
I'm trying to connect my app with a database (mySql) and i'm using an AsyncTask function.
This is a sort of introduction, the real problem comes out in the MainActivity. The app starts normally, but if i use the button to upload a single string on the db, it crashes. Here is the LogCat
06-09 16:33:12.625: E/AndroidRuntime(2048): FATAL EXCEPTION: main
06-09 16:33:12.625: E/AndroidRuntime(2048): Process: kh.edit_skill, PID: 2048
06-09 16:33:12.625: E/AndroidRuntime(2048): java.lang.NullPointerException
06-09 16:33:12.625: E/AndroidRuntime(2048): at kh.edit_skill.MainActivity.isEmptyS(MainActivity.java:137)
06-09 16:33:12.625: E/AndroidRuntime(2048): at kh.edit_skill.MainActivity.onClick(MainActivity.java:216)
06-09 16:33:12.625: E/AndroidRuntime(2048): at android.view.View.performClick(View.java:4438)
06-09 16:33:12.625: E/AndroidRuntime(2048): at android.view.View$PerformClick.run(View.java:18422)
06-09 16:33:12.625: E/AndroidRuntime(2048): at android.os.Handler.handleCallback(Handler.java:733)
06-09 16:33:12.625: E/AndroidRuntime(2048): at android.os.Handler.dispatchMessage(Handler.java:95)
06-09 16:33:12.625: E/AndroidRuntime(2048): at android.os.Looper.loop(Looper.java:136)
06-09 16:33:12.625: E/AndroidRuntime(2048): at android.app.ActivityThread.main(ActivityThread.java:5017)
06-09 16:33:12.625: E/AndroidRuntime(2048): at java.lang.reflect.Method.invokeNative(Native Method)
06-09 16:33:12.625: E/AndroidRuntime(2048): at java.lang.reflect.Method.invoke(Method.java:515)
06-09 16:33:12.625: E/AndroidRuntime(2048): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
06-09 16:33:12.625: E/AndroidRuntime(2048): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
06-09 16:33:12.625: E/AndroidRuntime(2048): at dalvik.system.NativeStart.main(Native Method)
These are the 2 functions mentioned in the LogCat;
1) isEmptyS at line 137
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
private boolean isEmptyS (EditText myText)
{
if(myText.getText().toString().trim().length() > 0) <----line 137
return false;
else
return true;
}
......code......
}
2) and his implementation in the onClick block
#Override
public void onClick(View v){
if(!isEmptyS(RequisitesTxt)){ <-----line 216
String MultilineRequisites = RequisitesTxt.getText().toString();
String Delimiter = ",";
mySkillRequisites = MultilineRequisites.split(Delimiter);
try{
EditSkillRequisites(myID_Skill, myID_Community, mySkillRequisites);}
catch(Validation_Error e){
e.showError();}
}
.......code........
}
P.S. i've used the same function in another app, and it works properly without errors. I checked the code so many times, I really don't know where is the problem and the difference with the working one.
Ty
I am trying to accept a phrase and pass it to other class called Animation.And I am using a self defined class called Error to store if error happens and what word causes the error.But when the button representing the class is clicked it displays "unfortunately the application has stopped".Check out partial code of the class below. Thank you for your help in advance.
public class Convert extends Activity implements OnClickListener {
EditText inputConvert;
TextView correct;
String correction;
String[] message = getResources().getStringArray(R.array.basic_words);
final Context context = this;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.convert);
View convert = findViewById(R.id.conv_button);
convert.setOnClickListener(this);
}
public void onClick(View v)
{
inputConvert=(EditText) findViewById(R.id.inputConvert);
String phrase = inputConvert.getText().toString();
if(v.getId()==R.id.conv_button)
{
Error obj1= new Error(false ,"initial");
obj1=check(phrase);
if(obj1.flag)
startAnim(phrase);
else
{
correction = build(obj1.word);
final Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.error);
Button dialogButton = (Button)dialog.findViewById(R.id.dialogButtonOK);
correct= (TextView) findViewById(R.id.error_content);
correct.setText(correction);
dialog.setTitle(R.string.help);
dialogButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
}
}
}
public String build(String word)
{
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("the word \"");
stringBuilder.append(word);
stringBuilder.append(" \" is not found please try to use a synomym");
String finalString = stringBuilder.toString();
return finalString;
}
public Error check(String word)
{
Error obj2 = new Error(false ,"initial");
obj2.word=word;
String[] words = word.split(" ");
for(int i=0; i< words.length; i++)
{
for(int j=0; i< message.length; j++)
{
if(words[i]==message[j])
obj2.flag=true;
break;
}
if(!obj2.flag)
obj2.word=words[i];
break;
}
return obj2;
}
public void startAnim(String phrase)
{
Intent j = new Intent(this, Animation.class);
j.putExtra("phrase",phrase);
startActivity(j);
}
Here is the code of the Animation activity.
public class Animation extends Activity
{
AnimationDrawable animation;
TextView errorMessage= (TextView)findViewById(R.id.testex);
#SuppressWarnings("deprecation")
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.animation);
Intent j= getIntent();
CharSequence message = j.getStringExtra("phrase");
String phrase=message.toString();
String[] words = phrase.split(" ");
animation = new AnimationDrawable();
int imid=0;
for(int i=0; i< words.length; i++)
{
imid=getResources().getIdentifier(words[i], "drawable", getPackageName());
animation.addFrame(getResources().getDrawable(imid), 700);
}
animation.setOneShot(false);
ImageView img = (ImageView)findViewById(R.id.spinning_wheel_image);
img.setBackgroundDrawable(animation);
animation = (AnimationDrawable) img.getBackground();
// Start the animation (looped playback by default).
animation.start();
}
}
Logcat.
12-12 08:32:04.962: E/AndroidRuntime(2273): FATAL EXCEPTION: main
12-12 08:32:04.962: E/AndroidRuntime(2273): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{org.example.ihear/org.example.ihear.Convert}: java.lang.NullPointerException
12-12 08:32:04.962: E/AndroidRuntime(2273): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2137)
12-12 08:32:04.962: E/AndroidRuntime(2273): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
12-12 08:32:04.962: E/AndroidRuntime(2273): at android.app.ActivityThread.access$600(ActivityThread.java:141)
12-12 08:32:04.962: E/AndroidRuntime(2273): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
12-12 08:32:04.962: E/AndroidRuntime(2273): at android.os.Handler.dispatchMessage(Handler.java:99)
12-12 08:32:04.962: E/AndroidRuntime(2273): at android.os.Looper.loop(Looper.java:137)
12-12 08:32:04.962: E/AndroidRuntime(2273): at android.app.ActivityThread.main(ActivityThread.java:5103)
12-12 08:32:04.962: E/AndroidRuntime(2273): at java.lang.reflect.Method.invokeNative(Native Method)
12-12 08:32:04.962: E/AndroidRuntime(2273): at java.lang.reflect.Method.invoke(Method.java:525)
12-12 08:32:04.962: E/AndroidRuntime(2273): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
12-12 08:32:04.962: E/AndroidRuntime(2273): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
12-12 08:32:04.962: E/AndroidRuntime(2273): at dalvik.system.NativeStart.main(Native Method)
12-12 08:32:04.962: E/AndroidRuntime(2273): Caused by: java.lang.NullPointerException
12-12 08:32:04.962: E/AndroidRuntime(2273): at android.content.ContextWrapper.getResources(ContextWrapper.java:89)
12-12 08:32:04.962: E/AndroidRuntime(2273): at android.view.ContextThemeWrapper.getResources(ContextThemeWrapper.java:78)
12-12 08:32:04.962: E/AndroidRuntime(2273): at org.example.ihear.Convert.(Convert.java:19)
12-12 08:32:04.962: E/AndroidRuntime(2273): at java.lang.Class.newInstanceImpl(Native Method)
12-12 08:32:04.962: E/AndroidRuntime(2273): at java.lang.Class.newInstance(Class.java:1130)
12-12 08:32:04.962: E/AndroidRuntime(2273): at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
12-12 08:32:04.962: E/AndroidRuntime(2273): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2128)
12-12 08:32:04.962: E/AndroidRuntime(2273): ... 11 more
Caused by: java.lang.NullPointerException
at org.example.ihear.Convert.(Convert.java:19)
here is your real error.please check it.
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo:{....}
means that Android OS could not create your activity.
The most probable error is that you forgot to add it to your AndroidManifest. I suspect that it is related to the Animation activity.
Try to declare
<activity android:name="**YOUR.PACKAGE**.Animation" />
See : java.lang.RuntimeException: Unable to instantiate activity ComponentInfo
If the declaration of the activity in the manifest was not the problem, try to inspect the constructor / onCreate methods of your Animation activity.
R.layout.convert is this layout right?
You can check it and make sure you have not used any element can not be found
Hi i am getting a nullpointer at line 493, marked in below code.
Can somebody assist in solving this? I almost know 100% it is the checkbox (nieuwbel).
But i can't get rid of the Exception.
Thank you in advance.
#Override
protected void onPause() {
MyBeltegoed dialog = new MyBeltegoed (this, new OnReadyListenerBeltegoed());
nieuwbel = (CheckBox)dialog.findViewById(R.id.nieuwbel);
Editor e = mPrefs.edit();
e.putBoolean(PREF_BOOL, nieuwbel.isChecked()); <----- Nullpointer
e.commit();
Toast.makeText(this, "Settings Saved.", Toast.LENGTH_SHORT).show();
super.onPause();
}
You need to check that nieuwbel is not null after attempting to get it. findViewById() might not find what you are looking for:
Returns The view that has the given id in the hierarchy or null
Try this:
#Override
protected void onPause() {
MyBeltegoed dialog = new MyBeltegoed (this, new OnReadyListenerBeltegoed());
nieuwbel = (CheckBox)dialog.findViewById(R.id.nieuwbel);
if (nieuwbel != null) {
Editor e = mPrefs.edit();
e.putBoolean(PREF_BOOL, nieuwbel.isChecked());
e.commit();
Toast.makeText(this, "Settings Saved.", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this, "Failed to save settings!", Toast.LENGTH_SHORT).show();
}
super.onPause();
}
Logcat forceclose:
10-31 22:57:36.618: E/AndroidRuntime(1423): FATAL EXCEPTION: main
10-31 22:57:36.618: E/AndroidRuntime(1423): android.app.SuperNotCalledException: Activity {com.sencide/com.sencide.AndroidLogin} did not call through to super.onPause()
10-31 22:57:36.618: E/AndroidRuntime(1423): at android.app.Activity.performPause(Activity.java:3854)
10-31 22:57:36.618: E/AndroidRuntime(1423): at android.app.Instrumentation.callActivityOnPause(Instrumentation.java:1191)
10-31 22:57:36.618: E/AndroidRuntime(1423): at android.app.ActivityThread.performPauseActivity(ActivityThread.java:2341)
10-31 22:57:36.618: E/AndroidRuntime(1423): at android.app.ActivityThread.performPauseActivity(ActivityThread.java:2311)
10-31 22:57:36.618: E/AndroidRuntime(1423): at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:2291)
10-31 22:57:36.618: E/AndroidRuntime(1423): at android.app.ActivityThread.access$1700(ActivityThread.java:117)
10-31 22:57:36.618: E/AndroidRuntime(1423): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:942)
10-31 22:57:36.618: E/AndroidRuntime(1423): at android.os.Handler.dispatchMessage(Handler.java:99)
10-31 22:57:36.618: E/AndroidRuntime(1423): at android.os.Looper.loop(Looper.java:123)
10-31 22:57:36.618: E/AndroidRuntime(1423): at android.app.ActivityThread.main(ActivityThread.java:3683)
10-31 22:57:36.618: E/AndroidRuntime(1423): at java.lang.reflect.Method.invokeNative(Native Method)
10-31 22:57:36.618: E/AndroidRuntime(1423): at java.lang.reflect.Method.invoke(Method.java:507)
10-31 22:57:36.618: E/AndroidRuntime(1423): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
10-31 22:57:36.618: E/AndroidRuntime(1423): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
10-31 22:57:36.618: E/AndroidRuntime(1423): at dalvik.system.NativeStart.main(Native Method)
Did you set the content view correctly? Ensure that you are using your created R class, not the default android R class.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
EDIT:
You need to set the content view for the dialog, too.
#Override
protected void onPause() {
MyBeltegoed dialog = new MyBeltegoed (this, new OnReadyListenerBeltegoed());
dialog.setContentView(R.layout.custom_dialog); <-- add this
nieuwbel = (CheckBox)dialog.findViewById(R.id.nieuwbel);
Editor e = mPrefs.edit();
e.putBoolean(PREF_BOOL, nieuwbel.isChecked());
e.commit();
Toast.makeText(this, "Settings Saved.", Toast.LENGTH_SHORT).show();
super.onPause();
}
custom_dialog is the dialog that contains nieuwbel. (from http://developer.android.com/guide/topics/ui/dialogs.html#CustomDialog)