Android :: Calling Superclass Method In Subclass Constructor

Apr 30, 2010

I get a NullPointerException calling a Superclass Method in Subclass Inner Class Constructor... What's the Deal?

In my application's main class (subclass of Application), I have a public inner class that simply contains 3 public string objects. In the parent class I declare an object of that inner class.

CODE:...................

After I instantiate the object in the constructor, I get a runtime error when I try to assign a value in the inner class with a superclass method.

Can you not call superclass methods in the subclass constructor?

Android :: calling superclass method in subclass constructor


Android :: Method OnBackPressed() Of Type FirstGroup Must Override Superclass Method

Sep 7, 2010

I'm trying to override the onBackPressed() method of the ActivityGroup class:

public class MyClass extends ActivityGroup {

@Override
public void onBackPressed() {
// do something
return;
}

but I'm getting the error The method onBackPressed() of type MyClass must override a superclass method. I'm relatively new to Java, I've seen here that people do it and it works for them Why I'm getting this error? I'm writing an app for android 1.5, could the problem be here?

View 1 Replies View Related

Android :: Subclass Of View Constructor Not Being Called

Jun 6, 2010

I'm subclassing Android's view class, but whenever I make an instance of the view from another class, the constructor never gets called (or so it seems). I've implemented both public myclass (Context context) and public myclass (Context context, AttributeSet, attrs) I can't figure out what I'm doing wrong. Do I need to override onDraw and onMeasure?

View 1 Replies View Related

Android :: Calling Method From Service Immediately

Sep 3, 2010

I'm pretty sure that android services are going to be the end of me.I have almost no hair left after the last few days.At first I was having a heck of a time getting the service to bind on an onclick of a button, got that straightened out from help here yesterday. Now I actually want the service to bind in the onCreate() method of the activity. That part is no problem, works as intended.My service is actually a socket service to connect TCP sockets to a socket server that I wrote.If I put the call to the method from the bound service mBoundService.StartSocketServer() inside a button click, bingo, works great. But I need this to fire up immediately when the activity loads, so directly under my bindService() call within my onCreate() method of the activity.When I place the call to start the socket inside my onCreate() I get a force-close.

This method (StartSocketServer()) spawns a new thread then opens the socket on that thread to my remote machine.I'm guessing that the problem lies with the new thread generation before the activity fully loads not sure.LogCat is fairly cryptic here. It does say something about thread attach failed, then shows an uncaught handler exception that has "Caused by: java.lang.NullPointerException" within it.Again, if I put this call to the method inside a button click, I"m in business, if it's in the onCreate() it fails. Is there some way inside an activity (presuming that my assumption is correct that it needs to fully load before spawning a new thread) to call the StartSocketServer() after it's loaded: ala body.onLoad() in html?

View 1 Replies View Related

Android :: Calling A Non-static Java Method From C

Dec 22, 2009

In my Android app, I need to call a non static java method from C/C++. But i get a blunt crash when i do it using GetMethodID/CallVoidMethod()1 methods.

I have done like this:

1. Register the method using GetMethodID() as follows (mine is a cpp file): jmethodID xyz = (env)->GetMethodID( cls, "showxyz", "()V");

2. And I call this method as follows: env->CallVoidMethod(cls, xyz);

3. In java, my showxyz() is defined this way(this basically enables a button which was disabled) void showxyz() {findViewById(R.id.btnPass).setEnabled(true);}

And this crashes.

But I have been using this method of calling Java funcs from C using a set of GetStaticMethodID/CallStaticVoidMethod()(for nonstatic methods) and that works always.

But in this case, I have to call a non-static method and i get a crash.

View 2 Replies View Related

Android :: Error When Calling Method SetRequestedOrientation() / Fix It?

Aug 18, 2010

Code...

When the method is called setRequestedOrientation() - error. Create layout-land and placed there a copy of the main.xml file.

View 2 Replies View Related

Android :: Calling An InputMethod Method When A BroadcastReceiver Gets Called

Feb 19, 2010

I added a BroadCastReceiver to my application.I want to call my inputMethod's method but I can't find a way to access it's instance.but I couldn't find a way to get the the InputMethod instance from the InputMethodManager.Is doing a singleton the only way to access it?

View 1 Replies View Related

Android :: How To Stop Service Method Of Calling Activity Class?

Jul 2, 2010

I am trying to call my service class's stopService() method from my activity. But I don't know how to access stopservice method from my activity class. I have the below code but its not working. This is HomeScreen class:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
enablecheck = (CheckBox)findViewById(R.id.enablecheck);
enablecheck.setOnCheckedChangeListener(new OnCheckedChangeListener(){
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// TODO Auto-generated method stub
if(enablecheck.isChecked()){
startService(new Intent(HomeScreen.this, AutoService.class));
} else {
stopService(new Intent(HomeScreen.this, AutoService.class));
} } });
}
This is Service Class:
public class AutoService extends Service {
private static final String TAG = "AutoService";
private Timer timer;
private TimerTask task;
@Override
public IBinder onBind(Intent intent) {
return null;
} @Override
public void onCreate() {
Toast.makeText(this, "Auto Service Created", Toast.LENGTH_LONG).show();
Log.d(TAG, "onCreate");
int delay = 5000; // delay for 5 sec.
int period = 5000; // repeat every sec.
timer = new Timer();
timer.scheduleAtFixedRate(task = new TimerTask(){
public void run() {
System.out.println("done");
} }, delay, period);
}
@Override
public boolean stopService(Intent name) {
// TODO Auto-generated method stub
timer.cancel();
task.cancel();
return super.stopService(name);
} }

View 3 Replies View Related

Android :: Activity Constructor Vs OnCreate

Jul 21, 2010

I understand that Android Activities have specific lifecycles and that onCreate should be overridden and used for initialization, but what exactly happens in the constructor? Are there any cases when you could/should override the Activity constructor as well, or should you never touch it?

I'm assuming that the constructor should never be used because references to Activities aren't cleaned up entirely (thus hampering the garbage collector) and that onDestroy is there for that purpose. Is this correct?

View 2 Replies View Related

Android :: NinePatchDrawable Constructor - Chunk And Padding

Mar 2, 2009

I am trying to create a NinePatchDrawable programmatically, but there is no documentation on the constructor's argruments (Bitmap bitmap, byte[] chunk, Rect padding, String srcName). Does anyone know what chunk and padding are... and how to specify them?

View 7 Replies View Related

Android :: StartActivity From Subclass?

May 15, 2009

I have a Activity and I have a class which extends this Activity. In this subclass I call:

startActivity(new Intent(this, CameraView.class))

Which should start the "CameraView" Activity. However, I always get this error:

CODE:...........

If it makes any difference the subclass creates a ListView and when a row of the ListView is clicked it calls startActivity();

View 5 Replies View Related

Android :: Pass Enumerators To An Activity Constructor From An Intent?

May 14, 2010

I have an activity that when started needs access to two different ArrayLists. Both Lists are different Objects I have created myself.

Basically I need a way to pass these objects to the activity from an Intent. I can use addExtras() but this requires a Parceable compatible class. I could make my classes to be passed serializable but as I understand this slows down the program.

What are my options?

Can I pass an Enum?

As an an aside: is there a way to pass parameters to an Activity Constructor from an Intent?

View 3 Replies View Related

Android :: StartActivity() In A Subclass Of Dialog?

Nov 24, 2010

I have one subclass which extends Dialog class, it seems I can not use startActivity() function to start a new Activity in this subclass which extends Dialog class, how to resolve it?

How to start a new Activity in a Dialog subclass? (In my customized dialog subclass, I have one button, when pressed, I would like to have a new Activity start).

View 3 Replies View Related

Android :: Subclass Of ArrayAdapter Not Working

Nov 4, 2009

I have subclassed ArrayAdapter to set the color of text to RED if the string does not contain 100%, this has been added to a ListView. The problem is that some of the rows show as red when they contain 100%.

CODE:.....................

View 7 Replies View Related

Android :: Class Derived From Intent Service Must Have Default Constructor

May 8, 2009

I'm posting this to share the lessons I learned while working with IntentService. IntentService has a single constructor that takes a string argument "name". The documentation has no description of what name is used for. In looking at the sources, I found that its only use is in naming the worker thread for the IntentService. This thread is named IntentService [name].

I initially implemented the constructor of the derived class to also take a String argument and passed it along to the derived class. This is wrong. This will cause the startService() call to generated a java.lang.InstantiationException in the application containing the service i.e. you don't get the exception in the application calling startService(). A clue to the actual problem is a little further up in the logs:"newInstance failed: no <init>()"

The derived class must have a Default constructor and that constructor must call super() passing a string for the name component of the worker thread name.
public class MyIntentService extends IntentService {
public MyIntentService() { super("MyIntentService");
} @Override
protected void onHandleIntent(Intent intent) {
// Handle events on worker thread here }

View 2 Replies View Related

Android :: How To Use Parcelable - If Class Requires Additional Parameters In Constructor

May 20, 2010

I'm trying to create class with generics that will have ability to serialize its state using Parcelable interface.
The problem is that class has to contain constructor with single parameter - Parcel, but in my case I need to create class with additional parameters.
Besides, Parcelable.Creator doesn't allow to use generics.

Here is an example:

public class Sample<T> { ...

public Sample(Context ctx, SomeInterface iface, Parcel parcel) {...}

...}

What is the best practice to do it?

View 1 Replies View Related

Android :: Retrieve Saved State Of Custom View In Constructor?

Oct 12, 2009

The "View" instance currently provides a way to retrieve the saved state using the methods below, but there doesn't seem a way to retrieve the view's saved state in the constructor, or onFinishInflate. The custom view is constructed via XML, so I cannot pass the saved bundle from the Activity to the View's constructor.

Relevant methods: - protected Parcelable onSaveInstanceState() and - protected void onRestoreInstanceState(Parcelable state)

I need this because I make an asynchronous network request in a custom view constructor, and if there is a configuration (orientation) change, the custom view is getting reconstructed, and the request is getting performed again. I want to intercept the second request in the constructor. I can do this in the onRestoreInstanceState, but I need to handle this in the constructor.

It would be nice if there was a method such as getSavedState so that the decision can be made in a constructor or onFinishInflate instead of waiting for the onRestoreInstanceState trigger.

View 3 Replies View Related

Android :: ListActivity Subclass - OnListItemClick Never Called?

Aug 1, 2010

I don't think this problem is caused from my ListActivity subclass. I think it has something to do with with my BaseAdapter subclass:

package com.mohit.gtodo;
import com.mohit.gtodo.database.TasksDBAdapter;
import android.content.Context;
import android.database.Cursor;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CursorAdapter;
import android.widget.TextView;............................

View 1 Replies View Related

Android :: App.Application Subclass - OnTerminate Is Not Being Called

Mar 19, 2010

From the documentation for android.app.Application:

"Base class for those who need to maintain global application state"

I am using my own subclass to maintain an object that I'm using to query a server. Also from the documentation:

"onTerminate() Called when the application is stopping."

However, onTerminate() in my class is never called. I press the back button while viewing my main activity, and everything seems to shut down. My main Activity's onDestroy() method is called and isFinishing() returns true, but my android.app.Application's onTerminate() method is never called.

View 1 Replies View Related

Android :: Dalvik Message - Default Buffer Size Used In BufferedInputStream Constructor

Aug 17, 2010

When I used BufferedInputStream and I specify a buffer size, Dalvik gives me this warning - Default buffer size used in BufferedInputStream constructor. It would be better to be explicit if an 8k buffer is required.
But right now, my buffer size is already at 8k. What am I doing wrong?

View 1 Replies View Related

Android :: What Is The Significance Of Context In Various Constructor Of Intent Class When Starting An Activity

Mar 4, 2010

I had come across a code snippet which calls for an activity without referring to any context. Before, i was considering that context is used to tell about the calling component. But as i came see that another component can be called without any reference to context, it makes me wonder what purpose it might be serving. please put some light on it.

Here is the code which calls for an activity without referring to 'context'

CODE:............................

View 1 Replies View Related

Android :: Application Subclass Constantly Generates Forceclose

Nov 16, 2010

I've found a example on this site on how to make a subclass of the application for android.

I've created this code

package mensand.test;
class TestApp extends android.app.Application { }

Added this line to the manifest

android:name="mensand.test.TestApp"

And when i run the app it's starts with a force close message.

When i remove the line from the manifest all runs ok

View 2 Replies View Related

Android :: Multiple Intents In A ListView Populated Via Subclass

Jun 2, 2010

I have a ListActivity which is being filled via an internal class "OrderAdapter" - while the list is being populated I set various OnClickListeners on the TextView elements which should open the same view with different parameter values per line. My problem I have is that no matter which entry in the list I click I will always get to a view with the same parameter ID (it's always the ID of the last line in the list) - even though the output of the ID varies if I output it to the TextView.

Here is the code of the internal class which populates the list in the ListActivity:

CODE:.............

Any ideas why it always opens the view with the same ID even though the TextView "tvCheatTitle" displays a different value in every line?

View 4 Replies View Related

Android :: How To Access Protected Fields From View Subclass?

Apr 19, 2010

I'm implementing custom widget exdending a View class. But I've found that View's protected field (e.g. mLeft) is not accessible from subClass

View 2 Replies View Related

Android :: Test OnLowMemory Function Of Application Subclass?

Jun 11, 2010

I have put some instructions in onLowMemory() callback and want to test the same. Is there a "direct" way to test onLowMemory function of the application subclass?

Or will I have to just overload the phone by starting many apps and doing memory intensive tasks?

View 2 Replies View Related

Android :: Manually Set Preferences Being Overwritten By A Subclass Of PreferenceActivity

Mar 16, 2010

I am having a problem with an application I am in the middle of writing which is causing me some serious headaches.

The situation is this:

The application allows the user to configure several different kinds of information in several activities.

One of the activities, which is a subclass of Activity, takes data from the user and stores it in a shared preferences instance that I create manually and edit in code. This activity requires a complex screen layout that I do not believe would work well with a PreferenceActivity, hence me rolling my own in this case.

Another one of the activities, which is a subclass of PreferenceActivity, is a straight forward list of preferences, each with a list options - standard stuff.

I am finding that any data that I store from the first activity, my bespoke preference screen which manually adds the data using a StoredPreferences.Editor instance is overwritten once the user selects an option in my activity that extends PreferenceActivity.

View 4 Replies View Related

Android :: ClassCastException When Casting Custom View Subclass

May 23, 2010

I've run into an early problem with developing for android. I've made my own custom View (which works well). In the beginning i just added it to the layout programmatically, but i figured i could try putting it into the XML layout instead (for consistency).

So what i got is this:

main.xml:

CODE:..........

(Theres obviously more, but you get the point)

Now, this is the stacktrace:

CODE:...........

Why cant i cast my custom view? I need it to be that type since it has a few extra methods in it that i want to access. Should i restructure it and have another class handle the logic, and then just having the view being a view? I'd really like this to work though.

View 2 Replies View Related

App Crash Every Time Try To Call Constructor Code From Map Class

Oct 10, 2013

I'm developing an app that uses google maps, but for some reason it crashed every time I try to call the constructor code from the map class.

main
[HIGH]import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {

[Code] ......

View 2 Replies View Related

Android :: Static Variables Of An ApplicationContext Subclass Left Untouched When The Process Is Killed?

Sep 7, 2010

Do static variables of an ApplicationContext subclass left untouched when the process is killed?

View 4 Replies View Related

Android :: Show Method Definition - Eclipse Recognizes Warning On Method

Nov 22, 2010

In Eclipse, when I mouse hover over a built-in method, it displays a method definition including stuff like what the method does, input objects, return objects etc. If I have a yellow line (warning) under the method I'm trying to use, I can't get the mouse-over to show the definition. If I try hitting F3, I get a "The Jar of this class file belongs to container "Android 1.6" How do I show the definition of the method I am using when there is a warning?

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved