Activity using CacheWord has leaked ServiceConnection - service

Trying to use CacheWord in an app with multiple activities to handle my password for database encryption I get randomly the error that the activity has leaked ServiceConnection ... that was originally bound here.
I think this problem is caused by not disconnecting proberly the service when onDestroy() is called. But I don't know how to do this.
There is the structure of my MainActivity:
package de.my.app;
import info.guardianproject.cacheword.CacheWordActivityHandler;
import info.guardianproject.cacheword.CacheWordHandler;
import info.guardianproject.cacheword.ICacheWordSubscriber;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.channels.FileChannel;
import java.text.SimpleDateFormat;
import java.util.Date;
import net.sqlcipher.database.SQLiteDatabase;
import android.net.ParseException;
import android.os.Bundle;
import android.os.Environment;
import android.app.ActionBar;
import android.app.Activity;
import android.app.ActionBar.OnNavigationListener;
import android.content.Intent;
import android.database.Cursor;
import android.app.Fragment;
import android.util.DisplayMetrics;
import android.util.Log;
import android.util.TypedValue;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.WindowManager;
import android.widget.ArrayAdapter;
import android.widget.Toast;
public class Home extends Activity implements ICacheWordSubscriber {
private static final String TAG = Home.class.getSimpleName();
private Menu mainMenu;
// removed more definitions
private CacheWordActivityHandler mCacheWord;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SQLiteDatabase.loadLibs(this);
mCacheWord = new CacheWordActivityHandler(this, this);
}
#Override
protected void onPause() {
super.onPause();
mCacheWord.onPause();
Log.d(TAG,"onPause()");
}
#Override
protected void onResume() {
super.onStart();
mCacheWord.onResume();
Log.d(TAG,"onResume()");
}
private void closeDatabase()
{
Log.d(TAG,"closeDatabase()");
if (dbHandler != null) {
dbHandler.close();
dbHandler = null;
}
}
void showLockScreen() {
Log.d(TAG,"showLockScreen()");
Intent intent = new Intent(this, LockScreenActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.putExtra("originalIntent", getIntent());
startActivity(intent);
finish();
}
void lock() {
Log.d(TAG,"lock()");
closeDatabase();
System.gc();
showLockScreen();
}
private void unlockDatabase()
{
Log.d(TAG,"unlockDatabase()");
dbHandler = new TBOpenHandler(mCacheWord, this);
try
{
dbHandler.open();
} catch (Exception e)
{
e.printStackTrace();
Toast.makeText(this, getString(R.string.err_pass), Toast.LENGTH_LONG).show();
}
}
#Override
public void onCacheWordUninitialized() {
Log.d(TAG, "onCacheWordUninitialized()");
showLockScreen();
}
#Override
public void onCacheWordLocked() {
Log.d(TAG, "onCacheWordLocked()");
lock();
}
#Override
public void onCacheWordOpened() {
Log.d(TAG, "onCacheWordOpened()");
unlockDatabase();
if (dbHandler.isOpen()) {
inhalt();
}
}
private void inhalt() {
// removed the content
}
}
And there're the error messages:
10-09 22:57:38.009: E/ActivityThread(16122): Activity de.my.app.Home has leaked ServiceConnection info.guardianproject.cacheword.CacheWordHandler$2#41fe8738 that was originally bound here
10-09 22:57:38.009: E/ActivityThread(16122): android.app.ServiceConnectionLeaked: Activity de.my.app.Home has leaked ServiceConnection info.guardianproject.cacheword.CacheWordHandler$2#41fe8738 that was originally bound here
10-09 22:57:38.009: E/ActivityThread(16122): at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:974)
10-09 22:57:38.009: E/ActivityThread(16122): at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:868)
10-09 22:57:38.009: E/ActivityThread(16122): at android.app.ContextImpl.bindServiceAsUser(ContextImpl.java:1452)
10-09 22:57:38.009: E/ActivityThread(16122): at android.app.ContextImpl.bindService(ContextImpl.java:1440)
10-09 22:57:38.009: E/ActivityThread(16122): at android.content.ContextWrapper.bindService(ContextWrapper.java:496)
10-09 22:57:38.009: E/ActivityThread(16122): at info.guardianproject.cacheword.CacheWordHandler.connectToService(CacheWordHandler.java:74)
10-09 22:57:38.009: E/ActivityThread(16122): at info.guardianproject.cacheword.CacheWordActivityHandler.onResume(CacheWordActivityHandler.java:15)
10-09 22:57:38.009: E/ActivityThread(16122): at de.my.app.Home.onResume(Home.java:457)
10-09 22:57:38.009: E/ActivityThread(16122): at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1192)
10-09 22:57:38.009: E/ActivityThread(16122): at android.app.Activity.performResume(Activity.java:5211)
10-09 22:57:38.009: E/ActivityThread(16122): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2780)
10-09 22:57:38.009: E/ActivityThread(16122): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2819)
10-09 22:57:38.009: E/ActivityThread(16122): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2266)
10-09 22:57:38.009: E/ActivityThread(16122): at android.app.ActivityThread.access$600(ActivityThread.java:141)
10-09 22:57:38.009: E/ActivityThread(16122): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
10-09 22:57:38.009: E/ActivityThread(16122): at android.os.Handler.dispatchMessage(Handler.java:99)
10-09 22:57:38.009: E/ActivityThread(16122): at android.os.Looper.loop(Looper.java:137)
10-09 22:57:38.009: E/ActivityThread(16122): at android.app.ActivityThread.main(ActivityThread.java:5103)
10-09 22:57:38.009: E/ActivityThread(16122): at java.lang.reflect.Method.invokeNative(Native Method)
10-09 22:57:38.009: E/ActivityThread(16122): at java.lang.reflect.Method.invoke(Method.java:525)
10-09 22:57:38.009: E/ActivityThread(16122): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
10-09 22:57:38.009: E/ActivityThread(16122): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
10-09 22:57:38.009: E/ActivityThread(16122): at dalvik.system.NativeStart.main(Native Method)
Is there a way to fis this problem?

It's a bit late answer, but you never know.
I had the same problem, and it was, because I didn't have the correct service in AndroidManifest.
I mean, I had the service, but, when I did a refactor of the name package, eclipse changed the package of the service.
So take a look into the AndroidManifest, and be sure you have in this way:
<service
android:name="info.guardianproject.cacheword.CacheWordService"
android:enabled="true"
android:exported="false" />

Related

How to solve Nullpoint in android

This is the code in MainActivity
MainActivity.java:541
#Override
public void onSaveInstanceState (Bundle savedInstanceState) {
super.onSaveInstanceState(savedInstanceState);
savedInstanceState.putInt("mCurrentChapter", mCurrentChapter);
savedInstanceState.putInt("index", mPager.getCurrentItem());
////Log.e("SaveInstance", mCurrentChapter + " " + mPager.getCurrentItem());
}
I don't see any problem.
java.lang.NullPointerException
at com.techexpert4u.duaaadhkaar.MainActivity.onSaveInstanceState(MainActivity.java:541)
at android.app.Activity.performSaveInstanceState(Activity.java:1153)
at android.app.Instrumentation.callActivityOnSaveInstanceState(Instrumentation.java:1223)
at android.app.ActivityThread.performStopActivityInner(ActivityThread.java:3175)
at android.app.ActivityThread.handleStopActivity(ActivityThread.java:3234)
at android.app.ActivityThread.access$1100(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1223)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
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:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)

"java.lang.NullPointerException" Error when trying to insert data to sqlite (Android)

I face the error :
1566-1566/com.example.rom.romproject E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.rom.romproject, PID: 1566
java.lang.IllegalStateException: Could not execute method of the activity
at android.view.View$1.onClick(View.java:3823)
at android.view.View.performClick(View.java:4438)
at android.view.View$PerformClick.run(View.java:18422)
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:5017)
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:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at android.view.View$1.onClick(View.java:3818)
            at android.view.View.performClick(View.java:4438)
            at android.view.View$PerformClick.run(View.java:18422)
            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:5017)
            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:779)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
            at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.example.rom.romproject.ContactView.contactFavorite(ContactView.java:37)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at android.view.View$1.onClick(View.java:3818)
            at android.view.View.performClick(View.java:4438)
            at android.view.View$PerformClick.run(View.java:18422)
            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:5017)
            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:779)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
            at dalvik.system.NativeStart.main(Native Method)
This happens when im clicking on a button i created.
The button purpose is to insert Data into my sql table.
The SQL class :
public class sqlDatabaseAdapter
{
sqlHelper helper;
public sqlDatabaseAdapter(Context context)
{
helper = new sqlHelper(context);
}
public long insertData(String name, String phone)
{
SQLiteDatabase db = helper.getWritableDatabase();
ContentValues content = new ContentValues();
content.put(sqlHelper.NAME, name);
content.put(sqlHelper.PHONE, phone);
return db.insert(helper.TABLE_NAME, null, content);
}
static class sqlHelper extends SQLiteOpenHelper
{
static final String DATABASE_NAME = "ContactDB";
static final String TABLE_NAME = "Favorites";
static final int DB_VERSION = 1;
static final String UID = "_id";
static final String NAME = "Name";
static final String PHONE = "Phone";
static final String CREATE_TABLE = "CREATE TABLE "+ TABLE_NAME +" ("+UID+" INTEGER PRIMARY KEY AUTOINCREMENT, "+NAME+" VARCHAR(255), "+PHONE+" VARCHAR(255));";
static final String DROP_TABLE = "DROP TABLE IF EXISTS"+TABLE_NAME;
private Context context;
public sqlHelper(Context context)
{
super(context, DATABASE_NAME, null, DB_VERSION);
this.context = context;
Message.Message(context, "Constructor Called");
}
#Override
public void onCreate(SQLiteDatabase db)
{
try {
db.execSQL(CREATE_TABLE);
Message.Message(context, "onCreate Called");
} catch( SQLException e)
{
Message.Message(context, "" + e);
}
}
#Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
{
try {
db.execSQL(DROP_TABLE);
onCreate(db);
Message.Message(context, "OnUpgrade Called");
} catch(SQLException e)
{
Message.Message(context, "" + e);
}
}
}
}
Now, im not rly sure at the source of the problem , so i will post both of my activites.
Btw : the info im trying to insert to the SQL is a contact name and phone
(that i get from the main activity list view).
Main Activity ( List view of phone contacts ) :
public class MainActivity extends ListActivity {
ListView l;
Cursor cursor;
SimpleCursorAdapter listAdapter;
sqlDatabaseAdapter helper;
#Override
public int getSelectedItemPosition()
{
return super.getSelectedItemPosition();
}
#Override
public long getSelectedItemId()
{
return super.getSelectedItemId();
}
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
cursor = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, null);
startManagingCursor(cursor);
String[] from = {ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,ContactsContract.CommonDataKinds.Phone.NUMBER, ContactsContract.CommonDataKinds.Phone._ID};
int[] to = {android.R.id.text1,android.R.id.text2};
listAdapter = new SimpleCursorAdapter(this,android.R.layout.simple_list_item_2,cursor,from,to);
setListAdapter(listAdapter);
l = getListView();
l.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
helper = new sqlDatabaseAdapter(this);
helper.helper.getWritableDatabase();
}
#Override
protected void onListItemClick(ListView l, View v, int position, long id)
{
super.onListItemClick(l, v, position, id);
TextView _tempName= (TextView)v.findViewById(android.R.id.text1);
String _temp = _tempName.getText().toString();
TextView _tempPhone = (TextView)v.findViewById(android.R.id.text2);
String _temp2 = _tempPhone.getText().toString();
Intent intent = new Intent(this, ContactView.class);
intent.putExtra("contactName", _temp);
intent.putExtra("contactPhone", _temp2);
startActivity(intent);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
The second activity (where the button is ) :
public class ContactView extends ActionBarActivity {
Button _Call;
Button _Favorite;
FavoriteContact contact = new FavoriteContact();
sqlDatabaseAdapter helper;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_contact_view);
_Call = (Button)findViewById(R.id.bCall);
_Favorite = (Button)findViewById(R.id.bFavorite);
contact.setName(getIntent().getExtras().getString("contactName"));
contact.setPhone(getIntent().getExtras().getString("contactPhone"));
setTitle(contact.getName());
}
public void contactFavorite(View view)
{
long id = 0L;
id = helper.insertData(contact.getName(), contact.getPhone());
/*
if( id < 0)
{
Message.Message(this, "Unsuccessful");
}
else
{
Message.Message(this, "Successfully inserted to favorite contacts ");
}
*/
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_contact_view, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Contact class i created and FavoriteContact class :
(favoritecontact extends Contact)
public class Contact
{
private String Name = null;
private String Phone = null;
public String getPhone() {
return Phone;
}
public void setPhone(String phone) {
Phone = phone;
}
public String getName() {
return Name;
}
public void setName(String name) {
Name = name;
}
}
public class FavoriteContact extends Contact
{
private Boolean isFavorite;
public Boolean getIsFavorite() {
return isFavorite;
}
public void setIsFavorite(Boolean isFavorite) {
this.isFavorite = isFavorite;
}
}
i think i gave everything i need...
sorry for my bad english and its my first time posting here so i dont rly know how it works :D
thanks for every bit of help .
The variable helper is never initialized in ContactView.

Is it possible to create myown interface (with implementation) to extend neo4j GraphRepository?

I am trying to create an interface extends GraphRepository. Looks like this is impossible. The problem is when I run the smoke test, require a default constructor for CustomerGraphRepositoryImpl. Anybody can help? Thanks. Interface as following:
#NoRepositoryBean
public interface CustomerGraphRepository<T> extends GraphRepository<T> {
public T findNode(Long id);
}
Implementation:
#Repository
public class CustomerGraphRepositoryImpl<T> extends NodeGraphRepositoryImpl<T> implements CustomerGraphRepository<T>{
public CustomerGraphRepositoryImpl(Class<T> clazz, Neo4jTemplate template) {
super(clazz, template);
// TODO Auto-generated constructor stub
}
#Override
public T findNode(Long id) {
try {
return createEntity(getById(id));
} catch (DataRetrievalFailureException e) {
return null;
}
}
protected T createEntity(Node node){
try{
return template.createEntityFromStoredType(node, null);
}
catch(ClassCastException e){
return null;
}
}
}
The failure trace as follows:
java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:99)
at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:122)
at org.springframework.test.context.web.ServletTestExecutionListener.setUpRequestContextIfNecessary(ServletTestExecutionListener.java:105)
at org.springframework.test.context.web.ServletTestExecutionListener.prepareTestInstance(ServletTestExecutionListener.java:74)
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:312)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:211)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:288)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:284)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:88)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'customGraphRepositoryImpl' defined in file [pratice/dao/util/CustomGraphRepositoryImpl.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [pratice.dao.util.CustomGraphRepositoryImpl]: No default constructor found; nested exception is java.lang.NoSuchMethodException: pratice.dao.util.CustomGraphRepositoryImpl.<init>()
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1007)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:953)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:487)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:626)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:120)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60)
at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:100)
at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:248)
at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContextInternal(CacheAwareContextLoaderDelegate.java:64)
at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:91)
... 25 more
Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [pratice.dao.util.CustomGraphRepositoryImpl]: No default constructor found; nested exception is java.lang.NoSuchMethodException: pratice.dao.util.CustomGraphRepositoryImpl.<init>()
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:83)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1000)
... 41 more
Caused by: java.lang.NoSuchMethodException: pratice.dao.util.CustomGraphRepositoryImpl.<init>()
at java.lang.Class.getConstructor0(Class.java:2800)
at java.lang.Class.getDeclaredConstructor(Class.java:2043)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:78)
... 42 more

Problems with XmlPullParser code inside an AsyncTask (Activated By Button Click)

SO I have a program that I have been working on for a while. However, I am stuck on method that uses XmlPullParser, the method is called getAllXml(). It is inside of the doInBackGround() method of an AsyncTask. The AsyncTask is a subclass of an Activity called FormActivity. When I run the code.
Here is what the code is supposed to do. After the user selects "CloverField" from a previous activity. An xml file called cloverfield_in.xml is called by setContentView(). The user then presses a button on this same xml file. Clicking this button executes the AsyncTask called MadLIbAsyncTask. Within this AsyncTask this are only two methods, the doInBackground() and the onPostExecute(). (I don't know if I need onPreExecute()...within which I would have have a progress bar....but without this method I figure the program shouldn't crash the way it does).
Within the doInBackground() method, I am calling the method called getAllXml(). This method uses XmlPullParser to search through the current xml (cloverfield_in.xml) and capture text from a single TextView. The code for getAllXml() is as follows.
public void getAllXml() throws XmlPullParserException, IOException{
Activity activity = this;
Resources res = activity.getResources();
XmlResourceParser xpp = res.getXml(R.layout.cloverfield_in);
int eventtype = xpp.getEventType();
while (eventtype != XmlPullParser.END_DOCUMENT){
if (eventtype == XmlPullParser.START_DOCUMENT){
}
else if (eventtype == XmlPullParser.START_TAG){
if (xpp.getName() == "TextView"){
while (eventtype != XmlPullParser.END_TAG){
if (eventtype == XmlPullParser.TEXT){
stringViews[0] = xpp.getText();
}else {}
eventtype = xpp.next();
}
}else {}
}
else if (eventtype == XmlPullParser.END_TAG){
}
else if (eventtype == XmlPullParser.TEXT){
}
eventtype = xpp.next();
}
}
When in the process of debugging, my program often returns a NullPointerException or a RunTimeException. I believe within this code is where the problem resides. I tested the AsyncTask without the existence of the getAllXml() method and everything works fine. Eventually the program is supposed to take the text gathered from the cloverfield_in.xml file and display it in a new file called cloverfield_out.xml.
For a complete review of everything, here is the entire code for FormActivity.class.
package com.muirconsult.mymadlibs;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.content.res.XmlResourceParser;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.Layout;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AutoCompleteTextView;
import android.widget.TextView;
public class FormActivity extends Activity{
String [] textFields;
String Choice;
int thisLayout;
View thatLayout ;
String[] stringViews;
ViewGroup anskey;
Activity activity = this;
String test;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent objIntent = getIntent();
Choice = objIntent.getStringExtra("selection");
if (Choice.equals("Cloverfield")) {
setContentView(R.layout.cloverfield_in);
thisLayout = (R.layout.cloverfield_in);
thatLayout = (View)findViewById(R.layout.cloverfield_out);
}
if (Choice.equals("Fargo")) {
setContentView(R.layout.fargo_in);
}
if(Choice.equals("Ying Yang In This Thang (Ying Yang Twins)")){
setContentView(R.layout.ying_yang_twins_in_this_thang_in);
}
}
public void getAllXml() throws XmlPullParserException, IOException{
Activity activity = this;
Resources res = activity.getResources();
XmlResourceParser xpp = res.getXml(R.layout.cloverfield_in);
int eventtype = xpp.getEventType();
while (eventtype != XmlPullParser.END_DOCUMENT){
if (eventtype == XmlPullParser.START_DOCUMENT){
}
else if (eventtype == XmlPullParser.START_TAG){
if (xpp.getName() == "TextView"){
while (eventtype != XmlPullParser.END_TAG){
if (eventtype == XmlPullParser.TEXT){
stringViews[0] = xpp.getText();
}else {}
eventtype = xpp.next();
}
}else {}
}
else if (eventtype == XmlPullParser.END_TAG){
}
else if (eventtype == XmlPullParser.TEXT){
}
eventtype = xpp.next();
}
}
class MadLibAsyncTask extends AsyncTask<Void, Void, Void>{
String testString;
int thisLayout;
protected Void doInBackground(Void... params) {
try{
getAllXml();
}catch (XmlPullParserException e){
e.printStackTrace();
}catch (IOException e){
e.printStackTrace();
}
return null;
}
protected void onPostExecute (Void result){
String str = "let's go to the park";
String newstr;
setContentView(R.layout.cloverfield_out);
TextView outview = (TextView)findViewById(R.id.outview);
str = (String) outview.getText();
newstr = str.replaceFirst("film",stringViews[0]);
outview.setText(newstr);
}
}
public void onClick(View view) {
MadLibAsyncTask mad = new MadLibAsyncTask();
mad.execute();
}
}
Also, most importantly...the logcat looks as such:
08-10 23:04:50.064: W/dalvikvm(1415): threadid=1: thread exiting with uncaught exception >>> (group=0x40a71930)
08-10 23:04:50.145: E/AndroidRuntime(1415): FATAL EXCEPTION: main
08-10 23:04:50.145: E/AndroidRuntime(1415): java.lang.NullPointerException
08-10 23:04:50.145: E/AndroidRuntime(1415): at java.util.regex.Matcher.appendEvaluated>(Matcher.java:130)
08-10 23:04:50.145: E/AndroidRuntime(1415): at java.util.regex.Matcher.appendReplacement(Matcher.java:110)
08-10 23:04:50.145: E/AndroidRuntime(1415): at java.util.regex.Matcher.replaceFirst(Matcher.java:299)
08-10 23:04:50.145: E/AndroidRuntime(1415): at java.lang.String.replaceFirst(String.java:1793)
08-10 23:04:50.145: E/AndroidRuntime(1415): at com.muirconsult.mymadlibs.FormActivity$MadLibAsyncTask.onPostExecute(FormActivity.java:116)
08-10 23:04:50.145: E/AndroidRuntime(1415): at com.muirconsult.mymadlibs.FormActivity$MadLibAsyncTask.onPostExecute(FormActivity.java:1)
08-10 23:04:50.145: E/AndroidRuntime(1415): at android.os.AsyncTask.finish(AsyncTask.java:631)
08-10 23:04:50.145: E/AndroidRuntime(1415): at android.os.AsyncTask.access$600>\ (AsyncTask.java:177)
08-10 23:04:50.145: E/AndroidRuntime(1415): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
08-10 23:04:50.145: E/AndroidRuntime(1415): at android.os.Handler.dispatchMessage(Handler.java:99)
08-10 23:04:50.145: E/AndroidRuntime(1415): at android.os.Looper.loop(Looper.java:137)
08-10 23:04:50.145: E/AndroidRuntime(1415): at android.app.ActivityThread.main(ActivityThread.java:5041)
08-10 23:04:50.145: E/AndroidRuntime(1415): at java.lang.reflect.Method.invokeNative(Native Method)
08-10 23:04:50.145: E/AndroidRuntime(1415): at java.lang.reflect.Method.invoke(Method.java:511)
08-10 23:04:50.145: E/AndroidRuntime(1415): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
08-10 23:04:50.145: E/AndroidRuntime(1415): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
08-10 23:04:50.145: E/AndroidRuntime(1415): at dalvik.system.NativeStart.main(Native Method)

GWT Uncaught exception escaped

I have created a new google application using GWT, and it runs fine. But when i click a button that is responsible for performing some action with the server side, it throws an unusual error. Please could someone offer some help? Thank you in advance :(
Here is the code:
package com.ukstudentfeedback.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.ukstudentfeedback.shared.FieldVerifier;
import com.ukstudentfeedback.client.MailClient;
import com.ukstudentfeedback.client.MailClientAsync;
public class Ukstudentfeedback implements EntryPoint{
private static final String SERVER_ERROR = "An error occurred while "
+ "attempting to contact the server. Please check your network "
+ "connection and try again.";
/**
* Create a remote service proxy to talk to the server-side Greeting service.
*/
private final MailClientAsync sendMessage = GWT
.create(MailClient.class);
// ...
public void onModuleLoad()
{
java.lang.System.out.println("I finally worked!");
final Button sendButton;
final TextBox toField, fromField, subjectField, messageField;
final Label errorLabel = new Label();
sendButton = new Button("Send");
toField = new TextBox();
fromField = new TextBox();
subjectField = new TextBox();
messageField = new TextBox();
sendButton.addStyleName("sendButton");
toField.setText("Testing");
// Add the nameField and sendButton to the RootPanel
// Use RootPanel.get() to get the entire body element
RootPanel.get("sendButton").add(sendButton);
RootPanel.get("To").add(toField);
RootPanel.get("From").add(fromField);
RootPanel.get("Subject").add(subjectField);
RootPanel.get("Message").add(messageField);
RootPanel.get("errorLabelContainer").add(errorLabel);
// Focus the cursor on the to field when the app loads
toField.setFocus(true);
toField.selectAll();
//sendButton.setEnabled(true);
// Create the popup dialog box
final DialogBox dialogBox = new DialogBox();
dialogBox.setText("Message Sent");
dialogBox.setAnimationEnabled(true);
final Button closeButton = new Button("Close");
// We can set the id of a widget by accessing its Element
closeButton.getElement().setId("closeButton");
final Label textToServerLabel = new Label();
final HTML serverResponseLabel = new HTML();
VerticalPanel dialogVPanel = new VerticalPanel();
dialogVPanel.addStyleName("dialogVPanel");
dialogVPanel.add(new HTML("<b>Message Sent:</b>"));
dialogVPanel.add(textToServerLabel);
dialogVPanel.add(new HTML("<br><b>Server replies:</b>"));
dialogVPanel.add(serverResponseLabel);
dialogVPanel.setHorizontalAlignment(VerticalPanel.ALIGN_RIGHT);
dialogVPanel.add(closeButton);
dialogBox.setWidget(dialogVPanel);
// Add a handler to close the DialogBox
closeButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
dialogBox.hide();
sendButton.setEnabled(true);
sendButton.setFocus(true);
}
});
// Create a handler for the sendButton and nameField
class MyHandler implements ClickHandler{
/**
* Fired when the user clicks on the sendButton.
*/
public void onClick(ClickEvent event) {
java.lang.System.out.println("I have been clicked");
sendMessageToServer();
}
public void sendMessageToServer()
{
errorLabel.setText("");
String to = toField.getText();
String from = fromField.getText();
String subject = subjectField.getText();
String message = messageField.getText();
if (!FieldVerifier.isValidName(to, from, subject, message)) {
errorLabel.setText("Please enter at least four characters");
return;
}
sendButton.setEnabled(false);
textToServerLabel.setText("Hello");
serverResponseLabel.setText("");
sendMessage.sendMessage(to, from, subject, message, new AsyncCallback<String>() {
public void onFailure(Throwable caught) {
// Show the RPC error message to the user
dialogBox
.setText("Message sending Failed");
serverResponseLabel
.addStyleName("serverResponseLabelError");
serverResponseLabel.setHTML(SERVER_ERROR);
dialogBox.center();
closeButton.setFocus(true);
}
public void onSuccess(String result) {
dialogBox.setText("Message Sent");
serverResponseLabel
.removeStyleName("serverResponseLabelError");
serverResponseLabel.setHTML(result);
dialogBox.center();
closeButton.setFocus(true);
}
});
}
}
// Add a handler to send the name to the server
MyHandler handler = new MyHandler();
sendButton.addClickHandler(handler);
}
}
Server side:
package com.ukstudentfeedback.server;
import java.io.UnsupportedEncodingException;
import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.ukstudentfeedback.shared.FieldVerifier;
#SuppressWarnings("serial")
public class MailServerImpl extends RemoteServiceServlet{
public void sendMessage(String to, String from, String subject, String message) throws IllegalArgumentException
{
// Verify that no input is null.
if (!FieldVerifier.isValidName(to, from, subject, message)) {
// If the input is not valid, throw an IllegalArgumentException back to
// the client.
throw new IllegalArgumentException(
"Name must be at least 4 characters long");
}
Properties props = new Properties();
Session session = Session.getDefaultInstance(props, null);
try
{
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(from, "Admin"));
msg.addRecipient(Message.RecipientType.TO,
new InternetAddress(to, "Mr. User"));
msg.setSubject(subject);
msg.setText(message);
Transport.send(msg);
}
catch (AddressException e)
{
// ...
e.printStackTrace();
} catch (MessagingException e)
{
// ...
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Error Stack:
23:26:55.817 [ERROR] [ukstudentfeedback] Uncaught exception escaped
com.google.gwt.event.shared.UmbrellaException: One or more exceptions caught, see full set in UmbrellaException#getCauses
at com.google.gwt.event.shared.HandlerManager.fireEvent(HandlerManager.java:129)
at com.google.gwt.user.client.ui.Widget.fireEvent(Widget.java:129)
at com.google.gwt.event.dom.client.DomEvent.fireNativeEvent(DomEvent.java:116)
at com.google.gwt.user.client.ui.Widget.onBrowserEvent(Widget.java:177)
at com.google.gwt.user.client.DOM.dispatchEventImpl(DOM.java:1351)
at com.google.gwt.user.client.DOM.dispatchEvent(DOM.java:1307)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:337)
at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:218)
at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561)
at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:269)
at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
at com.google.gwt.core.client.impl.Impl.apply(Impl.java)
at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:213)
at sun.reflect.GeneratedMethodAccessor27.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:292)
at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:546)
at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:363)
at java.lang.Thread.run(Thread.java:680)
Caused by: com.google.gwt.user.client.rpc.ServiceDefTarget$NoServiceEntryPointSpecifiedException: Service implementation URL not specified
at com.google.gwt.user.client.rpc.impl.RemoteServiceProxy.doPrepareRequestBuilderImpl(RemoteServiceProxy.java:430)
at com.google.gwt.user.client.rpc.impl.RemoteServiceProxy.doInvoke(RemoteServiceProxy.java:368)
at com.google.gwt.user.client.rpc.impl.RemoteServiceProxy$ServiceHelper.finish(RemoteServiceProxy.java:74)
at com.ukstudentfeedback.client.MailClient_Proxy.sendMessage(MailClient_Proxy.java:38)
at com.ukstudentfeedback.client.Ukstudentfeedback$1MyHandler.sendMessageToServer(Ukstudentfeedback.java:118)
at com.ukstudentfeedback.client.Ukstudentfeedback$1MyHandler.onClick(Ukstudentfeedback.java:98)
at com.google.gwt.event.dom.client.ClickEvent.dispatch(ClickEvent.java:54)
at com.google.gwt.event.dom.client.ClickEvent.dispatch(ClickEvent.java:1)
at com.google.gwt.event.shared.GwtEvent.dispatch(GwtEvent.java:1)
at com.google.web.bindery.event.shared.EventBus.dispatchEvent(EventBus.java:40)
at com.google.web.bindery.event.shared.SimpleEventBus.doFire(SimpleEventBus.java:193)
at com.google.web.bindery.event.shared.SimpleEventBus.fireEvent(SimpleEventBus.java:88)
at com.google.gwt.event.shared.HandlerManager.fireEvent(HandlerManager.java:127)
at com.google.gwt.user.client.ui.Widget.fireEvent(Widget.java:129)
at com.google.gwt.event.dom.client.DomEvent.fireNativeEvent(DomEvent.java:116)
at com.google.gwt.user.client.ui.Widget.onBrowserEvent(Widget.java:177)
at com.google.gwt.user.client.DOM.dispatchEventImpl(DOM.java:1351)
at com.google.gwt.user.client.DOM.dispatchEvent(DOM.java:1307)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:337)
at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:218)
at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561)
at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:269)
at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
at com.google.gwt.core.client.impl.Impl.apply(Impl.java)
at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:213)
at sun.reflect.GeneratedMethodAccessor27.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:292)
at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:546)
at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:363)
at java.lang.Thread.run(Thread.java:680)
To find the cause of an UmbrellaException look for "Caused by":
Caused by:
com.google.gwt.user.client.rpc.ServiceDefTarget$NoServiceEntryPointSpecifiedException:
Service implementation URL not specified
Specify the remote service URL by doing either of the following:
Adding a RemoteServiceRelativePath annotation to your MailClientAsync interface.
Calling ServiceDefTarget#setServiceEntryPoint:
((ServiceDefTarget)sendMessage).
setServiceEntryPoint("http://www.example.com/service");