MediaPlayer+SurfaceView app fails - surfaceview

Uploaded an example from /samples/android-16 >/ApiDemos.
There's a few examples in a single project.
Extracted from there one-MediaPlayerDemo_Video, like so:
Mediaplayer_video.java
package com.example.mediaplayer_video;
import android.app.Activity;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnBufferingUpdateListener;
import android.media.MediaPlayer.OnCompletionListener;
import android.media.MediaPlayer.OnPreparedListener;
import android.media.MediaPlayer.OnVideoSizeChangedListener;
import android.os.Bundle;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.widget.Toast;
public class Mediaplayer_video extends Activity implements
OnBufferingUpdateListener, OnCompletionListener,
OnPreparedListener, OnVideoSizeChangedListener, SurfaceHolder.Callback {
private static final String TAG = "MediaPlayerVideo";
private int mVideoWidth;
private int mVideoHeight;
private MediaPlayer mMediaPlayer;
private SurfaceView mPreview;
private SurfaceHolder holder;
private String path;
private Bundle extras;
private static final String MEDIA = "media";
private boolean mIsVideoSizeKnown = false;
private boolean mIsVideoReadyToBePlayed = false;
/**
*
* Called when the activity is first created.
*/
#SuppressWarnings("deprecation")
#Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.mediaplayer_2);
mPreview = (SurfaceView) findViewById(R.id.surface);
holder = mPreview.getHolder();
holder.addCallback(this);
holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
extras = getIntent().getExtras();
}
private void playVideo(Integer Media) {
doCleanUp();
try {
path = "sdcard/scheen.mp4";
if (path == "") {
// Tell the user to provide a media file URL.
Toast
.makeText(
Mediaplayer_video.this,
"Please edit Mediaplayer_Video Activity, "
+ "and set the path variable to your media file path."
+ " Your media file must be stored on sdcard.",
Toast.LENGTH_LONG).show();
}
// Create a new media player and set the listeners
mMediaPlayer = new MediaPlayer();
mMediaPlayer.setDataSource(path);
mMediaPlayer.setDisplay(holder);
mMediaPlayer.prepare();
mMediaPlayer.setOnBufferingUpdateListener(this);
mMediaPlayer.setOnCompletionListener(this);
mMediaPlayer.setOnPreparedListener(this);
mMediaPlayer.setOnVideoSizeChangedListener(this);
mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
} catch (Exception e) {
Log.e(TAG, "error: " + e.getMessage(), e);
}
}
public void onBufferingUpdate(MediaPlayer arg0, int percent) {
Log.d(TAG, "onBufferingUpdate percent:" + percent);
}
public void onCompletion(MediaPlayer arg0) {
Log.d(TAG, "onCompletion called");
}
public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
Log.v(TAG, "onVideoSizeChanged called");
if (width == 0 || height == 0) {
Log.e(TAG, "invalid video width(" + width + ") or height(" + height + ")");
return;
}
mIsVideoSizeKnown = true;
mVideoWidth = width;
mVideoHeight = height;
if (mIsVideoReadyToBePlayed && mIsVideoSizeKnown) {
startVideoPlayback();
}
}
public void onPrepared(MediaPlayer mediaplayer) {
Log.d(TAG, "onPrepared called");
mIsVideoReadyToBePlayed = true;
if (mIsVideoReadyToBePlayed && mIsVideoSizeKnown) {
startVideoPlayback();
}
}
public void surfaceChanged(SurfaceHolder surfaceholder, int i, int j, int k) {
Log.d(TAG, "surfaceChanged called");
}
public void surfaceDestroyed(SurfaceHolder surfaceholder) {
Log.d(TAG, "surfaceDestroyed called");
}
public void surfaceCreated(SurfaceHolder holder) {
Log.d(TAG, "surfaceCreated called");
playVideo(extras.getInt(MEDIA));
}
#Override
protected void onPause() {
super.onPause();
releaseMediaPlayer();
doCleanUp();
}
#Override
protected void onDestroy() {
super.onDestroy();
releaseMediaPlayer();
doCleanUp();
}
private void releaseMediaPlayer() {
if (mMediaPlayer != null) {
mMediaPlayer.release();
mMediaPlayer = null;
}
}
private void doCleanUp() {
mVideoWidth = 0;
mVideoHeight = 0;
mIsVideoReadyToBePlayed = false;
mIsVideoSizeKnown = false;
}
private void startVideoPlayback() {
Log.v(TAG, "startVideoPlayback");
holder.setFixedSize(mVideoWidth, mVideoHeight);
mMediaPlayer.start();
}
}
mediaplayer_2.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:orientation="vertical"
tools:context=".Mediaplayer_video" >
<SurfaceView
android:id="#+id/surface"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" >
</SurfaceView>
</LinearLayout>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mediaplayer_video"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="16" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.mediaplayer_video.Mediaplayer_video"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Falls with this logo:
07-20 17:54:04.597: E/Trace(5713): error opening trace file: No such file or directory (2)
07-20 17:54:07.006: D/MediaPlayerVideo(5713): surfaceCreated called
07-20 17:54:07.106: D/AndroidRuntime(5713): Shutting down VM
07-20 17:54:07.106: W/dalvikvm(5713): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
07-20 17:54:07.236: E/AndroidRuntime(5713): FATAL EXCEPTION: main
07-20 17:54:07.236: E/AndroidRuntime(5713): java.lang.NullPointerException
07-20 17:54:07.236: E/AndroidRuntime(5713): at com.example.mediaplayer_video.Mediaplayer_video.surfaceCreated(Mediaplayer_video.java:128)
07-20 17:54:07.236: E/AndroidRuntime(5713): at android.view.SurfaceView.updateWindow(SurfaceView.java:543)
07-20 17:54:07.236: E/AndroidRuntime(5713): at android.view.SurfaceView.access$000(SurfaceView.java:81)
07-20 17:54:07.236: E/AndroidRuntime(5713): at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:169)
07-20 17:54:07.236: E/AndroidRuntime(5713): at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:671)
07-20 17:54:07.236: E/AndroidRuntime(5713): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1820)
07-20 17:54:07.236: E/AndroidRuntime(5713): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1000)
07-20 17:54:07.236: E/AndroidRuntime(5713): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4214)
07-20 17:54:07.236: E/AndroidRuntime(5713): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
07-20 17:54:07.236: E/AndroidRuntime(5713): at android.view.Choreographer.doCallbacks(Choreographer.java:555)
07-20 17:54:07.236: E/AndroidRuntime(5713): at android.view.Choreographer.doFrame(Choreographer.java:525)
07-20 17:54:07.236: E/AndroidRuntime(5713): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
07-20 17:54:07.236: E/AndroidRuntime(5713): at android.os.Handler.handleCallback(Handler.java:615)
07-20 17:54:07.236: E/AndroidRuntime(5713): at android.os.Handler.dispatchMessage(Handler.java:92)
07-20 17:54:07.236: E/AndroidRuntime(5713): at android.os.Looper.loop(Looper.java:137)
07-20 17:54:07.236: E/AndroidRuntime(5713): at android.app.ActivityThread.main(ActivityThread.java:4745)
07-20 17:54:07.236: E/AndroidRuntime(5713): at java.lang.reflect.Method.invokeNative(Native Method)
07-20 17:54:07.236: E/AndroidRuntime(5713): at java.lang.reflect.Method.invoke(Method.java:511)
07-20 17:54:07.236: E/AndroidRuntime(5713): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
07-20 17:54:07.236: E/AndroidRuntime(5713): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
07-20 17:54:07.236: E/AndroidRuntime(5713): at dalvik.system.NativeStart.main(Native Method)
There are thoughts, what's up?

I found out what was my mistake.
The log indicates the line 128:
07-20 17:54:07.236: E/AndroidRuntime(5713): java.lang.NullPointerException
07-20 17:54:07.236: E/AndroidRuntime(5713): at com.example.mediaplayer_video.Mediaplayer_video.surfaceCreated(Mediaplayer_video.java:128)
At line 128 Mediaplayer_video.java this:
public void surfaceCreated(SurfaceHolder holder) {
Log.d(TAG, "surfaceCreated called");
playVideo(extras.getInt(MEDIA));
PlayVideo() method defined as playVideo(Integer Media), and Media = null.
Fixed the playVideo(Integer Media) and playVideo(extras.getInt(MEDIA)) on playVideo() and everything earned.

Related

"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.

Google Glass Camera: setPreviewCallback

I have an operating android app that utilizes preview callbacks, to process the image after every frame from the preview (the preview is paused for a minute while the calculations take place). It works great! But, now I am trying to get Google Glass to do the same thing: activate Preview, activate preview callback, activating the calculations.
This issue likely has to do with how Camera is defined:
Camera mCamera = null;
but, I cannot define it as Camera.open(); with Google Glass because it fails. Thus when i get to defining the callback, I'm told it may produce a NullPointerException, and indeed I get the following error string:
Process: com.ead.glasscam.app, PID: 14231
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ead.glasscam.app/com.ead.glasscam.app.MainActivity}:
java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2235)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2285)
at android.app.ActivityThread.access$800(ActivityThread.java:138)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1236)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:149)
at android.app.ActivityThread.main(ActivityThread.java:5061)
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:794)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:610)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.ead.glasscam.app.MainActivity.onCreate(MainActivity.java:100)
at android.app.Activity.performCreate(Activity.java:5236)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1089)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2199)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2285)
            at android.app.ActivityThread.access$800(ActivityThread.java:138)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1236)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:149)
            at android.app.ActivityThread.main(ActivityThread.java:5061)
            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:794)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:610)
            at dalvik.system.NativeStart.main(Native Method)
So, the code:
// Attach a callback for preview
mPreviewCallback camCallback = new mPreviewCallback();
mCamera.setPreviewCallback(camCallback);
What is mPreviewCallback?:
public class mPreviewCallback implements Camera.PreviewCallback {
public void onPreviewFrame(byte[] data, final Camera camera){
Log.i("CAMERA", "Triggered Preview Frame");
}
}
I really don't understand how to do this simple process on Android, with Google Glass. Thank you for reading.
Checkout this example from jaredsburrows, it uses the camera preview on Glass and I used it in a project once (It Works! ;) )
https://github.com/jaredsburrows/OpenQuartz/tree/master/example-apps/OG_CameraApp
public class CameraView extends SurfaceView implements SurfaceHolder.Callback
{
private SurfaceHolder surfaceHolder = null;
private Camera camera = null;
#SuppressWarnings("deprecation")
public CameraView(Context context)
{
super(context);
surfaceHolder = this.getHolder();
surfaceHolder.addCallback(this);
surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}
/*
* (non-Javadoc)
* #see android.view.SurfaceHolder.Callback#surfaceCreated(android.view.SurfaceHolder)
*/
#Override
public void surfaceCreated(SurfaceHolder holder)
{
camera = Camera.open();
// Set the Hotfix for Google Glass
this.setCameraParameters(camera);
// Show the Camera display
try
{
camera.setPreviewDisplay(holder);
}
catch (Exception e)
{
this.releaseCamera();
}
}
/*
* (non-Javadoc)
* #see android.view.SurfaceHolder.Callback#surfaceChanged(android.view.SurfaceHolder, int, int, int)
*/
#Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height)
{
// Start the preview for surfaceChanged
if (camera != null)
{
camera.startPreview();
}
}
/*
* (non-Javadoc)
* #see android.view.SurfaceHolder.Callback#surfaceDestroyed(android.view.SurfaceHolder)
*/
#Override
public void surfaceDestroyed(SurfaceHolder holder)
{
// Do not hold the camera during surfaceDestroyed - view should be gone
this.releaseCamera();
}
/**
* Important HotFix for Google Glass (post-XE11) update
* #param camera Object
*/
public void setCameraParameters(Camera camera)
{
if (camera != null)
{
Parameters parameters = camera.getParameters();
parameters.setPreviewFpsRange(30000, 30000);
camera.setParameters(parameters);
}
}
/**
* Release the camera from use
*/
public void releaseCamera()
{
if (camera != null)
{
camera.release();
camera = null;
}
}
}

Android: java.lang.nullPointerException at custom ListView adapter

I'm trying to make a custom view for my ListView, but the app crash when try to open it. I read a lot of pages but don't find the solution. Please help me!
This is my custom Adapter:
public class AdaptadorCatalogo extends BaseAdapter {
protected Activity activity;
protected ArrayList<LineaCatalogo> items;
public AdaptadorCatalogo(Activity activity, ArrayList<LineaCatalogo> items) {
this.activity = activity;
this.items = items;
}
#Override
public int getCount() {
return items.size();
}
#Override
public Object getItem(int position) {
return items.get(position);
}
#Override
public long getItemId(int position){
return 0;
}
#Override
public View getView(int position, View contentView, ViewGroup parent) {
View vi=contentView;
if(contentView == null) {
LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
vi = inflater.inflate(R.layout.listitem_catalogo, null);
}
LineaCatalogo item = items.get(position);
TextView primeraLinea = (TextView) vi.findViewById(R.id.lblPrimeraLinea);
primeraLinea.setText(item.getPrimeraLinea());
TextView segundaLinea = (TextView) vi.findViewById(R.id.lblSegundaLinea);
segundaLinea.setText(item.getSegundaLinea());
TextView magnitud = (TextView) vi.findViewById(R.id.lblMagnitud);
magnitud.setText(item.getMagnitud());
return vi;
}
}
This is my 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=".listaSismos" >
<RelativeLayout
android:id="#+id/general"
style="#style/AppCentral"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="50dp" >
<TextView
android:id="#+id/titulo_catalogo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30sp"
android:text="#string/esperando_info" />
<ListView
android:id="#+id/listaDatos"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginBottom="50dp"
android:layout_marginTop="50dp"
android:layout_marginLeft="30dp" />
</RelativeLayout>
</RelativeLayout>
This is my Activity:
public class listaSismos extends Activity {
private TextView tituloCatalogo;
private ListView listaDatos;
private String opcion;
private String codigoUsuario;
private String latitud;
private String longitud;
private String idioma;
private int difHoraria;
private ArrayList<LineaCatalogo> Catalogo;
#Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.lista_sismos);
tituloCatalogo = (TextView)findViewById(R.id.titulo_catalogo);
listaDatos = (ListView)findViewById(R.id.listaDatos);
Bundle bundle = getIntent().getExtras();
opcion = bundle.getString("lista");
codigoUsuario = bundle.getString("codigoUsuario");
latitud = bundle.getString("latitud");
longitud = bundle.getString("longitud");
idioma = getResources().getConfiguration().locale.toString();
TimeZone defaultTZ = TimeZone.getDefault();
difHoraria = defaultTZ.getRawOffset() / 1000;
ListarCatalogo conexion = new ListarCatalogo();
conexion.execute();
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
private class ListarCatalogo extends AsyncTask<String,Integer,Boolean> {
private int contador;
protected Boolean doInBackground(String... params) {
boolean resul = true;
HttpClient httpClient = new DefaultHttpClient();
HttpGet del =
new HttpGet(my_app_server_url);
del.setHeader("content-type", "application/json");
try
{
HttpResponse resp = httpClient.execute(del);
String respStr = EntityUtils.toString(resp.getEntity());
JSONArray respJSON = new JSONArray(respStr);
ArrayList<LineaCatalogo> Catalogo = new ArrayList<LineaCatalogo>();
contador = respJSON.length();
for(int cont=0; cont<contador; cont++)
{
JSONObject obj = respJSON.getJSONObject(cont);
String tituloS = obj.getString("P");
String subtituloS = obj.getString("S");
String magnitudS = obj.getString("M");
Catalogo.add(new LineaCatalogo(tituloS, subtituloS, magnitudS));
}
}
catch(Exception ex)
{
resul = false;
}
return resul;
}
protected void onPostExecute(Boolean result) {
tituloCatalogo.setText(R.string.titulo_catalogo);
if (result)
{
//Rellenamos la lista con los resultados
AdaptadorCatalogo adaptador = new AdaptadorCatalogo(listaSismos.this, Catalogo);
listaDatos.setAdapter(adaptador);
tituloCatalogo.setText("OK");
} else {
tituloCatalogo.setText(R.string.no_datos);
}
}
}
}
If i comment the line "listaDatos.setAdapter(adaptador);", the app runs ok. If not, i get this LogCat:
12-06 09:34:32.443: W/dalvikvm(903): threadid=1: thread exiting with uncaught exception (group=0x41465700)
12-06 09:34:32.559: E/AndroidRuntime(903): FATAL EXCEPTION: main
12-06 09:34:32.559: E/AndroidRuntime(903): java.lang.NullPointerException
12-06 09:34:32.559: E/AndroidRuntime(903): at com.tapsistemas.avcanquake.AdaptadorCatalogo.getCount(AdaptadorCatalogo.java:23)
12-06 09:34:32.559: E/AndroidRuntime(903): at android.widget.ListView.setAdapter(ListView.java:463)
12-06 09:34:32.559: E/AndroidRuntime(903): at com.tapsistemas.avcanquake.listaSismos$ListarCatalogo.onPostExecute(listaSismos.java:124)
12-06 09:34:32.559: E/AndroidRuntime(903): at com.tapsistemas.avcanquake.listaSismos$ListarCatalogo.onPostExecute(listaSismos.java:1)
12-06 09:34:32.559: E/AndroidRuntime(903): at android.os.AsyncTask.finish(AsyncTask.java:631)
12-06 09:34:32.559: E/AndroidRuntime(903): at android.os.AsyncTask.access$600(AsyncTask.java:177)
12-06 09:34:32.559: E/AndroidRuntime(903): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
12-06 09:34:32.559: E/AndroidRuntime(903): at android.os.Handler.dispatchMessage(Handler.java:99)
12-06 09:34:32.559: E/AndroidRuntime(903): at android.os.Looper.loop(Looper.java:137)
12-06 09:34:32.559: E/AndroidRuntime(903): at android.app.ActivityThread.main(ActivityThread.java:5103)
12-06 09:34:32.559: E/AndroidRuntime(903): at java.lang.reflect.Method.invokeNative(Native Method)
12-06 09:34:32.559: E/AndroidRuntime(903): at java.lang.reflect.Method.invoke(Method.java:525)
12-06 09:34:32.559: E/AndroidRuntime(903): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
12-06 09:34:32.559: E/AndroidRuntime(903): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
12-06 09:34:32.559: E/AndroidRuntime(903): at dalvik.system.NativeStart.main(Native Method)
I still working a week looking for the solution, but i can't do it. Please, help me. And sorry by my poor english, i'm spanish from Canary Islands.
Declare and initialize like
private ArrayList<LineaCatalogo> Catalogo= new ArrayList<LineaCatalogo>();
#Override
public void onCreate(Bundle savedInstanceState){
Remove
ArrayList<LineaCatalogo> Catalogo = new ArrayList<LineaCatalogo>();
// becomes local to doInbackground as it is declared and initialized there.
in doInbackground.
In your case Catalogo was null.
You redefine your list with
ArrayList<LineaCatalogo> Catalogo = new ArrayList<LineaCatalogo>();
in the doInBacground
use just
Catalogo = new ArrayList<LineaCatalogo>();

How to avoid java.lang.IllegalStateException: Could not execute method of the activity

In My project I am interacting with data bases, I has a button when pressed adds three items from three different edittexts such as name(string), idcardno(int of maximum 4nos), phoneno(int of max 10nos). On pressing Add button it makes exeception as below..
09-19 01:28:31.491: E/AndroidRuntime(1160): FATAL EXCEPTION: main
09-19 01:28:31.491: E/AndroidRuntime(1160): java.lang.IllegalStateException: Could not execute method of the activity
09-19 01:28:31.491: E/AndroidRuntime(1160): at android.view.View$1.onClick(View.java:3633)
09-19 01:28:31.491: E/AndroidRuntime(1160): at android.view.View.performClick(View.java:4240)
09-19 01:28:31.491: E/AndroidRuntime(1160): at android.view.View$PerformClick.run(View.java:17721)
09-19 01:28:31.491: E/AndroidRuntime(1160): at android.os.Handler.handleCallback(Handler.java:730)
09-19 01:28:31.491: E/AndroidRuntime(1160): at android.os.Handler.dispatchMessage(Handler.java:92)
09-19 01:28:31.491: E/AndroidRuntime(1160): at android.os.Looper.loop(Looper.java:137)
09-19 01:28:31.491: E/AndroidRuntime(1160): at android.app.ActivityThread.main(ActivityThread.java:5103)
09-19 01:28:31.491: E/AndroidRuntime(1160): at java.lang.reflect.Method.invokeNative(Native Method)
09-19 01:28:31.491: E/AndroidRuntime(1160): at java.lang.reflect.Method.invoke(Method.java:525)
09-19 01:28:31.491: E/AndroidRuntime(1160): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
09-19 01:28:31.491: E/AndroidRuntime(1160): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
09-19 01:28:31.491: E/AndroidRuntime(1160): at dalvik.system.NativeStart.main(Native Method)
09-19 01:28:31.491: E/AndroidRuntime(1160): Caused by: java.lang.reflect.InvocationTargetException
09-19 01:28:31.491: E/AndroidRuntime(1160): at java.lang.reflect.Method.invokeNative(Native Method)
09-19 01:28:31.491: E/AndroidRuntime(1160): at java.lang.reflect.Method.invoke(Method.java:525)
09-19 01:28:31.491: E/AndroidRuntime(1160): at android.view.View$1.onClick(View.java:3628)
09-19 01:28:31.491: E/AndroidRuntime(1160): ... 11 more
09-19 01:28:31.491: E/AndroidRuntime(1160): Caused by: java.lang.NumberFormatException: Invalid int: "4233494398"
09-19 01:28:31.491: E/AndroidRuntime(1160): at java.lang.Integer.invalidInt(Integer.java:138)
09-19 01:28:31.491: E/AndroidRuntime(1160): at java.lang.Integer.parse(Integer.java:378)
09-19 01:28:31.491: E/AndroidRuntime(1160): at java.lang.Integer.parseInt(Integer.java:366)
09-19 01:28:31.491: E/AndroidRuntime(1160): at java.lang.Integer.parseInt(Integer.java:332)
09-19 01:28:31.491: E/AndroidRuntime(1160): at com.wordpress.smdaudhilbe.database.MainActivity.addData(MainActivity.java:59)
09-19 01:28:31.491: E/AndroidRuntime(1160): ... 14 more
09-19 01:28:34.340: I/Process(1160): Sending signal. PID: 1160 SIG: 9
Here is my complete code,
package com.wordpress.smdaudhilbe.database;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
public class MainActivity extends Activity {
public EditText nameField,idCardField,phoneField;
public Button add,del,update;
public Spinner spN;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initViews();
spN.setOnItemSelectedListener(new OnItemSelectedListener()
{
#Override
public void onItemSelected(AdapterView<?> parent, View view,int position, long id) {
nameField.setText(parent.getItemAtPosition(position - 1).toString());
idCardField.setText(parent.getItemAtPosition(position).toString());
phoneField.setText(parent.getItemAtPosition(position+1).toString());
}
#Override
public void onNothingSelected(AdapterView<?> arg0) {
}
});
}
public void addData(View v) {
initViews();
DataBaseHelper dbH = new DataBaseHelper(getApplicationContext());
dbH.insertContact(nameField.getText().toString(),Integer.parseInt(idCardField.getText().toString()),Integer.parseInt(phoneField.getText().toString()));
loadSpinner();
return;
}
private void loadSpinner() {
initViews();
DataBaseHelper dbH = new DataBaseHelper(getApplicationContext());
List<String> label = dbH.getIds();
ArrayAdapter<String> adpt = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,label);
spN.setAdapter(adpt);
}
public void deleteData(View v) {
initViews();
DataBaseHelper dbH = new DataBaseHelper(getApplicationContext());
dbH.deleteContact(Integer.parseInt(idCardField.getText().toString()));
}
private void initViews(){
nameField = (EditText)findViewById(R.id.editText1name);
idCardField = (EditText)findViewById(R.id.editText2idcard);
phoneField = (EditText)findViewById(R.id.editText3phone);
add = (Button)findViewById(R.id.button1);
del = (Button)findViewById(R.id.button2);
update = (Button)findViewById(R.id.button3);
spN = (Spinner)findViewById(R.id.spinner1);
}
}
class DataBaseHelper extends SQLiteOpenHelper{
public DataBaseHelper(Context context) {
super(context,"MyDataBase", null, 1);
}
#Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("create table contacts(name text not null,idCard integer,phoneNumber integer(10));");
}
#Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("drop table if exists contacts;");
}
public void insertContact(String name,int idcard,int phone) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues vals = new ContentValues();
vals.put("name",name);
vals.put("idCard", idcard);
vals.put("phoneNumber", phone);
db.insert("contacts", null, vals);
db.close();
}
public void deleteContact(long idcard) {
SQLiteDatabase db = this.getWritableDatabase();
db.delete("contacts", "idCard=?",new String[] {String.valueOf(idcard)});
db.close();
}
public List<String> getIds() {
SQLiteDatabase db = this.getReadableDatabase();
List<String> lst = new ArrayList<String>();
Cursor cursor = db.rawQuery("select * from contacts;",null);
if(cursor.moveToFirst()){
do{
lst.add(cursor.getString(2));
}while(cursor.moveToNext());
}
cursor.close();
db.close();
return lst;
}
}
How to solve this...? Kindly help, I read many are pointing to null pointer exception for this kind of problem.
for your information my main_activity.xml is
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<EditText
android:id="#+id/editText1name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" >
<requestFocus />
</EditText>
<EditText
android:id="#+id/editText2idcard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:digits="0123456789"
android:maxLength="4" />
<EditText
android:id="#+id/editText3phone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="phone"
android:ems="10"
android:digits="0123456789"
android:maxLength="10" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="add"
android:onClick="addData" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="del"
android:onClick="deleteData"/>
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="update"
android:onClick="updateData"/>
</LinearLayout>
<Spinner
android:id="#+id/spinner1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
UPDATE:
When I put try - catch around
try{
dbH.insertContact(nameField.getText().toString(),Integer.parseInt(idCardField.getText().toString()),Integer.parseInt(phoneField.getText().toString()));
}catch (Exception e){e.printStackTrace();}
of addData() method,
I got this,
09-19 02:33:39.485: E/AndroidRuntime(933): FATAL EXCEPTION: main
09-19 02:33:39.485: E/AndroidRuntime(933): java.lang.NullPointerException
09-19 02:33:39.485: E/AndroidRuntime(933): at com.wordpress.smdaudhilbe.database.MainActivity$1.onItemSelected(MainActivity.java:41)
09-19 02:33:39.485: E/AndroidRuntime(933): at android.widget.AdapterView.fireOnSelected(AdapterView.java:892)
09-19 02:33:39.485: E/AndroidRuntime(933): at android.widget.AdapterView.access$200(AdapterView.java:49)
09-19 02:33:39.485: E/AndroidRuntime(933): at android.widget.AdapterView$SelectionNotifier.run(AdapterView.java:860)
09-19 02:33:39.485: E/AndroidRuntime(933): at android.os.Handler.handleCallback(Handler.java:730)
09-19 02:33:39.485: E/AndroidRuntime(933): at android.os.Handler.dispatchMessage(Handler.java:92)
09-19 02:33:39.485: E/AndroidRuntime(933): at android.os.Looper.loop(Looper.java:137)
09-19 02:33:39.485: E/AndroidRuntime(933): at android.app.ActivityThread.main(ActivityThread.java:5103)
09-19 02:33:39.485: E/AndroidRuntime(933): at java.lang.reflect.Method.invokeNative(Native Method)
09-19 02:33:39.485: E/AndroidRuntime(933): at java.lang.reflect.Method.invoke(Method.java:525)
09-19 02:33:39.485: E/AndroidRuntime(933): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
09-19 02:33:39.485: E/AndroidRuntime(933): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
09-19 02:33:39.485: E/AndroidRuntime(933): at dalvik.system.NativeStart.main(Native Method)
09-19 02:33:42.555: I/Process(933): Sending signal. PID: 933 SIG: 9
I don't think, I made any error. using initViews() method,
private void initViews(){
nameField = (EditText)findViewById(R.id.editText1name);
idCardField = (EditText)findViewById(R.id.editText2idcard);
phoneField = (EditText)findViewById(R.id.editText3phone);
add = (Button)findViewById(R.id.button1);
del = (Button)findViewById(R.id.button2);
update = (Button)findViewById(R.id.button3);
spN = (Spinner)findViewById(R.id.spinner1);
}
I had already initialised all fields
and also I made every field as public.
public EditText nameField,idCardField,phoneField;
public Button add,del,update;
public Spinner spN;
Please help in this to trace the reason.

Provider<HttpSession> not getting injected

I am using gwt dispatch to communicate and get data from server to client.
In order to get user specific data I want to store the user object in httpsession and access application specific data from servlet context
but when I inject Provider<HttpSession> when the handler execute is called but the dispatchservlet the provider is null i.e it does not get injected.
following is the code from my action handler
#Inject
Provider<HttpSession> provider;
public ReadEntityHandler() {
}
#Override
public EntityResult execute(ReadEntityAction arg0, ExecutionContext arg1) throws DispatchException {
HttpSession session = null;
if (provider == null)
System.out.println("httpSession is null..");
else {
session = provider.get();
System.out.println("httpSession not null..");
}
System.out.println("reached execution");
return null;
}
and my Dispatch servlet
#Singleton
public class ActionDispatchServlet extends RemoteServiceServlet implements StandardDispatchService {
private Dispatch dispatch;
private Dispatch dispatch;
#Inject ReadEntityHandler readEntityHandler;
public ActionDispatchServlet() {
InstanceActionHandlerRegistry registry = new DefaultActionHandlerRegistry();
registry.addHandler(readEntityHandler);
dispatch = new SimpleDispatch(registry);
}
#Override
public Result execute(Action<?> action) throws DispatchException {
try {
return dispatch.execute(action);
}
catch (RuntimeException e) {
log("Exception while executing " + action.getClass().getName() + ": " + e.getMessage(), e);
throw e;
}
}
}
when I try to inject the ReadEntityHandler it throws the following exception
[WARN] failed guiceFilter
com.google.inject.ProvisionException: Guice provision errors:
1) Error injecting constructor, java.lang.NullPointerException
at com.ensarm.wikirealty.server.service.ActionDispatchServlet.<init>(ActionDispatchServlet.java:22)
at com.ensarm.wikirealty.server.service.ActionDispatchServlet.class(ActionDispatchServlet.java:22)
while locating com.ensarm.wikirealty.server.service.ActionDispatchServlet
1 error
at com.google.inject.internal.InjectorImpl$4.get(InjectorImpl.java:834)
at com.google.inject.internal.InjectorImpl.getInstance(InjectorImpl.java:856)
at com.google.inject.servlet.ServletDefinition.init(ServletDefinition.java:74)
at com.google.inject.servlet.ManagedServletPipeline.init(ManagedServletPipeline.java:84)
at com.google.inject.servlet.ManagedFilterPipeline.initPipeline(ManagedFilterPipeline.java:106)
at com.google.inject.servlet.GuiceFilter.init(GuiceFilter.java:168)
at org.mortbay.jetty.servlet.FilterHolder.doStart(FilterHolder.java:97)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
at org.mortbay.jetty.servlet.ServletHandler.initialize(ServletHandler.java:593)
at org.mortbay.jetty.servlet.Context.startContext(Context.java:140)
at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1220)
at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:513)
at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:448)
at com.google.gwt.dev.shell.jetty.JettyLauncher$WebAppContextWithReload.doStart(JettyLauncher.java:468)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
at org.mortbay.jetty.handler.RequestLogHandler.doStart(RequestLogHandler.java:115)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
at org.mortbay.jetty.Server.doStart(Server.java:222)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
at com.google.gwt.dev.shell.jetty.JettyLauncher.start(JettyLauncher.java:672)
at com.google.gwt.dev.DevMode.doStartUpServer(DevMode.java:509)
at com.google.gwt.dev.DevModeBase.startUp(DevModeBase.java:1068)
at com.google.gwt.dev.DevModeBase.run(DevModeBase.java:811)
at com.google.gwt.dev.DevMode.main(DevMode.java:311)
Caused by: java.lang.NullPointerException
at net.customware.gwt.dispatch.server.DefaultActionHandlerRegistry.addHandler(DefaultActionHandlerRegistry.java:21)
at com.ensarm.wikirealty.server.service.ActionDispatchServlet.<init>(ActionDispatchServlet.java:24)
at com.ensarm.wikirealty.server.service.ActionDispatchServlet$$FastClassByGuice$$e0a28a5d.newInstance(<generated>)
at com.google.inject.internal.cglib.reflect.FastConstructor.newInstance(FastConstructor.java:40)
at com.google.inject.internal.DefaultConstructionProxyFactory$1.newInstance(DefaultConstructionProxyFactory.java:58)
at com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:84)
at com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:200)
at com.google.inject.internal.ProviderToInternalFactoryAdapter$1.call(ProviderToInternalFactoryAdapter.java:43)
at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:878)
at com.google.inject.internal.ProviderToInternalFactoryAdapter.get(ProviderToInternalFactoryAdapter.java:40)
at com.google.inject.Scopes$1$1.get(Scopes.java:64)
at com.google.inject.internal.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:40)
at com.google.inject.internal.InjectorImpl$4$1.call(InjectorImpl.java:825)
at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:871)
at com.google.inject.internal.InjectorImpl$4.get(InjectorImpl.java:821)
... 25 more
You create instance of ReadEntityHandler registry.addHandler(new ReadEntityHandler()); himself not by container.Provider<HttpSession> provider; is null
Try:
#Inject
public ActionDispatchServlet(ReadEntityHandler handler) {
InstanceActionHandlerRegistry registry = new DefaultActionHandlerRegistry();
registry.addHandler(handler);
dispatch = new SimpleDispatch(registry);
}
Caused by: java.lang.NullPointerException
at net.customware.gwt.dispatch.server.DefaultActionHandlerRegistry.addHandler(DefaultActionHandlerRegistry.java:21)
Is it possible that DefaultActionHandlerRegistry has a bug in it at line 21, and that the error is happening there? I don't see the code for that class, so it isn't clear if this is the cause of your issue, or just a symptom.