稳定的例外。不确定如何解决这个问题 [英] Stable Exception .Not sure how to resolve this
本文介绍了稳定的例外。不确定如何解决这个问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在完成视频播放时遇到稳定的异常。不确定究竟是什么导致了这个问题。尝试调试并说出以下错误
I am getting stable exception on completing video play. Not sure what really causing the issue. tried debugging and says the following error
Exception 'android.database.StaleDataException' occurred in thread '<1> main' at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:139)
Exception 'android.database.StaleDataException' occurred in thread '<1> main' at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1957)
Exception 'android.database.StaleDataException' occurred in thread '<1> main' at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1041)
Exception 'android.database.StaleDataException' occurred in thread '<1> main' at android.view.Choreographer.doCallbacks(Choreographer.java:584)
Exception 'java.lang.reflect.InvocationTargetException' occurred in thread '<1> main' at java.lang.reflect.Method.invoke(Method.java:515)
Exception 'android.database.StaleDataException' occurred in thread '<1> main' at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:799)
Videolist.java
Videolist.java
package shashank_balaganchi.sbsvideoplayer;
/**
* Created by shashank on 04-10-2015.
*/
import android.app.*;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.database.*;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.*;
import android.provider.*;
import android.support.v4.widget.SwipeRefreshLayout;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.*;
import android.widget.AdapterView.*;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.InterstitialAd;
public class Videolist extends Activity {
public Cursor videoCursor;
public int videoColumnIndex;
ListView videolist;
int count;
String thumbPath;
SwipeRefreshLayout swipeLayout;
private InterstitialAd mInterstitialAd;
String[] thumbColumns = { MediaStore.Video.Thumbnails.DATA,MediaStore.Video.Thumbnails.VIDEO_ID };
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.filelist);
initialization();
}
@SuppressWarnings("deprecation")
public void initialization()
{
System.gc();
String[] videoProjection = { MediaStore.Video.Media._ID,MediaStore.Video.Media.DATA,
MediaStore.Video.Media.DISPLAY_NAME,MediaStore.Video.Media.SIZE };
videoCursor = managedQuery(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,videoProjection, null, null, null);
count = videoCursor.getCount();
videolist = (ListView) findViewById(R.id.PhoneVideoList);
videolist.setAdapter(new VideoAdapter(this.getApplicationContext()));
videolist.setOnItemClickListener(videogridlistener);
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId("ca-app-pub-9884649282055349/9213170919");
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice("YOUR_DEVICE_HASH")
.build();
mInterstitialAd.loadAd(adRequest);
if (mInterstitialAd.isLoaded())
{
mInterstitialAd.show();
}
}
private OnItemClickListener videogridlistener = new OnItemClickListener()
{
public void onItemClick(AdapterView parent, View v, int position,long id)
{
System.gc();
videoColumnIndex = videoCursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA);
videoCursor.moveToPosition(position);
String filename = videoCursor.getString(videoColumnIndex);
Log.i("FileName: ", filename);
Intent intent = new Intent(Videolist.this,ViewVideo.class);
intent.putExtra("videofilename", filename);
startActivity(intent);
}
};
public class VideoAdapter extends BaseAdapter
{
private Context vContext;
int layoutResourceId;
public VideoAdapter(Context c)
{
vContext = c;
}
public int getCount()
{
return videoCursor.getCount();
}
public Object getItem(int position)
{
return position;
}
public long getItemId(int position)
{
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
System.gc();
String id = null;
if (convertView == null)
convertView = LayoutInflater.from(vContext).inflate(R.layout.listview, parent, false);
TextView txtTitle = (TextView) convertView.findViewById(R.id.txtTitle);
TextView txtSize = (TextView) convertView.findViewById(R.id.txtSize);
ImageView thumbImage = (ImageView) convertView.findViewById(R.id.imgIcon);
videoColumnIndex = videoCursor.getColumnIndexOrThrow(MediaStore.Video.Media.DISPLAY_NAME);
videoCursor.moveToPosition(position);
txtTitle.setText(videoCursor.getString(videoColumnIndex));
videoColumnIndex = videoCursor.getColumnIndexOrThrow(MediaStore.Video.Media.SIZE);
videoCursor.moveToPosition(position);
txtSize.setText(" Size(KB):" + videoCursor.getString(videoColumnIndex));
int videoId = videoCursor.getInt(videoCursor.getColumnIndexOrThrow(MediaStore.Video.Media._ID));
@SuppressWarnings("deprecation")
Cursor videoThumbnailCursor = managedQuery(MediaStore.Video.Thumbnails.EXTERNAL_CONTENT_URI,
thumbColumns, MediaStore.Video.Thumbnails.VIDEO_ID+ "=" + videoId, null, null);
if (videoThumbnailCursor.moveToFirst())
{
thumbPath = videoThumbnailCursor.getString(videoThumbnailCursor.getColumnIndex(MediaStore.Video.Thumbnails.DATA));
Log.i("ThumbPath: ",thumbPath);
}
thumbImage.setImageURI(Uri.parse(thumbPath));
return convertView;
}
}
@Override
public void onDestroy() {
super.onDestroy();
{
videoCursor.close();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.action_quit:
finish();
System.exit(0);
default:
return super.onOptionsItemSelected(item);
}
}
}
Videoview.java
Videoview.java
package shashank_balaganchi.sbsvideoplayer;
/**
* Created by shiva on 04-10-2015.
*/
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.util.*;
import android.view.*;
import android.view.View;
import android.widget.*;
import android.media.*;
public class ViewVideo extends Activity implements GestureDetection.SimpleGestureListener
{
//Declare Variables
private String filename;
VideoView vv;
Cursor videoCursor;
ProgressDialog pdailog;
boolean pausing = false;
AudioManager audioManager;
GestureDetection detector;
int currentPosition;
int currentVolume;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Insert your Video
System.gc();
Intent i = getIntent();
Bundle extras = i.getExtras();
filename = extras.getString("videofilename");
//Get the videoview layout
setContentView(R.layout.videoview);
//audiomanager
audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
// Find your VideoView in your videoview.xml layout
vv = (VideoView) this.findViewById(R.id.videoView);
//Swipe Feature
detector = new GestureDetection(this, this);
// Create a progressbar
pdailog = new ProgressDialog(ViewVideo.this);
// Set progressbar title
pdailog.setTitle("SBS VideoPlayer");
// Set progressbar message
pdailog.setMessage("Buffering...");
pdailog.setIndeterminate(false);
pdailog.setCancelable(false);
// Show progressbar
pdailog.show();
try
{
// Start the MediaController
MediaController mediacontroller = new MediaController(ViewVideo.this);
mediacontroller.setAnchorView(vv);
mediacontroller.setVisibility(View.VISIBLE);
vv.setMediaController(mediacontroller);
vv.setVideoPath(filename);
}
catch (Exception e)
{
Log.e("Error", e.getMessage());
e.printStackTrace();
}
vv.requestFocus();
vv.setOnPreparedListener(new MediaPlayer.OnPreparedListener()
{
// Close the progress bar and play the video
public void onPrepared(MediaPlayer mp)
{
pdailog.dismiss();
vv.start();
}
});
vv.requestFocus();
vv.setOnCompletionListener(new MediaPlayer.OnCompletionListener()
{
// Close the progress bar and stop video
public void onCompletion(MediaPlayer mp)
{
pdailog.dismiss();
vv.stopPlayback();
Intent intent = new Intent(getApplicationContext(), Videolist.class);
startActivity(intent);
}
});
vv.requestFocus();
vv.setOnErrorListener(new MediaPlayer.OnErrorListener()
{
// Close the progress bar and stop video
public boolean onError(MediaPlayer mp, int a, int b)
{
pdailog.dismiss();
vv.stopPlayback();
Intent intent = new Intent(getApplicationContext(), Videolist.class);
startActivity(intent);
return false;
}
});
}
@Override
public void onBackPressed()
{
pdailog.dismiss();
vv.stopPlayback();
Intent intent = new Intent(getApplicationContext(), Videolist.class);
startActivity(intent);
super.onBackPressed();
}
@Override
public boolean dispatchTouchEvent(MotionEvent me) {
// Call onTouchEvent of SimpleGestureFilter class
this.detector.onTouchEvent(me);
return super.dispatchTouchEvent(me);
}
@Override
public void onSwipe(int direction) {
// TODO Auto-generated method stub
String str = "";
//SeekBar volControl = (SeekBar)findViewById(R.id.volbar);
switch (direction) {
case GestureDetection.SWIPE_LEFT:
currentPosition = vv.getCurrentPosition();
currentPosition = vv.getCurrentPosition() + 10000;
vv.seekTo(currentPosition);
str = "Swipe Left";
break;
case GestureDetection.SWIPE_RIGHT:
currentPosition = vv.getCurrentPosition();
currentPosition = vv.getCurrentPosition() - 10000;
vv.seekTo(currentPosition);
str = "Swipe Right";
break;
case GestureDetection.SWIPE_DOWN:
currentVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, currentVolume - 5, 0);
//str = "Swipe Down";
break;
case GestureDetection.SWIPE_UP:
currentVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, currentVolume + 5, 0);
// str = "Swipe Up";
break;
}
// Toast.makeText(this, str, Toast.LENGTH_SHORT).show();
}
}
推荐答案
MethodAndArgsCaller。 run(ZygoteInit.java:799)
MethodAndArgsCaller.run(ZygoteInit.java:799)
Videolist.java
Videolist.java
package shashank_balaganchi.sbsvideoplayer;
/**
* Created by shashank on 04-10-2015.
*/
import android.app.*;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.database.*;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.*;
import android.provider.*;
import android.support.v4.widget.SwipeRefreshLayout;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.*;
import android.widget.AdapterView.*;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.InterstitialAd;
public class Videolist extends Activity {
public Cursor videoCursor;
public int videoColumnIndex;
ListView videolist;
int count;
String thumbPath;
SwipeRefreshLayout swipeLayout;
private InterstitialAd mInterstitialAd;
String[] thumbColumns = { MediaStore.Video.Thumbnails.DATA,MediaStore.Video.Thumbnails.VIDEO_ID };
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.filelist);
initialization();
}
@SuppressWarnings("deprecation")
public void initialization()
{
System.gc();
String[] videoProjection = { MediaStore.Video.Media._ID,MediaStore.Video.Media.DATA,
MediaStore.Video.Media.DISPLAY_NAME,MediaStore.Video.Media.SIZE };
videoCursor = managedQuery(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,videoProjection, null, null, null);
count = videoCursor.getCount();
videolist = (ListView) findViewById(R.id.PhoneVideoList);
videolist.setAdapter(new VideoAdapter(this.getApplicationContext()));
videolist.setOnItemClickListener(videogridlistener);
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId("ca-app-pub-9884649282055349/9213170919");
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice("YOUR_DEVICE_HASH")
.build();
mInterstitialAd.loadAd(adRequest);
if (mInterstitialAd.isLoaded())
{
mInterstitialAd.show();
}
}
private OnItemClickListener videogridlistener = new OnItemClickListener()
{
public void onItemClick(AdapterView parent, View v, int position,long id)
{
System.gc();
videoColumnIndex = videoCursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA);
videoCursor.moveToPosition(position);
String filename = videoCursor.getString(videoColumnIndex);
Log.i("FileName: ", filename);
Intent intent = new Intent(Videolist.this,ViewVideo.class);
intent.putExtra("videofilename", filename);
startActivity(intent);
}
};
public class VideoAdapter extends BaseAdapter
{
private Context vContext;
int layoutResourceId;
public VideoAdapter(Context c)
{
vContext = c;
}
public int getCount()
{
return videoCursor.getCount();
}
public Object getItem(int position)
{
return position;
}
public long getItemId(int position)
{
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
System.gc();
String id = null;
if (convertView == null)
convertView = LayoutInflater.from(vContext).inflate(R.layout.listview, parent, false);
TextView txtTitle = (TextView) convertView.findViewById(R.id.txtTitle);
TextView txtSize = (TextView) convertView.findViewById(R.id.txtSize);
ImageView thumbImage = (ImageView) convertView.findViewById(R.id.imgIcon);
videoColumnIndex = videoCursor.getColumnIndexOrThrow(MediaStore.Video.Media.DISPLAY_NAME);
videoCursor.moveToPosition(position);
txtTitle.setText(videoCursor.getString(videoColumnIndex));
videoColumnIndex = videoCursor.getColumnIndexOrThrow(MediaStore.Video.Media.SIZE);
videoCursor.moveToPosition(position);
txtSize.setText(" Size(KB):" + videoCursor.getString(videoColumnIndex));
int videoId = videoCursor.getInt(videoCursor.getColumnIndexOrThrow(MediaStore.Video.Media._ID));
@SuppressWarnings("deprecation")
Cursor videoThumbnailCursor = managedQuery(MediaStore.Video.Thumbnails.EXTERNAL_CONTENT_URI,
thumbColumns, MediaStore.Video.Thumbnails.VIDEO_ID+ "=" + videoId, null, null);
if (videoThumbnailCursor.moveToFirst())
{
thumbPath = videoThumbnailCursor.getString(videoThumbnailCursor.getColumnIndex(MediaStore.Video.Thumbnails.DATA));
Log.i("ThumbPath: ",thumbPath);
}
thumbImage.setImageURI(Uri.parse(thumbPath));
return convertView;
}
}
@Override
public void onDestroy() {
super.onDestroy();
{
videoCursor.close();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.action_quit:
finish();
System.exit(0);
default:
return super.onOptionsItemSelected(item);
}
}
}
Videoview.java
Videoview.java
package shashank_balaganchi.sbsvideoplayer;
/**
* Created by shiva on 04-10-2015.
*/
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.util.*;
import android.view.*;
import android.view.View;
import android.widget.*;
import android.media.*;
public class ViewVideo extends Activity implements GestureDetection.SimpleGestureListener
{
//Declare Variables
private String filename;
VideoView vv;
Cursor videoCursor;
ProgressDialog pdailog;
boolean pausing = false;
AudioManager audioManager;
GestureDetection detector;
int currentPosition;
int currentVolume;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Insert your Video
System.gc();
Intent i = getIntent();
Bundle extras = i.getExtras();
filename = extras.getString("videofilename");
//Get the videoview layout
setContentView(R.layout.videoview);
//audiomanager
audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
// Find your VideoView in your videoview.xml layout
vv = (VideoView) this.findViewById(R.id.videoView);
//Swipe Feature
detector = new GestureDetection(this, this);
// Create a progressbar
pdailog = new ProgressDialog(ViewVideo.this);
// Set progressbar title
pdailog.setTitle("SBS VideoPlayer");
// Set progressbar message
pdailog.setMessage("Buffering...");
pdailog.setIndeterminate(false);
pdailog.setCancelable(false);
// Show progressbar
pdailog.show();
try
{
// Start the MediaController
MediaController mediacontroller = new MediaController(ViewVideo.this);
mediacontroller.setAnchorView(vv);
mediacontroller.setVisibility(View.VISIBLE);
vv.setMediaController(mediacontroller);
vv.setVideoPath(filename);
}
catch (Exception e)
{
Log.e("Error", e.getMessage());
e.printStackTrace();
}
vv.requestFocus();
vv.setOnPreparedListener(new MediaPlayer.OnPreparedListener()
{
// Close the progress bar and play the video
public void onPrepared(MediaPlayer mp)
{
pdailog.dismiss();
vv.start();
}
});
vv.requestFocus();
vv.setOnCompletionListener(new MediaPlayer.OnCompletionListener()
{
// Close the progress bar and stop video
public void onCompletion(MediaPlayer mp)
{
pdailog.dismiss();
vv.stopPlayback();
Intent intent = new Intent(getApplicationContext(), Videolist.class);
startActivity(intent);
}
});
vv.requestFocus();
vv.setOnErrorListener(new MediaPlayer.OnErrorListener()
{
// Close the progress bar and stop video
public boolean onError(MediaPlayer mp, int a, int b)
{
pdailog.dismiss();
vv.stopPlayback();
Intent intent = new Intent(getApplicationContext(), Videolist.class);
startActivity(intent);
return false;
}
});
}
@Override
public void onBackPressed()
{
pdailog.dismiss();
vv.stopPlayback();
Intent intent = new Intent(getApplicationContext(), Videolist.class);
startActivity(intent);
super.onBackPressed();
}
@Override
public boolean dispatchTouchEvent(MotionEvent me) {
// Call onTouchEvent of SimpleGestureFilter class
this.detector.onTouchEvent(me);
return super.dispatchTouchEvent(me);
}
@Override
public void onSwipe(int direction) {
// TODO Auto-generated method stub
String str = "";
//SeekBar volControl = (SeekBar)findViewById(R.id.volbar);
switch (direction) {
case GestureDetection.SWIPE_LEFT:
currentPosition = vv.getCurrentPosition();
currentPosition = vv.getCurrentPosition() + 10000;
vv.seekTo(currentPosition);
str = "Swipe Left";
break;
case GestureDetection.SWIPE_RIGHT:
currentPosition = vv.getCurrentPosition();
currentPosition = vv.getCurrentPosition() - 10000;
vv.seekTo(currentPosition);
str = "Swipe Right";
break;
case GestureDetection.SWIPE_DOWN:
currentVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, currentVolume - 5, 0);
//str = "Swipe Down";
break;
case GestureDetection.SWIPE_UP:
currentVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, currentVolume + 5, 0);
// str = "Swipe Up";
break;
}
// Toast.makeText(this, str, Toast.LENGTH_SHORT).show();
}
}
这篇关于稳定的例外。不确定如何解决这个问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文