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)
Related
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 made a timer for my app but it keeps crashing and throwing an exception when I try to open it through my listActivity
code is below, I posted only the important ones
tool.java
package com.example.taekwondobuddy.util;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class Tools extends ListActivity{
String classes[] = {"Counter","Accelermeter","Time"} ;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(Tools.this, android.R.layout.simple_list_item_1, classes));
}
#Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
String cheese = classes[position];
try{
Class ourclass = Class.forName("com.example.taekwondobuddy.util." + cheese);
Intent ourIntent = new Intent(Tools.this, ourclass);
startActivity(ourIntent);
} catch(ClassNotFoundException e){
e.printStackTrace();
}
}
}
time.java
package com.example.taekwondobuddy.util;
import java.util.Timer;
import java.util.TimerTask;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class Time extends Activity {
TextView mTextView;
Button mButtonStart;
Button mButtonStop;
int mCount;
Timer mTimer;
Handler mHandler = new Handler();
Runnable TheDelegatedTimerTask = new Runnable() {
#Override
public void run() {
mCount++;
mTextView.setText("Count=" + mCount);
}
};
protected class TheTimerTask extends TimerTask {
#Override
public void run() {
// What we want to say is
// mCount++;
// mTextView.setText("Count="+mCount);
// But this gives
// "Only the original thread that created a view hierarchy can touch its views."
mHandler.post(TheDelegatedTimerTask);
}
}
protected void timerStart() {
if (mTimer == null) {
mTimer = new Timer();
mTimer.schedule(new TheTimerTask(), 0, 100); // 100 milli seconds
}
}
protected void timerStop() {
if (mTimer != null) {
mTimer.cancel();
mTimer = null;
}
}
OnClickListener mButtonStart_OnClick = new OnClickListener() {
#Override
public void onClick(View v) {
mCount = 0;
timerStart();
}
};
OnClickListener mButtonStop_OnClick = new OnClickListener() {
#Override
public void onClick(View v) {
timerStop();
}
};
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.timer);
mTextView = (TextView) findViewById(R.id.textview);
mButtonStart = (Button) findViewById(R.id.buttonstart);
mButtonStop = (Button) findViewById(R.id.buttonstop);
mButtonStart.setOnClickListener(mButtonStart_OnClick);
mButtonStop.setOnClickListener(mButtonStop_OnClick);
}
}
timer.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<TextView
android:id="#+id/textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="26dp"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:id="#+id/buttonstart"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textview"
android:layout_below="#+id/textview"
android:layout_marginTop="50dp"
android:text="Start" />
<Button
android:id="#+id/buttonstop"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/buttonstart"
android:layout_centerVertical="true"
android:text="Stop" />
</RelativeLayout
Any ideas what's the problem?
EDIT
error log
10-31 02:44:52.053: E/AndroidRuntime(304): FATAL EXCEPTION: main
10-31 02:44:52.053: E/AndroidRuntime(304): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.taekwondobuddy.util/com.example.taekwondobuddy.util.Time}; have you declared this activity in your AndroidManifest.xml?
10-31 02:44:52.053: E/AndroidRuntime(304): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1404)
10-31 02:44:52.053: E/AndroidRuntime(304): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
10-31 02:44:52.053: E/AndroidRuntime(304): at android.app.Activity.startActivityForResult(Activity.java:2817)
10-31 02:44:52.053: E/AndroidRuntime(304): at android.app.Activity.startActivity(Activity.java:2923)
10-31 02:44:52.053: E/AndroidRuntime(304): at com.example.taekwondobuddy.util.Tools.onListItemClick(Tools.java:30)
10-31 02:44:52.053: E/AndroidRuntime(304): at android.app.ListActivity$2.onItemClick(ListActivity.java:321)
10-31 02:44:52.053: E/AndroidRuntime(304): at android.widget.AdapterView.performItemClick(AdapterView.java:284)
10-31 02:44:52.053: E/AndroidRuntime(304): at android.widget.ListView.performItemClick(ListView.java:3382)
10-31 02:44:52.053: E/AndroidRuntime(304): at android.widget.AbsListView$PerformClick.run(AbsListView.java:1696)
10-31 02:44:52.053: E/AndroidRuntime(304): at android.os.Handler.handleCallback(Handler.java:587)
10-31 02:44:52.053: E/AndroidRuntime(304): at android.os.Handler.dispatchMessage(Handler.java:92)
10-31 02:44:52.053: E/AndroidRuntime(304): at android.os.Looper.loop(Looper.java:123)
10-31 02:44:52.053: E/AndroidRuntime(304): at android.app.ActivityThread.main(ActivityThread.java:4627)
10-31 02:44:52.053: E/AndroidRuntime(304): at java.lang.reflect.Method.invokeNative(Native Method)
10-31 02:44:52.053: E/AndroidRuntime(304): at java.lang.reflect.Method.invoke(Method.java:521)
10-31 02:44:52.053: E/AndroidRuntime(304): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
10-31 02:44:52.053: E/AndroidRuntime(304): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
10-31 02:44:52.053: E/AndroidRuntime(304): at dalvik.system.NativeStart.main(Native Method)
It's hard to know what the issue is without seeing anything from your logcat.
Try changing the TimerTask run() to
mTextView.post(new TheDelegatedTimerTask());
That should queue up the work on the UI thread. It looks like that's what you're trying to figure out based on your commented out code.
oh embarrassing I forgot to put in my manifest
I want to stop a running thread while click on the splash screen, if I don't click on screen, after the thread execution, it will launch another Activity. But getting UnSupportedException, how do I solve it?
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
iImage = (ImageView) findViewById(R.id.iIcon);
splashImage = (ImageView) findViewById(R.id.splash_image);
iImage.setOnClickListener(this);
splashImage.setOnClickListener(this);
}
#Override
protected void onStart() {
super.onStart();
splashTimer = new Thread(new Runnable() {
#Override
public void run() {
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
startActivity(new Intent(SplashActivity.this, LoginAuthenticationActivity.class));
finish();
}
});
splashTimer.start();
}
#Override
public void onClick(View view) {
if(splashTimer.isAlive())
splashTimer.stop();
switch (view.getId()) {
case R.id.iIcon:
startActivity(new Intent(this, AboutUsActivity.class));
break;
case R.id.splash_image:
startActivity(new Intent(this, LoginAuthenticationActivity.class));
break;
default:
break;
}
finish();
}
Log:
01-27 03:27:01.189: W/dalvikvm(1080): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
01-27 03:27:01.209: E/AndroidRuntime(1080): FATAL EXCEPTION: main
01-27 03:27:01.209: E/AndroidRuntime(1080): java.lang.UnsupportedOperationException
01-27 03:27:01.209: E/AndroidRuntime(1080): at java.lang.Thread.stop(Thread.java:1076)
01-27 03:27:01.209: E/AndroidRuntime(1080): at java.lang.Thread.stop(Thread.java:1063)
01-27 03:27:01.209: E/AndroidRuntime(1080): at com.app.wooqer.SplashActivity.onClick(SplashActivity.java:48)
01-27 03:27:01.209: E/AndroidRuntime(1080): at android.view.View.performClick(View.java:3511)
01-27 03:27:01.209: E/AndroidRuntime(1080): at android.view.View$PerformClick.run(View.java:14105)
01-27 03:27:01.209: E/AndroidRuntime(1080): at android.os.Handler.handleCallback(Handler.java:605)
01-27 03:27:01.209: E/AndroidRuntime(1080): at android.os.Handler.dispatchMessage(Handler.java:92)
01-27 03:27:01.209: E/AndroidRuntime(1080): at android.os.Looper.loop(Looper.java:137)
01-27 03:27:01.209: E/AndroidRuntime(1080): at android.app.ActivityThread.main(ActivityThread.java:4424)
01-27 03:27:01.209: E/AndroidRuntime(1080): at java.lang.reflect.Method.invokeNative(Native Method)
01-27 03:27:01.209: E/AndroidRuntime(1080): at java.lang.reflect.Method.invoke(Method.java:511)
01-27 03:27:01.209: E/AndroidRuntime(1080): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
01-27 03:27:01.209: E/AndroidRuntime(1080): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
01-27 03:27:01.209: E/AndroidRuntime(1080): at dalvik.system.NativeStart.main(Native Method)
What you're doing is very wasteful (any splash screen is wasteful, but using Threads like this is more so), but to fix your issue:
use interrrupt(); intead of stop();
As the docs say for stop()
Throws UnsupportedOperationException.
And to fix the duplicate issue, move the startActivity() inside the try so it looks like this:
public void run() {
try {
Thread.sleep(5000);
startActivity(new Intent(SplashActivity.this, LoginAuthenticationActivity.class));
} catch (InterruptedException e) {
e.printStackTrace();
}
finish();
}
That way when you call interrupt() all your Activity does is finish() and the duplicate startActivity() is not called.
To further explain:
Very first issue: stop() throws an exception by default, since it's an unsafe method which you're not supposed to use.
Then when you used interrupt(), you had startActivity() in the run method after the catch block. When you interrupted, startActivity() was called once in run() and once in onClick(). By moving startActivity() inside the try block to right after Thread.sleep(), when interrupt() interrupts the Thread, the rest of the try block isn't executed. This means that you now only have one startActivity() call instead of two. For more information, read up on exceptions.
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.
So whenever I click the button on the startup page, it gives me a force close error. Here's the class for the main.xml layout file:
public class ForeverAloneActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btnstrt = (Button) findViewById(R.id.toq1);
btnstrt.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
// TODO Auto-generated method stub
Intent frstq = new Intent(v.getContext(), QuestionOne.class);
startActivityForResult(frstq, 0);
And this is what I believe is producing the error. This class is related to the page that that when pressing the button on the startup page, you are taken to:
#Override
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView (R.layout.frstq);
Button startQ2 = (Button) findViewById(R.id.toq2);
startQ2.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
// TODO Auto-generated method stub
Intent toQ2 = new Intent(v.getContext(), QuestionTwo.class);
final EditText number = (EditText) findViewById(R.id.editText1);
final Toast error = Toast.makeText(QuestionOne.this, "Please insert a value", Toast.LENGTH_SHORT);
if (number.getText().toString().equals("")) {error.show();
}else{
startActivityForResult(toQ2, 0);}
That if statement is there as on the next page, there is an EditText box. I tried to make it so that if there is nothing in the EditText box, it displays a toast message saying "Please insert a value". Until an integer is put into the EditText box, then the button will not work.
If someone can help, it will be much appreciated.
Logcat:
04-07 19:33:58.199: W/dalvikvm(362): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
04-07 19:33:58.221: E/AndroidRuntime(362): FATAL EXCEPTION: main
04-07 19:33:58.221: E/AndroidRuntime(362): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.kenning.foreveralone/com.kenning.foreveralone.QuestionOne}; have you declared this activity in your AndroidManifest.xml?
04-07 19:33:58.221: E/AndroidRuntime(362): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1404)
04-07 19:33:58.221: E/AndroidRuntime(362): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
04-07 19:33:58.221: E/AndroidRuntime(362): at android.app.Activity.startActivityForResult(Activity.java:2817)
04-07 19:33:58.221: E/AndroidRuntime(362): at com.kenning.foreveralone.ForeverAloneActivity$1.onClick(ForeverAloneActivity.java:22)
04-07 19:33:58.221: E/AndroidRuntime(362): at android.view.View.performClick(View.java:2408)
04-07 19:33:58.221: E/AndroidRuntime(362): at android.view.View$PerformClick.run(View.java:8816)
04-07 19:33:58.221: E/AndroidRuntime(362): at android.os.Handler.handleCallback(Handler.java:587)
04-07 19:33:58.221: E/AndroidRuntime(362): at android.os.Handler.dispatchMessage(Handler.java:92)
04-07 19:33:58.221: E/AndroidRuntime(362): at android.os.Looper.loop(Looper.java:123)
04-07 19:33:58.221: E/AndroidRuntime(362): at android.app.ActivityThread.main(ActivityThread.java:4627)
04-07 19:33:58.221: E/AndroidRuntime(362): at java.lang.reflect.Method.invokeNative(Native Method)
04-07 19:33:58.221: E/AndroidRuntime(362): at java.lang.reflect.Method.invoke(Method.java:521)
04-07 19:33:58.221: E/AndroidRuntime(362): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-07 19:33:58.221: E/AndroidRuntime(362): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-07 19:33:58.221: E/AndroidRuntime(362): at dalvik.system.NativeStart.main(Native Method)
are you adding QuestionTwo in manifiest file ?
check your error - have you declared this activity in your AndroidManifest.xml?
Declare your activity in manifeast file. It seems you forgetted that
<activity android:name="QuestionTwo" />
also dont forget to include every activity in your manifeast file
Hey have you added the QuestionTwo class as an activity in menifest file. If after adding the
Intent toQ2 = new Intent(YourCurrentActivity.this,QuestionTwo.class);
then you must have not added the activity in menifest.B'coz it clearly shows in the log that Activity is not found. You have to declare the activity in menifest file.
Hope you'll get run your app.