I have 2 animations, slide[1] and slide[3], and when I try to cancel them when the animation repeats itself, it causes a crash. here is some relevant code:
slide[1].setDuration(500); slide[1].setStartDelay(500);
slide[3].setDuration(500); slide[3].setStartDelay(500);
slide[1].addListener(new Animator.AnimatorListener() {
#Override
public void onAnimationStart(Animator animation) {
}
#Override
public void onAnimationCancel(Animator animation) {
}
#Override
public void onAnimationRepeat(Animator animation) {
if (!start) {
table[2][2].setBackgroundResource(R.drawable.black);
slide[1].setDuration(1000);
slide[1].setStartDelay(0);
slide[3].setDuration(1000);
slide[3].setStartDelay(0);
slide[1].removeAllListeners();
slide[3].cancel();
slide[1].cancel();
}
}
#Override
public void onAnimationEnd(Animator animation) {
}
}); slide[1].start(); slide[3].start();
The line which causes the crash is "slide[1].cancel();", and I don't know why.
Apparently the crash is being caused when the phone is running on JellyBean, but not Marshmallow for example.
How can I solve this problem?
Thanks!
UPDATE: here is the logcat:
03-13 16:18:01.943 1623-1623/com.example.ohad.squerz E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:251)
at java.util.ArrayList.get(ArrayList.java:304)
at android.animation.ValueAnimator$AnimationHandler.doAnimationFrame(ValueAnimator.java:603)
at android.animation.ValueAnimator$AnimationHandler.run(ValueAnimator.java:639)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
at android.view.Choreographer.doCallbacks(Choreographer.java:555)
at android.view.Choreographer.doFrame(Choreographer.java:524)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
This crash has been fixed in AOSP in this commit.
If you want to support API 16, you need to cancel your animations somewhere else than in onAnimationUpdate/onAnimationRepeat.
In your case (if it matters, because this answer comes a long time after your question), you probably want to avoid the repeat on your first animator, using setRepeatCount(0).
Related
I am beginner and I had a test. I did all tasks, but I have a problem -
public class HttpTask extends AsyncTask<Integer, String, String> {####
ProgressDialog dialog;
Context context;
public HttpTask(Activity activity) {
//init progress dialog
dialog = new ProgressDialog(context);****
dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
}
protected void onPreExecute() {
// show progress dialog
dialog.setMessage("Loading...");
dialog.setCancelable(false);
}
protected String doInBackground(Integer... params) {
//freeze system to 5 seconds
try {
int seconds = params[0]*5;####
TimeUnit.SECONDS.sleep(seconds);
} catch (InterruptedException e) {
e.printStackTrace();
}
return null;
}
#Override
protected void onPostExecute(final String success) {
// if there is progress dialog hide it
dialog.dismiss();
}
}
It crashes, when I try to compile it (I showed where are problems with * sign):
08-03 10:43:10.873 29441-29441/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.NullPointerException
at android.app.AlertDialog.resolveDialogTheme(AlertDialog.java:142)
at android.app.AlertDialog.<init>(AlertDialog.java:98)
at android.app.ProgressDialog.<init>(ProgressDialog.java:77)
at net.joerichard.androidtest.main.f.HttpTask.<init>(HttpTask.java:26)
at net.joerichard.androidtest.main.f.F_Networking_Activity$1.onClick(F_Networking_Activity.java:27)
at android.view.View.performClick(View.java:4107)
at android.view.View$PerformClick.run(View.java:17166)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:155)
at android.app.ActivityThread.main(ActivityThread.java:5559)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1074)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:841)
at dalvik.system.NativeStart.main(Native Method)
08-03 10:43:10.913 754-877/? E/EmbeddedLogger﹕ App crashed! Process: net.joerichard.androidtest
08-03 10:43:10.913 754-877/? E/EmbeddedLogger﹕ App crashed! Package: net.joerichard.androidtest v1 (1.0)
08-03 10:43:10.913 754-877/? E/EmbeddedLogger﹕ Application Label: AndroidTest
This is class of main activity.
public class F_Networking_Activity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_f__networking_);
// bDownload: start HttpTask
Button bDownload = (Button) findViewById(R.id.bDownload);
bDownload.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
HttpTask task = new HttpTask(F_Networking_Activity.this);****
task.execute();
}
});
}
Thank you for your answers. Now I have another problem (I showed with # sign of second problems)
08-03 11:28:18.292 754-877/? E/EmbeddedLogger﹕ App crashed! Process: net.joerichard.androidtest'
08-03 11:28:18.292 754-877/? E/EmbeddedLogger﹕ App crashed! Package: net.joerichard.androidtest v1 (1.0)
08-03 11:28:18.292 754-877/? E/EmbeddedLogger﹕ Application Label: AndroidTest
08-03 11:28:18.292 30544-30726/? E/AndroidRuntime﹕ FATAL EXCEPTION: AsyncTask #1
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:299)
at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:864)
Caused by: java.lang.ArrayIndexOutOfBoundsException: length=0; index=0
at net.joerichard.androidtest.main.f.HttpTask.doInBackground(HttpTask.java:40)
at net.joerichard.androidtest.main.f.HttpTask.doInBackground(HttpTask.java:20)
at android.os.AsyncTask$2.call(AsyncTask.java:287)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:864)
Actually, your context is null because you didn't initialize it.
Add one extra line inside your HttpTask:
public HttpTask(Activity activity) {
this.context = activity;
dialog = new ProgressDialog(context);
dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
}
and change Context to Activity like this:
Activity context;
Now call this context anywhere in your class.
Yes you must get NullPointer. Because your context is null.
Change this like
public HttpTask(Context _context) {
context = _context;
//init progress dialog
dialog = new ProgressDialog(context);****
dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
}
Following problem: if I press the power button after pressing a take picture button just before the getPictureCallback() methode is called the app crashes.
The camera is loaded in a thread like this:
private class CameraHandlerThread extends HandlerThread {
Handler mHandler = null;
CameraHandlerThread() {
super("CameraHandlerThread");
start();
mHandler = new Handler(getLooper());
}
synchronized void notifyCameraOpened() {
notify();
runOnUiThread(new Runnable() {
public void run() {
setCameraParameter();
}
});
}
void openCamera() {
mHandler.post(new Runnable() {
#Override
public void run() {
openAndroidCamera();
notifyCameraOpened();
}
});
try {
wait();
}
catch (InterruptedException ex) {
LogManager.e(TAG, ex.getMessage(), ex);
CoreToastDialog.showErrorMessage(getString(R.string.FailedToLoadCamera));
}
}
}
I interrupt the thread in onPause. Any ideas how to fix this? The bug only occures in a very rare time shift - so only every 30 tries it works maybe once.
If it is PictureCallback, is there any way to fix this?
Error Message:
W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x410a32a0)
W/System.err﹕ java.lang.RuntimeException: Unable to start activity ComponentInfo{DeviceListView}: java.lang.NullPointerException
W/System.err﹕ at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2110)
W/System.err﹕ at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
W/System.err﹕ at android.app.ActivityThread.access$700(ActivityThread.java:140)
W/System.err﹕ at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
W/System.err﹕ at android.os.Handler.dispatchMessage(Handler.java:99)
W/System.err﹕ at android.os.Looper.loop(Looper.java:137)
W/System.err﹕ at android.app.ActivityThread.main(ActivityThread.java:4921)
W/System.err﹕ at java.lang.reflect.Method.invokeNative(Native Method)
I'm trying to create a ListView with bitmaps that are generated on demand. I'm using https://github.com/chrisbanes/Android-BitmapCache to cache the bitmaps
I'm using a SimpleAdapter, with this :
setViewBinder(new SimpleAdapter.ViewBinder() {
#Override
public boolean setViewValue(View view, Object object,String string) {
if( string.startsWith("ClassName:") ){
final ImageView yourImageView=(ImageView) view;
AsyncTask<String, Void, Bitmap> imageLoadAsyncTask = new AsyncTask<String, Void, Bitmap>() {
String cname;
#Override
protected Bitmap doInBackground(String... classnames) {
cname=classnames[0];
return db.getCharIcon(classnames[0]);
}
#Override
protected void onPostExecute(Bitmap bitmap) {
yourImageView.setImageBitmap(bitmap);
}
};
imageLoadAsyncTask.execute(string.substring(TextUtils.getTrimmedLength("ClassName:")));
return true;
}
return false;
}
}
the getCharIcon function is here :
Bitmap getCharIcon(String classname){
Bitmap modBmp;
CacheableBitmapDrawable cacheBmp=mCache.get(classname);
if(cacheBmp==null)
{
modBmp=createCharIcon(classname);
mCache.put(classname,modBmp);
}
else
{
modBmp=cacheBmp.getBitmap();
}
return modBmp;
}
where createCharIcon generates the bitmap this way (I have yet to implement the final version that selects the good portion of the image):
Bitmap createCharIcon(String classname)
{
Bitmap modBmp = Bitmap.createBitmap(srcBmp,0,0,60,60);
return modBmp;
}
Sadly I am getting this error :
07-02 14:13:04.248 11592-11592/com.lectem.gecharacters E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.util.concurrent.RejectedExecutionException
at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:1876)
at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:774)
at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1295)
at android.os.AsyncTask.execute(AsyncTask.java:394)
at com.lectem.gecharacters.CharFragment$1.setViewValue(CharFragment.java:110)
at android.widget.SimpleAdapter.bindView(SimpleAdapter.java:168)
at android.widget.SimpleAdapter.createViewFromResource(SimpleAdapter.java:126)
at android.widget.SimpleAdapter.getView(SimpleAdapter.java:114)
at android.widget.AbsListView.obtainView(AbsListView.java:1294)
at android.widget.ListView.makeAndAddView(ListView.java:1730)
at android.widget.ListView.fillDown(ListView.java:655)
at android.widget.ListView.fillSpecific(ListView.java:1287)
at android.widget.ListView.layoutChildren(ListView.java:1573)
at android.widget.AbsListView.onLayout(AbsListView.java:1147)
at android.view.View.layout(View.java:7035)
at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
at android.view.View.layout(View.java:7035)
at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
at android.view.View.layout(View.java:7035)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1252)
at android.widget.LinearLayout.layoutHorizontal(LinearLayout.java:1241)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1047)
at android.view.View.layout(View.java:7035)
at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
at android.view.View.layout(View.java:7035)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1252)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1128)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1045)
at android.view.View.layout(View.java:7035)
at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
at android.view.View.layout(View.java:7035)
at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
at android.view.View.layout(View.java:7035)
at android.view.ViewRoot.performTraversals(ViewRoot.java:1045)
at android.view.ViewRoot.handleMessage(ViewRoot.java:1727)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)
I get this error when I scroll the list back too fast, so I suppose it is linked with the number of asyncTasks I can use...
I'm really not sure if this is how I should do it or not, but the library bitmapLruCache needs to be ran on something else than the main thread.
Usually, that error means that you are trying to use too many AsyncTasks at once. In an AdapterView, this can occur if you are forking an AsyncTask for every item (e.g., every row in a ListView) without taking into account row recycling, and the user flings the list.
Quoting the library's documentation:
If you wish for the library and recycling feature to work, you MUST use the bundled CacheableImageView wherever possible.
Since you appear to be using this in an AdapterView, please make sure that you are using CacheableImageView.
Please help im getting java.lang.NullPointerException
in android.support.v7.app.ActionBarImplICS.getThemedContext in Google play developer console but when I test it I don't get any errors or crashes , please tell me what is causing the crash and how to solve the problem. the error is shown below, I can also share the code if needed.
java.lang.NullPointerException
at android.support.v7.app.ActionBarImplICS.getThemedContext(ActionBarImplICS.java:287)
at android.support.v7.app.ActionBarImplJB.getThemedContext(ActionBarImplJB.java:20)
at android.support.v7.app.ActionBarActivityDelegate.getActionBarThemedContext(ActionBarActivityDelegate.java:207)
at android.support.v7.app.ActionBarActivityDelegateICS.onActionModeStarted(ActionBarActivityDelegateICS.java:196)
at android.support.v7.app.ActionBarActivityDelegateICS$WindowCallbackWrapper.onActionModeStarted(ActionBarActivityDelegateICS.java:351)
at com.android.internal.policy.impl.PhoneWindow$DecorView.startActionMode(PhoneWindow.java:2292)
at com.android.internal.policy.impl.PhoneWindow$DecorView.startActionModeForChild(PhoneWindow.java:2215)
at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:619)
at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:619)
at android.view.View.startActionMode(View.java:4191)
at android.webkit.WebViewClassic.startSelectActionMode(WebViewClassic.java:5049)
at android.webkit.WebViewClassic.setupWebkitSelect(WebViewClassic.java:5178)
at android.webkit.WebViewClassic.updateTextSelectionFromMessage(WebViewClassic.java:7929)
at android.webkit.WebViewClassic.access$4300(WebViewClassic.java:147)
at android.webkit.WebViewClassic$PrivateHandler.handleMessage(WebViewClassic.java:7249)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
This solved my problem from https://stackoverflow.com/a/19320065/619673
I added this code for my activity because I was using theme "NO TITLE" for Activity.
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ( keyCode == KeyEvent.KEYCODE_MENU ) {
// do nothing
return true;
}
return super.onKeyDown(keyCode, event);
}
public class MainActivity extends ActionBarActivity
Change this to:
public class MainActivity extends Activity
I am trying to make an application that passes through the audio samples obtained at the microphone to the speaker. This is the source code:
public class MainActivity extends Activity {
AudioManager am = null;
AudioRecord record =null;
AudioTrack track =null;
final int SAMPLE_FREQUENCY = 44100;
final int SIZE_OF_RECORD_ARRAY = 1024;
boolean isPlaying = false;
class MyThread extends Thread{
#Override
public void run(){
recordAndPlay();
}
}
MyThread newThread;
private void init() {
int min = AudioRecord.getMinBufferSize(SAMPLE_FREQUENCY, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT);
record = new AudioRecord(MediaRecorder.AudioSource.VOICE_COMMUNICATION, SAMPLE_FREQUENCY, AudioFormat.CHANNEL_IN_MONO,
AudioFormat.ENCODING_PCM_16BIT, min);
int maxJitter = AudioTrack.getMinBufferSize(SAMPLE_FREQUENCY, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_16BIT);
track = new AudioTrack(AudioManager.MODE_IN_COMMUNICATION, SAMPLE_FREQUENCY, AudioFormat.CHANNEL_OUT_MONO,
AudioFormat.ENCODING_PCM_16BIT, maxJitter, AudioTrack.MODE_STREAM);
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setVolumeControlStream(AudioManager.STREAM_MUSIC);
init();
newThread.start();
}
#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 void recordAndPlay() {
short[] lin = new short[SIZE_OF_RECORD_ARRAY];
int num = 0;
am = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
am.setMode(AudioManager.MODE_IN_COMMUNICATION);
record.startRecording();
track.play();
while (true) {
num = record.read(lin, 0, SIZE_OF_RECORD_ARRAY);
track.write(lin, 0, num);
}
}
public void passStop(View view){
Button playBtn = (Button) findViewById(R.id.playBtn);
// /*
if(!isPlaying){
record.startRecording();
track.play();
isPlaying = true;
playBtn.setText("Pause");
}
if(isPlaying){
record.stop();
track.pause();
isPlaying=false;
playBtn.setText("Pass through");
}
// */
}
#SuppressWarnings("deprecation")
#Override
public void onDestroy(){
newThread.stop();
}
}
Unfortunately, this program stops as soon as I try to run it through eclipse. This is wht I get in the logcat but I am not sure what it all means:
08-19 18:58:43.365: D/AndroidRuntime(27915): Shutting down VM
08-19 18:58:43.365: W/dalvikvm(27915): threadid=1: thread exiting with uncaught exception (group=0x4161f700)
08-19 18:58:43.365: E/AndroidRuntime(27915): FATAL EXCEPTION: main
08-19 18:58:43.365: E/AndroidRuntime(27915): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mypassthrough/com.example.mypassthrough.MainActivity}: java.lang.NullPointerException
08-19 18:58:43.365: E/AndroidRuntime(27915): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
08-19 18:58:43.365: E/AndroidRuntime(27915): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
08-19 18:58:43.365: E/AndroidRuntime(27915): at android.app.ActivityThread.access$600(ActivityThread.java:141)
08-19 18:58:43.365: E/AndroidRuntime(27915): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
08-19 18:58:43.365: E/AndroidRuntime(27915): at android.os.Handler.dispatchMessage(Handler.java:99)
08-19 18:58:43.365: E/AndroidRuntime(27915): at android.os.Looper.loop(Looper.java:137)
08-19 18:58:43.365: E/AndroidRuntime(27915): at android.app.ActivityThread.main(ActivityThread.java:5103)
08-19 18:58:43.365: E/AndroidRuntime(27915): at java.lang.reflect.Method.invokeNative(Native Method)
08-19 18:58:43.365: E/AndroidRuntime(27915): at java.lang.reflect.Method.invoke(Method.java:525)
08-19 18:58:43.365: E/AndroidRuntime(27915): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
08-19 18:58:43.365: E/AndroidRuntime(27915): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-19 18:58:43.365: E/AndroidRuntime(27915): at dalvik.system.NativeStart.main(Native Method)
08-19 18:58:43.365: E/AndroidRuntime(27915): Caused by: java.lang.NullPointerException
08-19 18:58:43.365: E/AndroidRuntime(27915): at com.example.mypassthrough.MainActivity.onCreate(MainActivity.java:46)
08-19 18:58:43.365: E/AndroidRuntime(27915): at android.app.Activity.performCreate(Activity.java:5133)
08-19 18:58:43.365: E/AndroidRuntime(27915): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
08-19 18:58:43.365: E/AndroidRuntime(27915): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
08-19 18:58:43.365: E/AndroidRuntime(27915): ... 11 more
What could be the reason for this code crashing, and how can it be debugged? I am pretty sure it has something to do with Thread, because my other versions of this code where I have not included Thread at all do not crash on startup.
Variable newThread is not initialized in oncreate() method that's why it is giving nullpointer exception
add this in your init() method it will work
newThread=new Thread();
You are getting a null pointer exception because newThread has not been initialized yet and it is null when you try to start it. The thread doesn't have anything to do also. You should look at implementing a runnable, handler, and timer into your activity instead of a thread.
Use sub class with extending AsyncTask Class
class TestActivity extends AsyncTask <String, Void, String > {
protected String doInBackground(String... urls) {
// execution
}
protected void onPostExecute(String result) {
// post execution
}
protected void onPreExecute() {
super.onPreExecute();
// initial activities
}
}