i have Target.java(it is the main activity) and Layout.java.
When user clicks a button a url opens.
The button click is handled in Layout.java.
deleteButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
DebugLog.LOGD("Within onClick event of 'GO' button ");
Target.openURL();
}
});
Target.java has a static function openURL
public static void openURL() {
Uri uri = Uri.parse("http://www.thecinema.in");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}
I'd like to know how i can make this code work, since the error im getting now is "Cannot make a static reference to the non-static method startActivity(Intent) from the type Activity" . I can understand startActivity will not work within a static function, but please suggest me how i could acheive the objective ..Im a newbie to android.FYI ..Thanks guys
-Updated code :
Layout.java
deleteButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
DebugLog.LOGD("Within onClick event of 'GO' button ");
Target iA = new Target();
iA.openURL();
}
});
Target.java
public void openURL() { //removed static keyword
DebugLog.LOGD("Within nDelete event of GO button ");
Uri uri = Uri.parse("http://www.thecinema.in");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}
Exception thrown:
03-02 10:10:28.351: D/QCAR(6820): Within onClick event of 'GO' button
03-02 10:10:28.351: W/dalvikvm(6820): threadid=1: thread exiting with uncaught exception (group=0x400207d8)
03-02 10:10:28.361: E/AndroidRuntime(6820): FATAL EXCEPTION: main
03-02 10:10:28.361: E/AndroidRuntime(6820): java.lang.NullPointerException
03-02 10:10:28.361: E/AndroidRuntime(6820): at android.app.Activity.startActivityForResult(Activity.java:2817)
03-02 10:10:28.361: E/AndroidRuntime(6820): at android.app.Activity.startActivity(Activity.java:2923)
03-02 10:10:28.361: E/AndroidRuntime(6820): at com.ingage.pocs.phonegap.Layout$4.onClick(Layout.java:124)
03-02 10:10:28.361: E/AndroidRuntime(6820): at android.view.View.performClick(View.java:2408)
03-02 10:10:28.361: E/AndroidRuntime(6820): at android.view.View$PerformClick.run(View.java:8816)
03-02 10:10:28.361: E/AndroidRuntime(6820): at android.os.Handler.handleCallback(Handler.java:587)
03-02 10:10:28.361: E/AndroidRuntime(6820): at android.os.Handler.dispatchMessage(Handler.java:92)
03-02 10:10:28.361: E/AndroidRuntime(6820): at android.os.Looper.loop(Looper.java:123)
03-02 10:10:28.361: E/AndroidRuntime(6820): at android.app.ActivityThread.main(ActivityThread.java:4633)
Guys what went wrong in here..
i was able to come up with a solution for this question.
Under Target.java i created openURL() as:
public void openURL(Context context)
{
Intent intent = new Intent("com.ingage.pocs.phonegap.URL");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
I created a new Activity OpenURL.java and associated the intent "com.ingage.pocs.phonegap.URL" with it:
package com.ingage.pocs.phonegap;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
public class OpenURL extends Activity{
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
DebugLog.LOGD("Within BookTicketsActivity Activity GO button ");
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.thecinema.in"));
startActivity(browserIntent);
}
}
Layout.java:
private Context applicationContext;
deleteButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
DebugLog.LOGD("Within onClick event of 'GO' button ");
ImageTargets ia =new ImageTargets();
ia.openURL(applicationContext);
iA.openURL();
}
});
The best thing is, it worked :) If you guys come up with a better or more sensible solution , pls do post here.thank you
startActivity is not static and since you call it from Target not Layout it cannot resolve call context.
You'll need to call startActivity from Layout.java or pass reference or Target to Layout class
do it like this
Layout.java:
deleteButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
DebugLog.LOGD("Within onClick event of 'GO' button ");
Target.openURL(Layout.this);
}
});
Target.java:
public static void openURL(Context context) {
Uri uri = Uri.parse("http://www.thecinema.in");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
context.startActivity(intent);
}
You have
Targets iA = new Targets();
Did you, perhaps, mean to write
Target iA = new Target();
That would throw a NullPointerException because you're asking Java to find a class named Targets when none exists.
Related
I am creating a call application i created an adapter for Recycler view on requesting CALL_PHONE there is showing the error
E/AndroidRuntime: FATAL EXCEPTION: main Process: in.welcomeyou.merchant, PID: 14890 java.lang.ClassCastException: android.app.Application cannot be cast to android.app.Activity
#Override
public void onBindViewHolder(EnquiryViewHolder holder, int position) {
Enquiry enquiry = enquiryList.get(position);
holder.domainTextView.setText(enquiry.getDomain());
holder.nameTextView.setText(enquiry.getName());
holder.commentsTextView.setText(enquiry.getComments());
holder.dateTextView.setText(enquiry.getDate());
holder.callBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
if (ActivityCompat.checkSelfPermission(mCtx, CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(MainActivity.this,
new String[]{Manifest.permission.CALL_PHONE},
Constants.CALL_PHONE);
return;
}
Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:123456"));
mCtx.startActivity(intent);
}
});
}
Where you are passing context to this adapter use ActivityName.this or this .
Maybe now you passed
getApplicationContext();
And you get this exception because you can not cast the Application to Activity because Application is not a sub-class of Activity.
Please write this as below
Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:123456"));
((YourActivityName)mContext).startActivity(intent);
This question already has answers here:
What is a NullPointerException, and how do I fix it?
(12 answers)
Closed 5 years ago.
I have created an app with 5 tabs, in my 1st tab I am having a button on click of which I want to go to tab3. This is my code of button event --
moreButton3.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(view.getContext(), Tab3_Image.class);
view.getContext().startActivity(intent);
}
});
But while clicking the button the app crash, below is the logcat error --
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.s2s.doupnow, PID: 22481
java.lang.NullPointerException
at com.s2s.doupnow.Tab1_Home$6.onClick(Tab1_Home.java:313)
at android.view.View.performClick(View.java:4444)
at android.view.View$PerformClick.run(View.java:18457)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5113)
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:796)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:612)
at dalvik.system.NativeStart.main(Native Method)
Change this -:
moreButton3.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(view.getContext(), Tab3_Image.class);
view.getContext().startActivity(intent);
}
});
To-:
private Context context=this; //make it global
Button moreButton3=(Button)findViewById(R.id.buttoninxml);
moreButton3.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(context, Tab3_Image.class);
startActivity(intent);
}
});
I have the following Activity:
package com.example.myapp;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.content.SharedPreferences;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ScrollView;
import android.widget.Toast;
public class HomeActivity extends Activity implements AnimationListener {
// Animation
Animation animFadein;
Animation animFadeout;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.home_start);
// load the animation
animFadein = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.fade_in);
animFadeout = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.fade_out);
// set animation listener
animFadein.setAnimationListener(this);
ImageButton homepage =(ImageButton)findViewById(R.id.homepage);
ImageButton new_b =(ImageButton)findViewById(R.id.new_b);
ImageButton view_b =(ImageButton)findViewById(R.id.view_b);
ImageButton home_b =(ImageButton)findViewById(R.id.home_b);
ImageButton info_b =(ImageButton)findViewById(R.id.info_b);
Button back_b =(Button)findViewById(R.id.back_b);
Button site =(Button)findViewById(R.id.site);
homepage.startAnimation(animFadein);
//Click on screen to start
homepage.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
View homepage = (View)findViewById(R.id.homepage);
View startpage = (View)findViewById(R.id.startpage);
homepage.setVisibility(View.GONE);
homepage.startAnimation(animFadeout);
startpage.setVisibility(View.VISIBLE);
startpage.setAnimation(animFadein);};});
new_b.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
SharedPreferences values = getSharedPreferences("valoar", 0);
SharedPreferences.Editor editor = values.edit();
editor.clear();
editor.commit();
View startpage = (View)findViewById(R.id.startpage);
startpage.setAnimation(animFadeout);
Intent intent = new Intent(HomeActivity.this,QuestionsActivity.class);
startActivity(intent);}});
home_b.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
View homepage = (View)findViewById(R.id.homepage);
View startpage = (View)findViewById(R.id.startpage);
homepage.setVisibility(View.VISIBLE);
homepage.startAnimation(animFadein);
startpage.startAnimation(animFadeout);
startpage.setVisibility(View.GONE);};});
info_b.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
View startpage = (View)findViewById(R.id.startpage);
View infopage = (View)findViewById(R.id.infopage);
ScrollView info_s = (ScrollView)findViewById(R.id.info_s);
infopage.setVisibility(View.VISIBLE);
info_s.setVisibility(View.VISIBLE);
infopage.startAnimation(animFadein);
startpage.startAnimation(animFadeout);
startpage.setVisibility(View.GONE);};});
back_b.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
View startpage = (View)findViewById(R.id.startpage);
View infopage = (View)findViewById(R.id.infopage);
ScrollView info_s = (ScrollView)findViewById(R.id.info_s);
infopage.setVisibility(View.GONE);
info_s.setVisibility(View.GONE);
infopage.startAnimation(animFadeout);
startpage.startAnimation(animFadein);
startpage.setVisibility(View.VISIBLE);};});
**site.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent internetIntent = new Intent(Intent.ACTION_VIEW,
Uri.parse("http://www.i-amapp.com"));
internetIntent.setComponent(new ComponentName("com.android.browser","com.android.browser.BrowserActivity"));
internetIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(internetIntent);};});**
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.home, menu);
return true;
}
#Override
public void onAnimationEnd(Animation arg0) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
/**
* Back button listener.
* Will close the application if the back button pressed twice.
*/
#Override
public void onBackPressed()
{
int backButtonCount = 0;
if(backButtonCount >= 1)
{
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
finish();
}
else
{
Toast.makeText(this, "Press the x button to close the application.", Toast.LENGTH_SHORT).show();
backButtonCount++;
}
}
}
It works very well in android 4.1.2, but in android 2.3.7 it crashes, and Logcat displays:
D/AndroidRuntime(2172): Shutting down VM
W/dalvikvm(2172): threadid=1: thread exiting with uncaught exception (group=0x40018560)
E/AndroidRuntime(2172): FATAL EXCEPTION: main
E/AndroidRuntime(2172): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myapp/com.example.myapp.HomeActivity}: java.lang.NullPointerException
E/AndroidRuntime(2172): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1768)
E/AndroidRuntime(2172): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1784)
E/AndroidRuntime(2172): at android.app.ActivityThread.access$1500(ActivityThread.java:123)
E/AndroidRuntime(2172): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:939)
E/AndroidRuntime(2172): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(2172): at android.os.Looper.loop(Looper.java:130)
E/AndroidRuntime(2172): at android.app.ActivityThread.main(ActivityThread.java:3835)
E/AndroidRuntime(2172): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(2172): at java.lang.reflect.Method.invoke(Method.java:507)
E/AndroidRuntime(2172): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864)
E/AndroidRuntime(2172): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)
E/AndroidRuntime(2172): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(2172): Caused by: java.lang.NullPointerException
E/AndroidRuntime(2172): at com.example.myapp.HomeActivity.onCreate(HomeActivity.java:107)
E/AndroidRuntime(2172): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
E/AndroidRuntime(2172): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1722)
E/AndroidRuntime(2172): ... 11 more
D/dalvikvm(3117): GC_EXTERNAL_ALLOC freed 61K, 50% free 2724K/5379K, external 0K/0K, paused 44ms
D/dalvikvm(3117): GC_EXTERNAL_ALLOC freed 4K, 50% free 2730K/5379K, external 507K/513K, paused 43ms
D/dalvikvm(3117): GC_EXTERNAL_ALLOC freed 1K, 50% free 2736K/5379K, external 1068K/1524K, paused 43ms
D/dalvikvm(3117): GC_EXTERNAL_ALLOC freed 1K, 50% free 2741K/5379K, external 1669K/2086K, paused
This is all that logcat is displaying. I can't figure out what is the problem!
Why does it crash in android 2.3?
I have seen numerous similar questions on stackoverflow but I can not figure out what I am doing wrong. I have made a very simple app to replicate the error.
The app does the following:
it adds a fragment in the MainActivty's onCreate.
user can add another fragment from a dialog.
when the dialog calls the MainActivity's addFragment method an exception is thrown on the commit of the transaction.
Here is the MainActivity
package com.example.testapp;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.widget.Button;
public class MainActivity extends FragmentActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Button button = (Button) findViewById(R.id.add_button);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
AddButtonDialog addButtonDialog = new AddButtonDialog();
addButtonDialog.show(getSupportFragmentManager(), "ADD");
}
});
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
CustomFragment fragment = new CustomFragment();
transaction.add(R.id.fragment_container, fragment);
transaction.commit();
}
public void addButton() {
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
CustomFragment fragment = new CustomFragment();
transaction.add(R.id.fragment_container, fragment);
transaction.commit(); // <-- Exception
}
}
and here is the AddButtonDialog that calls the MainActivity
public class AddButtonDialog extends DialogFragment {
public Dialog onCreateDialog(Bundle savedInstanceState) {
final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
final LayoutInflater inflater = getActivity().getLayoutInflater();
View view = inflater.inflate(R.layout.new_button_dialog, null);
builder.setView(view)
.setPositiveButton("Add", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int id) {
MainActivity main = new MainActivity();
main.addButton();
}
});
return builder.create();
}
}
And here is the stacktrace
02-14 10:09:27.781: E/AndroidRuntime(26291): FATAL EXCEPTION: main
02-14 10:09:27.781: E/AndroidRuntime(26291): java.lang.IllegalStateException: Activity has been destroyed
02-14 10:09:27.781: E/AndroidRuntime(26291): at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1365)
02-14 10:09:27.781: E/AndroidRuntime(26291): at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:595)
02-14 10:09:27.781: E/AndroidRuntime(26291): at android.support.v4.app.BackStackRecord.commit(BackStackRecord.java:574)
02-14 10:09:27.781: E/AndroidRuntime(26291): at com.example.testapp.MainActivity.addButton(MainActivity.java:35)
02-14 10:09:27.781: E/AndroidRuntime(26291): at com.example.testapp.AddButtonDialog$1.onClick(AddButtonDialog.java:22)
02-14 10:09:27.781: E/AndroidRuntime(26291): at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:185)
02-14 10:09:27.781: E/AndroidRuntime(26291): at android.os.Handler.dispatchMessage(Handler.java:99)
02-14 10:09:27.781: E/AndroidRuntime(26291): at android.os.Looper.loop(Looper.java:137)
02-14 10:09:27.781: E/AndroidRuntime(26291): at android.app.ActivityThread.main(ActivityThread.java:5328)
02-14 10:09:27.781: E/AndroidRuntime(26291): at java.lang.reflect.Method.invokeNative(Native Method)
02-14 10:09:27.781: E/AndroidRuntime(26291): at java.lang.reflect.Method.invoke(Method.java:511)
02-14 10:09:27.781: E/AndroidRuntime(26291): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
02-14 10:09:27.781: E/AndroidRuntime(26291): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
02-14 10:09:27.781: E/AndroidRuntime(26291): at dalvik.system.NativeStart.main(Native Method)
I am fairly certain I am not grasping the concepts of the Fragment lifecycle. Please would someone be so kind as to explain what I am doing wrong.
Pass a reference of MainActivity to the Dialog and try this
mainActivity.addButton()
Where mainActivity is the reference
don't:
MainActivity main = new MainActivity();
main.addButton();
the way to start Activities in Android is via startActivity(intent); method
So for example do instead:
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
see Intent Guide
If your AddButtonDialog is an inner class then simply make a call to addActivity rather than doing main.addButton().
If not then try creating this method in a separate class and pass FragmentManager as a parameter to it. Thus you can call this from anywhere creating instance of the newly made class.
Also, try using the below in your addButton method,
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
CustomFragment fragment = new CustomFragment();
transaction.replace(R.id.fragment_container, fragment); //this will replace your fragment_container with this fragment
transaction.addToBackStack(null);// this will help you get back to your first fragment on back press
transaction.commit();
If all you want to do is calling a method in your Activity from somewhere else:
1 - create a static variable in your main activity, of type Activity, and instantiate it in onCreate to this, so you have your instance stored.
2 - create a static method in your main activity called get instance, that simply returns an instance of your activity
3 - wherever you are call : MainActivity.getInstance().yourMethod();
Of course it will only work if your activity is existing!
I created an overlay "always on top button", which is a service HUD, and I can't start an activity screen from there, it gives the error: "Unfortunately App has stopped". In the beginning, all I used to know if there was any TouchEventwas a toast, and that toast was created, but it was created several times, so I don't know if it gives that error because this code, which is on TouchEvent body , is repeated several times too.
here is my code:
public class HUD extends Service implements OnClickListener, OnTouchListener, OnLongClickListener {
Button mButton;
#Override
public IBinder onBind(Intent intent) {
return null;
}
#Override
public void onCreate() {
super.onCreate();
//mView = new HUDView(this);
mButton = new Button(this);
mButton.setId(1);
mButton.setText("Button");
mButton.setClickable(true);
mButton.setOnTouchListener(this);
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_PHONE,
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.OPAQUE);
params.gravity = Gravity.LEFT | Gravity.TOP;
params.setTitle("Load Average");
WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
wm.addView(mButton, params);
}
#Override
public void onDestroy() {
super.onDestroy();
if(mButton != null)
{
((WindowManager) getSystemService(WINDOW_SERVICE)).removeView(mButton);
mButton = null;
}
}
#Override
public boolean onTouch(View v, MotionEvent event) {
if(event.getX()<mButton.getWidth() & event.getY()>0)
{
Toast.makeText(this,"Overlay button event", Toast.LENGTH_SHORT).show(); //this my toast
Intent i = new Intent(); //this is my new acivity (intent)
i.setClass(HUD.this, screen.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
HUD.this.stopSelf();
}
return false;
}
#Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
Toast.makeText(this,"Click", Toast.LENGTH_SHORT).show();
}
#Override
public boolean onLongClick(View v) {
// TODO Auto-generated method stub
System.exit(1);
return false;
}
}
So my question is, is this code on TouchEvent body being repeated several times? If it is, is that the cause of the error?
log cat:
07-20 22:11:06.962: I/Choreographer(1620): Skipped 52 frames! The application may be doing too much work on its main thread.
07-20 22:11:08.062: D/AndroidRuntime(1620): Shutting down VM
07-20 22:11:08.062: W/dalvikvm(1620): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
07-20 22:11:08.132: E/AndroidRuntime(1620): FATAL EXCEPTION: main
07-20 22:11:08.132: E/AndroidRuntime(1620): android.app.SuperNotCalledException: Activity {com.example.screenshot/com.example.screenshot.screen} did not call through to super.onCreate()
07-20 22:11:08.132: E/AndroidRuntime(1620): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2146)
07-20 22:11:08.132: E/AndroidRuntime(1620): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
07-20 22:11:08.132: E/AndroidRuntime(1620): at android.app.ActivityThread.access$600(ActivityThread.java:141)
07-20 22:11:08.132: E/AndroidRuntime(1620): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
07-20 22:11:08.132: E/AndroidRuntime(1620): at android.os.Handler.dispatchMessage(Handler.java:99)
07-20 22:11:08.132: E/AndroidRuntime(1620): at android.os.Looper.loop(Looper.java:137)
07-20 22:11:08.132: E/AndroidRuntime(1620): at android.app.ActivityThread.main(ActivityThread.java:5041)
07-20 22:11:08.132: E/AndroidRuntime(1620): at java.lang.reflect.Method.invokeNative(Native Method)
07-20 22:11:08.132: E/AndroidRuntime(1620): at java.lang.reflect.Method.invoke(Method.java:511)
07-20 22:11:08.132: E/AndroidRuntime(1620): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
07-20 22:11:08.132: E/AndroidRuntime(1620): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
07-20 22:11:08.132: E/AndroidRuntime(1620): at dalvik.system.NativeStart.main(Native Method)
screen.java:
public class screen extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
Toast.makeText(getApplicationContext(), "Made it", 0).show();
finish();
}
}
See android start activity from service
Intent i= new Intent(getBaseContext(), screen.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplication().startActivity(i);
You error seems to be inside screen activity. There are many thread which might help to figure out the error that you are getting for the activity:
Error in Android "SuperNotCalledException:Activity did not call through to super.OnCreate()"
android.app.SuperNotCalledException: Activity did not call through to super.onStop()
Update
The error is because you haven't called: super.onCreate(savedInstanceState); in your screen activity's onCreate(). That should be the first thing to be called in onCreate(). Do something like this:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//.... other stuff
}
Hope this helps.