I am getting the following runtime exception.
Fatal signal 6 (SIGABRT) at 0x00000820 (code=-6), thread 2080
thread eixiting with uncaught exception
java.lang.RuntimeException: An error occured while executing doInBackground()
I am posted the full stacktrace errors below:
Stacktrace:
02-02 02:13:17.137: E/dalvikvm(2080): VM aborting
02-02 02:13:17.137: A/libc(2080): Fatal signal 6 (SIGABRT) at 0x00000820 (code=-6), thread 2080 (e.quranmadeeasy)
02-02 02:13:20.177: D/dalvikvm(2140): GC_FOR_ALLOC freed 101K, 8% free 2981K/3208K, paused 74ms, total 75ms
02-02 02:13:20.177: I/dalvikvm-heap(2140): Grow heap (frag case) to 3.637MB for 635812-byte allocation
02-02 02:13:20.217: D/dalvikvm(2140): GC_FOR_ALLOC freed 0K, 6% free 3602K/3832K, paused 36ms, total 36ms
02-02 02:13:20.397: W/dalvikvm(2140): threadid=13: thread exiting with uncaught exception (group=0xb3a3cba8)
02-02 02:13:20.397: E/AndroidRuntime(2140): FATAL EXCEPTION: AsyncTask #1
02-02 02:13:20.397: E/AndroidRuntime(2140): Process: com.qrme.quranmadeeasy, PID: 2140
02-02 02:13:20.397: E/AndroidRuntime(2140): java.lang.RuntimeException: An error occured while executing doInBackground()
02-02 02:13:20.397: E/AndroidRuntime(2140): at android.os.AsyncTask$3.done(AsyncTask.java:300)
02-02 02:13:20.397: E/AndroidRuntime(2140): at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
02-02 02:13:20.397: E/AndroidRuntime(2140): at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
02-02 02:13:20.397: E/AndroidRuntime(2140): at java.util.concurrent.FutureTask.run(FutureTask.java:242)
02-02 02:13:20.397: E/AndroidRuntime(2140): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
02-02 02:13:20.397: E/AndroidRuntime(2140): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
02-02 02:13:20.397: E/AndroidRuntime(2140): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
02-02 02:13:20.397: E/AndroidRuntime(2140): at java.lang.Thread.run(Thread.java:841)
02-02 02:13:20.397: E/AndroidRuntime(2140): Caused by: java.lang.NullPointerException
02-02 02:13:20.397: E/AndroidRuntime(2140): at com.qrme.quranmadeeasy.LessonActivity$getLesson.doInBackground(LessonActivity.java:259)
02-02 02:13:20.397: E/AndroidRuntime(2140): at com.qrme.quranmadeeasy.LessonActivity$getLesson.doInBackground(LessonActivity.java:1)
02-02 02:13:20.397: E/AndroidRuntime(2140): at android.os.AsyncTask$2.call(AsyncTask.java:288)
02-02 02:13:20.397: E/AndroidRuntime(2140): at java.util.concurrent.FutureTask.run(FutureTask.java:237)
02-02 02:13:20.397: E/AndroidRuntime(2140): ... 4 more
I am pointed out the error line in below code.
LessonActivity.java:
public class LessonActivity extends Activity implements OnItemClickListener {
AdapterLesson al; // creating object of AdapterLesson class
static ArrayList<Lesson> lessonList = null;
static ArrayList<Settings> settings = null;
int chapterId;
AdapterPages adapPage;
static ArrayList<Page> selectedpageList = null;
static ArrayList<Page> pageList = null;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
setContentView(R.layout.activity_lesson);
ParseAnalytics.trackAppOpened(getIntent());
if (getIntent() != null && getIntent().getExtras() != null) {
String chapt_id = getIntent().getExtras().getString("CHAPTER_ID");
chapter = getIntent().getExtras().getString("CHAPTER_NAME");
// txtChapterdetails.setText(chapter);
if (chapt_id != null && !chapt_id.equalsIgnoreCase("")) {
chapterId = Integer.parseInt(chapt_id);
}
}
initialize();
listLesson.setOnItemClickListener(this);
}
public class getLesson extends AsyncTask<String, Void, String> {
#Override
protected String doInBackground(String... params) {
lessonList = DatabaseQueryHelper.getInstance().getLesson(chapterId); --->259th line
return null;
}
#Override
protected void onPreExecute() {
super.onPreExecute();
}
#Override
protected void onPostExecute(String result) {
if(lessonList!=null)
{
if(lessonList.size()>0)
{
al = new AdapterLesson(LessonActivity.this, lessonList);
listLesson.setAdapter(al);
}
}
}
}
}
Anyone can help me with this.Thank you.
The problem is in DatabaseQueryHelper class. The method getInstance() is called before an instance has been initialized. So when you call it you get NullPointerException. Look for ways to implement a Singleton in order to correct this one.
Related
In database we have login details {"email":"nagu#gmail.com","pwd":"12345"}.By using REST services I got the URL, I need to validate the credentials and move to next screen. But unable to move to next screen so please help me
public class LoginScreen extends DIBaseActivty {
public static final int CONNECTION_TIMEOUT=10000;
public static final int READ_TIMEOUT=15000;
private EditText editTextUsername;
private EditText editTextPassword;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login_screen);
editTextUsername = (EditText)findViewById(R.id.emaiId);
editTextPassword = (EditText)findViewById(R.id.password);
}
public void buttonLogin (View arg0)
{
final String username = editTextUsername.getText().toString();
final String password = editTextPassword.getText().toString();
new TaskLogin().execute(username,password);
}
public class TaskLogin extends AsyncTask<String,String,String>
{
ProgressDialog pdLoading = new ProgressDialog(LoginScreen.this);
HttpURLConnection conn;
URL url = null;
#Override
protected void onPreExecute() {
super.onPreExecute();
pdLoading.setMessage("\t Loading...");
pdLoading.setCancelable(false);
pdLoading.show();
}
#Override
protected String doInBackground(String... params) {
try{
url = new URL("http://localhost:8080/RestSpring/DialysisInfo/login");
} catch (MalformedURLException e) {
e.printStackTrace();
return "exception";
}
try{
conn = (HttpURLConnection)url.openConnection();
conn.setReadTimeout(READ_TIMEOUT);
conn.setConnectTimeout(CONNECTION_TIMEOUT);
conn.setRequestMethod("POST");
conn.setDoInput(true);
conn.setDoOutput(true);
Uri.Builder builder = new Uri.Builder()
.appendQueryParameter("username",params[0])
.appendQueryParameter("password",params[1]);
String query = builder.build().getEncodedQuery();
OutputStream os = conn.getOutputStream();
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os,"UTF-8"));
writer.write(query);
writer.flush();
writer.close();
os.close();
conn.connect();
} catch (IOException e1)
{
e1.printStackTrace();
return "Exception";
}
try{
int response_code = conn.getResponseCode();
if(response_code==HttpURLConnection.HTTP_OK)
{
InputStream input = conn.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(input));
StringBuilder result = new StringBuilder();
String line;
while ((line= reader.readLine())!=null)
{
result.append(line);
}
return (result.toString());
} else { return ("unsuccessful");
}
} catch (IOException e)
{
e.printStackTrace();
return "Exception";
} finally {
conn.disconnect();
}
}
#Override
protected void onPostExecute(String result) {
pdLoading.dismiss();
if(result.equalsIgnoreCase("true"))
{
Intent intent = new Intent(LoginScreen.this,DIUserProfile.class);
startActivity(intent);
LoginScreen.this.finish();
}else if (result.equalsIgnoreCase("false"))
{
Toast.makeText(LoginScreen.this, "Invalid email or password", Toast.LENGTH_LONG).show();
} else if(result.equalsIgnoreCase("exception") || result.equalsIgnoreCase("unsuccessful"))
{
Toast.makeText(LoginScreen.this, "OOPs! Something went wrong. Connection Problem.", Toast.LENGTH_LONG).show();
}
}
}
}
Here is my error log
02-02 10:42:56.660 25016-27263/com.dialysis
W/System.err: java.net.ConnectException: failed to connect to localhost/127.0.0.1 (port 8080) after 10000ms: isConnected failed: ECONNREFUSED (Connection refused)
02-02 10:42:56.661 25016-27263/com.dialysis W/System.err: at libcore.io.IoBridge.isConnected(IoBridge.java:238)
02-02 10:42:56.661 25016-27263/com.dialysis W/System.err: at libcore.io.IoBridge.connectErrno(IoBridge.java:171)
02-02 10:42:56.661 25016-27263/com.dialysis W/System.err: at libcore.io.IoBridge.connect(IoBridge.java:122)
02-02 10:42:56.663 25016-27263/com.dialysis W/System.err: at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:183)
02-02 10:42:56.663 25016-27263/com.dialysis W/System.err: at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:456)
02-02 10:42:56.664 25016-27263/com.dialysis W/System.err: at java.net.Socket.connect(Socket.java:882)
02-02 10:42:56.664 25016-27263/com.dialysis W/System.err: at com.android.okhttp.internal.Platform.connectSocket(Platform.java:174)
02-02 10:42:56.664 25016-27263/com.dialysis W/System.err: at com.android.okhttp.Connection.connect(Connection.java:152)
02-02 10:42:56.665 25016-27263/com.dialysis W/System.err: at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:276)
02-02 10:42:56.665 25016-27263/com.dialysis W/System.err: at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:211)
02-02 10:42:56.665 25016-27263/com.dialysis W/System.err: at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:382)
02-02 10:42:56.665 25016-27263/com.dialysis W/System.err: at com.android.okhttp.internal.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:106)
02-02 10:42:56.666 25016-27263/com.dialysis W/System.err: at com.android.okhttp.internal.http.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:217)
02-02 10:42:56.666 25016-27263/com.dialysis W/System.err: at com.dialysis.renalteam.app.ui.activities.LoginScreen$TaskLogin.doInBackground(LoginScreen.java:86)
02-02 10:42:56.666 25016-27263/com.dialysis W/System.err: at com.dialysis.renalteam.app.ui.activities.LoginScreen$TaskLogin.doInBackground(LoginScreen.java:49)
02-02 10:42:56.666 25016-27263/com.dialysis W/System.err: at android.os.AsyncTask$2.call(AsyncTask.java:292)
02-02 10:42:56.666 25016-27263/com.dialysis W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:237)
02-02 10:42:56.666 25016-27263/com.dialysis W/System.err: at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
02-02 10:42:56.666 25016-27263/com.dialysis W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
02-02 10:42:56.666 25016-27263/com.dialysis W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
02-02 10:42:56.666 25016-27263/com.dialysis W/System.err: at java.lang.Thread.run(Thread.java:818)
02-02 10:42:56.667 25016-27263/com.dialysis W/System.err: Caused by: android.system.ErrnoException: isConnected failed: ECONNREFUSED (Connection refused)
02-02 10:42:56.667 25016-27263/com.dialysis W/System.err: at libcore.io.IoBridge.isConnected(IoBridge.java:223)
02-02 10:42:56.667 25016-27263/com.dialysis W/System.err: ... 20 more
02-02 10:42:56.714 25016-25071/com.dialysis W/EGL_emulation: eglSurfaceAttrib not implemented
02-02 10:42:56.714 25016-25071/com.dialysis W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xb43cbb00, error=EGL_SUCCESS
02-02 10:42:57.143 25016-25071/com.dialysis W/EGL_emulation: eglSurfaceAttrib not implemented
02-02 10:42:57.144 25016-25071/com.dialysis W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xb43cbd20, error=EGL_SUCCESS
02-02 10:52:41.787 25016-25030/com.dialysis W/art: Suspending all threads took: 5.515ms
From your logcat:
java.net.ConnectException: failed to connect to localhost/127.0.0.1 (port 8080) after 10000ms: isConnected failed: ECONNREFUSED (Connection refused)
Your Android app failed to connect to the server. Set debug breakpoints and check the following:
Url is correct
Method name is correct
Parameters key and value are correct
Server is working fine or not
Since you have not specified you are connected to a server from the device or emulator so I guess you are using your application in the emulator.
If you are referring your localhost on your system from the Android emulator then you have to use http://10.0.2.2:8080/ Because Android emulator runs in a Virtual Machine therefore here 127.0.0.1 or localhost will be emulator's own loopback address.
Replace: url = http://localhost:8080/RestSpring/DialysisInfo/login"
With : url = "http://10.0.2.2:8080/RestSpring/DialysisInfo/login"
Error Occured white retriving Bitmap In AsyncTask process the Logcat log is below,
please tell me how to clear this Error
I am beginner to android help me
thanks in advance
10-14 18:09:19.380 14124-16035/com.fragments D/dalvikvm﹕ GC_FOR_ALLOC freed 747K, 4% free 37438K/38855K, paused 191ms, total 193ms
10-14 18:09:19.400 14124-16035/com.fragments I/dalvikvm-heap﹕ Forcing collection of SoftReferences for 14155792-byte allocation
10-14 18:09:19.490 14124-16035/com.fragments D/dalvikvm﹕ GC_BEFORE_OOM freed 15K, 4% free 37422K/38855K, paused 91ms, total 91ms
10-14 18:09:19.490 14124-16035/com.fragments E/dalvikvm-heap﹕ Out of memory on a 14155792-byte allocation.
10-14 18:09:19.490 14124-16035/com.fragments I/dalvikvm﹕ "AsyncTask #4" prio=5 tid=16 RUNNABLE
10-14 18:09:19.490 14124-16035/com.fragments I/dalvikvm﹕ | group="main" sCount=0 dsCount=0 obj=0x432d6fc0 self=0x4d7c1fe8
10-14 18:09:19.490 14124-16035/com.fragments I/dalvikvm﹕ | sysTid=16035 nice=10 sched=3/0 cgrp=[fopen-error:2] handle=1300340400
10-14 18:09:19.490 14124-16035/com.fragments I/dalvikvm﹕ | schedstat=( 0 0 0 ) utm=15 stm=3 core=0
10-14 18:09:19.490 14124-16035/com.fragments I/dalvikvm﹕ at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
10-14 18:09:19.500 14124-16035/com.fragments I/dalvikvm﹕ at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:663)
10-14 18:09:19.500 14124-16035/com.fragments I/dalvikvm﹕ at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:735)
10-14 18:09:19.510 14124-16035/com.fragments I/dalvikvm﹕ at com.fragments.NewsListAdapter$ImageLoader.doInBackground(NewsListAdapter.java:128)
10-14 18:09:19.520 14124-16035/com.fragments I/dalvikvm﹕ at com.fragments.NewsListAdapter$ImageLoader.doInBackground(NewsListAdapter.java:112)
10-14 18:09:19.520 14124-16035/com.fragments I/dalvikvm﹕ at android.os.AsyncTask$2.call(AsyncTask.java:287)
10-14 18:09:19.530 14124-16035/com.fragments I/dalvikvm﹕ at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
10-14 18:09:19.530 14124-16035/com.fragments I/dalvikvm﹕ at java.util.concurrent.FutureTask.run(FutureTask.java:137)
10-14 18:09:19.530 14124-16035/com.fragments I/dalvikvm﹕ at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
10-14 18:09:19.530 14124-16035/com.fragments I/dalvikvm﹕ at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
10-14 18:09:19.530 14124-16035/com.fragments I/dalvikvm﹕ at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
10-14 18:09:19.530 14124-16035/com.fragments I/dalvikvm﹕ at java.lang.Thread.run(Thread.java:856)
10-14 18:09:19.530 14124-16035/com.fragments I/dalvikvm﹕ [ 10-14 18:09:19.530 14124:14133 W/SQLiteConnectionPool ]
A SQLiteConnection object for database '+data+data+com_fragments+databases+news_db' was leaked! Please fix your application to end transactions in progress properly and to close the database when it is no longer needed.
10-14 18:09:19.530 14124-14133/com.fragments D/AbsListView﹕ [unregisterDoubleTapMotionListener]
10-14 18:09:19.530 14124-14133/com.fragments I/MotionRecognitionManager﹕ .unregisterListener : / listener count = 0->0, ubvf 9budiwrd5ordgfl5BakTrklMrfo$,#,+)de/a(
10-14 18:09:19.560 14124-16035/com.fragments D/skia﹕ --- decoder->decode returned false
10-14 18:09:19.580 14124-16035/com.fragments W/dalvikvm﹕ threadid=16: thread exiting with uncaught exception (group=0x41ccd2b8)
10-14 18:09:19.740 14124-16035/com.fragments E/AndroidRuntime﹕ FATAL EXCEPTION: AsyncTask #4
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:856)
Caused by: java.lang.OutOfMemoryError
at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:663)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:735)
at com.fragments.NewsListAdapter$ImageLoader.doInBackground(NewsListAdapter.java:128)
at com.fragments.NewsListAdapter$ImageLoader.doInBackground(NewsListAdapter.java:112)
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:856)
10-14 18:09:28.740 14124-14124/com.fragments D/AndroidRuntime﹕ Shutting down VM
10-14 18:09:28.740 14124-14124/com.fragments W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x41ccd2b8)
10-14 18:09:28.740 14124-14124/com.fragments I/Process﹕ Sending signal. PID: 14124 SIG: 9
Update:
This is my AsyncTask class
private class ImageLoader extends AsyncTask<NewsAndImages, Void, NewsAndImages> {
#Override
protected NewsAndImages doInBackground(NewsAndImages... params) {
NewsAndImages container = params[0];
News news = container.news;
try {
if (container.position > 0) {
InputStream in = (InputStream) new URL(news.getImage150()).getContent();
Bitmap bitmap = BitmapFactory.decodeStream(in);
news.setBitmap(bitmap);
in.close();
container.bitmap = bitmap;
return container;
} else {
InputStream in = (InputStream) new URL(news.getRealImage()).getContent();
Bitmap bitmap = BitmapFactory.decodeStream(in);
news.setBitmap(bitmap);
in.close();
container.bitmap = bitmap;
return container;
}
} catch (Exception e) {
Log.v("LOGTAG", e + " streaming pic"+news.getImage150());
}
return null;
}
#Override
protected void onPostExecute(NewsAndImages newsAndImages) {
try {
if (newsAndImages.position > 0) {
ImageView imageView = (ImageView) newsAndImages.view.findViewById(R.id.newsListImage);
imageView.setImageBitmap(newsAndImages.bitmap);
newsAndImages.news.setBitmap(newsAndImages.bitmap);
}else {
ImageView imageView = (ImageView) newsAndImages.view.findViewById(R.id.newsHeadLineImage);
imageView.setImageBitmap(newsAndImages.bitmap);
newsAndImages.news.setBitmap(newsAndImages.bitmap);
}
} catch (Exception e) {
Log.v("LOGTAG", e + " post exe");
}
}
}
Now Tell me what to do...
Apparently your method doInBackground cant process your image. Do you have other images process in your app at all? Also, I recommend you to use this:
bitmap.recycle();
bitmap = null;
This will assure the bitmap is garbage collected. If you don't recycle your bitmaps you will have an out of memory exception
Don't set bitmap inside doInBackground. rather return new downloaded bitmap and set only inside onPostExecute.
you set bitmap twice right now so remove from doInBackground and recycle after use.
update code
private class ImageLoader extends AsyncTask<String, Void, Bitmap> {
#Override
protected Bitmap doInBackground(NewsAndImages... params) {
NewsAndImages container = params[0];
News news = container.news;
try {
if (container.position > 0) {
InputStream in = (InputStream) new URL(news.getImage150()).getContent();
Bitmap bitmap = BitmapFactory.decodeStream(in);
in.close();
return bitmap;
} else {
InputStream in = (InputStream) new URL(news.getRealImage()).getContent();
Bitmap bitmap = BitmapFactory.decodeStream(in);
in.close();
return bitmap;
}
} catch (Exception e) {
Log.v("LOGTAG", e + " streaming pic"+news.getImage150());
}
return null;
}
#Override
protected void onPostExecute(Bitmap bitmap) {
try {
if (bitmap !=null) {
ImageView imageView = (ImageView) newsAndImages.view.findViewById(R.id.newsListImage);
imageView.setImageBitmap(bitmap);
newsAndImages.news.setBitmap(bitmap);
}else {
ImageView imageView = (ImageView) newsAndImages.view.findViewById(R.id.newsHeadLineImage);
imageView.setImageBitmap(bitmap);
newsAndImages.news.setBitmap(bitmap);
}
bitmap.recycle();
} catch (Exception e) {
Log.v("LOGTAG", e + " post exe");
}
}
}
It Works...
By Using LruCache
private class ImageLoader extends AsyncTask<NewsAndImages, Void, NewsAndImages> {
#Override
protected NewsAndImages doInBackground(NewsAndImages... params) {
NewsAndImages container = params[0];
News news = container.news;
try {
if (container.position > 0) {
InputStream in = (InputStream) new URL(news.getImage150()).getContent();
Bitmap bitmap = BitmapFactory.decodeStream(in);
news.setBitmap(bitmap);
in.close();
container.bitmap = bitmap;
return container;
} else {
InputStream in = (InputStream) new URL(news.getRealImage()).getContent();
Bitmap bitmap = BitmapFactory.decodeStream(in);
news.setBitmap(bitmap);
in.close();
container.bitmap = bitmap;
return container;
}
} catch (Exception e) {
Log.v("LOGTAG", e + " streaming pic" + news.getImage150());
}
return null;
}
#Override
protected void onPostExecute(NewsAndImages newsAndImages) {
try {
if (newsAndImages.position > 0) {
ImageView imageView = (ImageView) newsAndImages.view.findViewById(R.id.newsListImage);
imageView.setImageBitmap(newsAndImages.bitmap);
imageCache.put(newsAndImages.news.getNews_id(),newsAndImages.bitmap);
} else {
ImageView imageView = (ImageView) newsAndImages.view.findViewById(R.id.newsHeadLineImage);
imageView.setImageBitmap(newsAndImages.bitmap);
imageCache.put(newsAndImages.news.getNews_id(),newsAndImages.bitmap);
}
} catch (Exception e) {
Log.i(NewsDBOpenHelper.LOGTAG, e + " onPostExecute");
}
}
}
i am totally new to android ..and i was trying a tutorial i found online.basic aim is to retrieve data from the database and display it. I am not able to execute it .I have attached the code and error log.It would be a great help if anyone can rectify the error.
<package com.example.androidhive;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.apache.http.NameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.ListActivity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
public class AllProductsActivity extends ListActivity {
// Progress Dialog
private ProgressDialog pDialog;
// Creating JSON Parser object
JSONParser jParser = new JSONParser();
ArrayList<HashMap<String, String>> productsList;
// url to get all products list
private static String url_all_products = "192.168.0.1/android_connect/get_all_products.php";
// JSON Node names
private static final String TAG_SUCCESS = "success";
private static final String TAG_PRODUCTS = "products";
private static final String TAG_PID = "pid";
private static final String TAG_NAME = "name";
// products JSONArray
JSONArray products = null;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.all_products);
// Hashmap for ListView
productsList = new ArrayList<HashMap<String, String>>();
// Loading products in Background Thread
new LoadAllProducts().execute();
// Get listview
ListView lv = getListView();
// on seleting single product
// launching Edit Product Screen
lv.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// getting values from selected ListItem
String pid = ((TextView) view.findViewById(R.id.pid)).getText()
.toString();
// Starting new intent
Intent in = new Intent(getApplicationContext(),
EditProductActivity.class);
// sending pid to next activity
in.putExtra(TAG_PID, pid);
// starting new activity and expecting some response back
startActivityForResult(in, 100);
}
});
}
// Response from Edit Product Activity
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// if result code 100
if (resultCode == 100) {
// if result code 100 is received
// means user edited/deleted product
// reload this screen again
Intent intent = getIntent();
finish();
startActivity(intent);
}
}
/**
* Background Async Task to Load all product by making HTTP Request
* */
class LoadAllProducts extends AsyncTask<String, String, String> {
/**
* Before starting background thread Show Progress Dialog
* */
#Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(AllProductsActivity.this);
pDialog.setMessage("Loading products. Please wait...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();
}
/**
* getting All products from url
* */
protected String doInBackground(String... args) {
// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
// getting JSON string from URL
JSONObject json = jParser.makeHttpRequest(url_all_products, "GET", params);
// Check your log cat for JSON reponse
Log.d("All Products: ", json.toString());
try {
// Checking for SUCCESS TAG
int success = json.getInt(TAG_SUCCESS);
if (success == 1) {
// products found
// Getting Array of Products
products = json.getJSONArray(TAG_PRODUCTS);
// looping through All Products
for (int i = 0; i < products.length(); i++) {
JSONObject c = products.getJSONObject(i);
// Storing each json item in variable
String id = c.getString(TAG_PID);
String name = c.getString(TAG_NAME);
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
// adding each child node to HashMap key => value
map.put(TAG_PID, id);
map.put(TAG_NAME, name);
// adding HashList to ArrayList
productsList.add(map);
}
} else {
// no products found
// Launch Add New product Activity
Intent i = new Intent(getApplicationContext(),
NewProductActivity.class);
// Closing all previous activities
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
/**
* After completing background task Dismiss the progress dialog
* **/
protected void onPostExecute(String file_url) {
// dismiss the dialog after getting all products
pDialog.dismiss();
// updating UI from Background Thread
runOnUiThread(new Runnable() {
public void run() {
/**
* Updating parsed JSON data into ListView
* */
ListAdapter adapter = new SimpleAdapter(
AllProductsActivity.this, productsList,
R.layout.list_item, new String[] { TAG_PID,
TAG_NAME},
new int[] { R.id.pid, R.id.name });
// updating listview
setListAdapter(adapter);
}
});
}`
Error
07-18 02:55:17.809: D/dalvikvm(2205): GC_FOR_ALLOC freed 56K, 5% free 2815K/2944K, paused 106ms, total 107ms
07-18 02:55:17.839: I/dalvikvm-heap(2205): Grow heap (frag case) to 5.628MB for 2949608-byte allocation
07-18 02:55:17.889: D/dalvikvm(2205): GC_FOR_ALLOC freed <1K, 3% free 5695K/5828K, paused 48ms, total 48ms
07-18 02:55:18.349: D/gralloc_goldfish(2205): Emulator without GPU emulation detected.
07-18 02:55:21.079: D/dalvikvm(2205): GC_FOR_ALLOC freed 19K, 2% free 6529K/6620K, paused 86ms, total 87ms
07-18 02:55:22.309: W/dalvikvm(2205): threadid=12: thread exiting with uncaught exception (group=0xb3a4fb90)
07-18 02:55:22.349: E/AndroidRuntime(2205): FATAL EXCEPTION: AsyncTask #1
07-18 02:55:22.349: E/AndroidRuntime(2205): Process: com.example.androidhive, PID: 2205
07-18 02:55:22.349: E/AndroidRuntime(2205): java.lang.RuntimeException: An error occured while executing doInBackground()
07-18 02:55:22.349: E/AndroidRuntime(2205): at android.os.AsyncTask$3.done(AsyncTask.java:300)
07-18 02:55:22.349: E/AndroidRuntime(2205): at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
07-18 02:55:22.349: E/AndroidRuntime(2205): at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
07-18 02:55:22.349: E/AndroidRuntime(2205): at java.util.concurrent.FutureTask.run(FutureTask.java:242)
07-18 02:55:22.349: E/AndroidRuntime(2205): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
07-18 02:55:22.349: E/AndroidRuntime(2205): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
07-18 02:55:22.349: E/AndroidRuntime(2205): at java.lang.Thread.run(Thread.java:841)
07-18 02:55:22.349: E/AndroidRuntime(2205): Caused by: java.lang.IllegalStateException: Target host must not be null, or set in parameters. scheme=null, host=null, path=192.168.0.1/android_connect/get_all_products.php
07-18 02:55:22.349: E/AndroidRuntime(2205): at org.apache.http.impl.client.DefaultRequestDirector.determineRoute(DefaultRequestDirector.java:591)
07-18 02:55:22.349: E/AndroidRuntime(2205): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:293)
07-18 02:55:22.349: E/AndroidRuntime(2205): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
07-18 02:55:22.349: E/AndroidRuntime(2205): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
07-18 02:55:22.349: E/AndroidRuntime(2205): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
07-18 02:55:22.349: E/AndroidRuntime(2205): at com.example.androidhive.JSONParser.makeHttpRequest(JSONParser.java:62)
07-18 02:55:22.349: E/AndroidRuntime(2205): at com.example.androidhive.AllProductsActivity$LoadAllProducts.doInBackground(AllProductsActivity.java:127)
07-18 02:55:22.349: E/AndroidRuntime(2205): at com.example.androidhive.AllProductsActivity$LoadAllProducts.doInBackground(AllProductsActivity.java:1)
07-18 02:55:22.349: E/AndroidRuntime(2205): at android.os.AsyncTask$2.call(AsyncTask.java:288)
07-18 02:55:22.349: E/AndroidRuntime(2205): at java.util.concurrent.FutureTask.run(FutureTask.java:237)
07-18 02:55:22.349: E/AndroidRuntime(2205): ... 3 more
07-18 02:55:22.819: I/Choreographer(2205): Skipped 362 frames! The application may be doing too much work on its main thread.
07-18 02:55:25.829: I/Choreographer(2205): Skipped 171 frames! The application may be doing too much work on its main thread.
07-18 02:55:30.059: E/WindowManager(2205): android.view.WindowLeaked: Activity com.example.androidhive.AllProductsActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{b40ada18 V.E..... R.....ID 0,0-461,175} that was originally added here
07-18 02:55:30.059: E/WindowManager(2205): at android.view.ViewRootImpl.<init>(ViewRootImpl.java:346)
07-18 02:55:30.059: E/WindowManager(2205): at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:248)
07-18 02:55:30.059: E/WindowManager(2205): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
07-18 02:55:30.059: E/WindowManager(2205): at android.app.Dialog.show(Dialog.java:286)
07-18 02:55:30.059: E/WindowManager(2205): at com.example.androidhive.AllProductsActivity$LoadAllProducts.onPreExecute(AllProductsActivity.java:117)
07-18 02:55:30.059: E/WindowManager(2205): at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:587)
07-18 02:55:30.059: E/WindowManager(2205): at android.os.AsyncTask.execute(AsyncTask.java:535)
07-18 02:55:30.059: E/WindowManager(2205): at com.example.androidhive.AllProductsActivity.onCreate(AllProductsActivity.java:57)
07-18 02:55:30.059: E/WindowManager(2205): at android.app.Activity.performCreate(Activity.java:5243)
07-18 02:55:30.059: E/WindowManager(2205): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
07-18 02:55:30.059: E/WindowManager(2205): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2140)
07-18 02:55:30.059: E/WindowManager(2205): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2226)
07-18 02:55:30.059: E/WindowManager(2205): at android.app.ActivityThread.access$700(ActivityThread.java:135)
07-18 02:55:30.059: E/WindowManager(2205): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1397)
07-18 02:55:30.059: E/WindowManager(2205): at android.os.Handler.dispatchMessage(Handler.java:102)
07-18 02:55:30.059: E/WindowManager(2205): at android.os.Looper.loop(Looper.java:137)
07-18 02:55:30.059: E/WindowManager(2205): at android.app.ActivityThread.main(ActivityThread.java:4998)
07-18 02:55:30.059: E/WindowManager(2205): at java.lang.reflect.Method.invokeNative(Native Method)
07-18 02:55:30.059: E/WindowManager(2205): at java.lang.reflect.Method.invoke(Method.java:515)
07-18 02:55:30.059: E/WindowManager(2205): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
07-18 02:55:30.059: E/WindowManager(2205): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593)
07-18 02:55:30.059: E/WindowManager(2205): at dalvik.system.NativeStart.main(Native Method)
07-18 02:55:30.059: I/Choreographer(2205): Skipped 217 frames! The application may be doing too much work on its main thread.
07-18 02:55:32.999: I/Process(2205): Sending signal. PID: 2205 SIG: 9
This exception message:
java.lang.IllegalStateException: Target host must not be n\
ull, or set in parameters. scheme=null, host=null, path=192.168.0.1/android_connect/get_all_products.php
tells me that the makeHttpRequest fails to identify the host parameter in the url you pass. So I really would go with #Titus advice and provide a full URL with http:// prefix (or whatever the protocol is). If the type of error changes you may have more then one error.
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
}
}
I am trying to set my AsyncTask returning a custom class type such as
AsyncTask<Void, Void, MyClass>
For this I have created a class User.
File: User.java
package com.asynctask.namespace;
import java.util.ArrayList;
public class User
{
private ArrayList<String> name;
public void addName(String value)
{
name.add(value);
}
public String getName(int pos)
{
return name.get(pos).toString();
}
}
In my main activity I have:
package com.asynctask.namespace;
import android.app.Activity;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.widget.TextView;
public class AsyncTaskExampleActivity extends Activity {
private TextView result;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.main);
result = new TextView(this);
setContentView(result);
new loadData().execute();
}
// --- Subclass --- //
private class loadData extends AsyncTask<Void, Void, User>
{
ProgressDialog progDialog;
User client = new User();
protected void onPreExecute()
{
progDialog = new ProgressDialog(AsyncTaskExampleActivity.this);
progDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progDialog.setMessage("Conectando a base de dados...");
progDialog.show();
}
protected User doInBackground(Void... args)
{
client.addName("testName");
return client;
}
protected void onPostExecute(User values)
{
progDialog.dismiss();
result.setText(values.getName(0));
}
}
}
I get the following Logcat errors:
04-02 13:45:05.683: W/dalvikvm(1056): threadid=15: thread exiting with uncaught exception (group=0x4001b188)
04-02 13:45:05.683: E/AndroidRuntime(1056): Uncaught handler: thread AsyncTask #1 exiting due to uncaught exception
04-02 13:45:05.783: E/AndroidRuntime(1056): java.lang.RuntimeException: An error occured while executing doInBackground()
04-02 13:45:05.783: E/AndroidRuntime(1056): at android.os.AsyncTask$3.done(AsyncTask.java:200)
04-02 13:45:05.783: E/AndroidRuntime(1056): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
04-02 13:45:05.783: E/AndroidRuntime(1056): at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
04-02 13:45:05.783: E/AndroidRuntime(1056): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
04-02 13:45:05.783: E/AndroidRuntime(1056): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
04-02 13:45:05.783: E/AndroidRuntime(1056): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
04-02 13:45:05.783: E/AndroidRuntime(1056): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
04-02 13:45:05.783: E/AndroidRuntime(1056): at java.lang.Thread.run(Thread.java:1096)
04-02 13:45:05.783: E/AndroidRuntime(1056): Caused by: java.lang.NullPointerException
04-02 13:45:05.783: E/AndroidRuntime(1056): at com.asynctask.namespace.User.addName(User.java:11)
04-02 13:45:05.783: E/AndroidRuntime(1056): at com.asynctask.namespace.AsyncTaskExampleActivity$loadData.doInBackground(AsyncTaskExampleActivity.java:39)
04-02 13:45:05.783: E/AndroidRuntime(1056): at com.asynctask.namespace.AsyncTaskExampleActivity$loadData.doInBackground(AsyncTaskExampleActivity.java:1)
04-02 13:45:05.783: E/AndroidRuntime(1056): at android.os.AsyncTask$2.call(AsyncTask.java:185)
04-02 13:45:05.783: E/AndroidRuntime(1056): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
04-02 13:45:05.783: E/AndroidRuntime(1056): ... 4 more
04-02 13:45:05.903: I/dalvikvm(1056): threadid=7: reacting to signal 3
04-02 13:45:06.093: I/dalvikvm(1056): Wrote stack trace to '/data/anr/traces.txt'
Any ideas why?
Your help is much appreciated!
Happy coding!
You have to initialize the array list name before you use it. Try this:
package com.asynctask.namespace;
import java.util.ArrayList;
public class User
{
// initialize before use
private ArrayList<String> name = new ArrayList<String>();
public void addName(String value)
{
name.add(value);
}
public String getName(int pos)
{
return name.get(pos).toString();
}
}