Hi how to print file list...now I trying to print my file list...but I am its not printing...please help me....
This is my coding:
package ImageViewExample.ImageViewExample;
import java.io.File;
import java.util.ArrayList;
import android.R.string;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.GridView;
//import android.widget.GridView;
import android.widget.ImageView;
import android.widget.AdapterView.OnItemClickListener;
public class ImageViewExample extends Activity {
/** Called when the activity is first created. */
private Cursor imagecursor, actualimagecursor;
private int image_column_index, actual_image_column_index;
GridView imagegrid;
private int count;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
init_phone_image_grid();
}
private void init_phone_image_grid() {
String[] img = { MediaStore.Images.Thumbnails._ID };
imagecursor = managedQuery(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI,
img, null,null,
MediaStore.Images.Thumbnails.IMAGE_ID + "");
System.out.println("cursor"+managedQuery(MediaStore.Images
.Thumbnails.EXTERNAL_CONTENT_URI, img, null,null,
MediaStore.Images.Thumbnails.IMAGE_ID + ""));
image_column_index =
imagecursor.getColumnIndexOrThrow(MediaStore.Images.Thumbnails._ID);
System.out.println("index"+imagecursor.getColumnIndexOrThrow(MediaStore
.Images.Thumbnails._ID));
count = imagecursor.getCount();
System.out.println("image"+count);
imagegrid = (GridView) findViewById(R.id.PhoneImageGrid);
imagegrid.setAdapter(new ImAdapterh(this));
imagegrid.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView parent, View v,int position, long id)
{
System.gc();
String[] proj = { MediaStore.Images.Media.DATA };
actualimagecursor = managedQuery(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
proj,null, null, null);
// System.out.println("doubt"+managedQuery(MediaStore
.Images.Media.EXTERNAL_CONTENT_URI, proj,null, null, null));
actual_image_column_index =
actualimagecursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
actualimagecursor.moveToPosition(position);
String i = actualimagecursor.getString(actual_image_column_index);
System.gc();
Intent intent = new Intent(getApplicationContext(), ViewImage.class);
intent.putExtra("filename", i);
startActivity(intent);
}
});
}
public class ImAdapterh extends BaseAdapter{
File dir=new File(Environment.getExternalStorageDirectory(),"/myImages/");
int count=dir.list().length;
String[] fileNames = dir.list();
private Context mContext;
public ImAdapterh(Context c) {
mContext = c;
}
public int getCount() {
return count;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return 0;
}
// create a new ImageView for each item referenced by the Adapter
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView = null;
for(String bitmapFileName : fileNames)
{
if (convertView == null)
{ // if it's not recycled, initialize some attributes
imageView = new ImageView(mContext);
imageView.setLayoutParams(new Gallery.LayoutParams(85, 85));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(8, 8, 8, 8);
Bitmap bmp = BitmapFactory.decodeFile(dir.getPath() + "/" +
bitmapFileName);
imageView.setImageBitmap(bmp);
}else
{
imageView = (ImageView) convertView;
}
} return imageView;
}
}}
I wish to print my file list:
File dir=new File(Environment.getExternalStorageDirectory(),"/myImages/");
int count=dir.list().length;
String[] fileNames = dir.list();
logcat error:
05-05 22:39:42.147: DEBUG/dalvikvm(739): GC_EXTERNAL_ALLOC freed 1035 objects / 68800
bytes in 141ms
05-05 22:39:42.497: DEBUG/dalvikvm(739): GC_EXTERNAL_ALLOC freed 418 objects / 217344
bytes in 118ms
05-05 22:39:42.568: DEBUG/AndroidRuntime(739): Shutting down VM
05-05 22:39:42.578: WARN/dalvikvm(739): threadid=1: thread exiting with uncaught
exception (group=0x4001d800)
05-05 22:39:42.608: ERROR/AndroidRuntime(739): FATAL EXCEPTION: main
05-05 22:39:42.608: ERROR/AndroidRuntime(739): java.lang.ClassCastException:
android.widget.Gallery$LayoutParams
05-05 22:39:42.608: ERROR/AndroidRuntime(739): at
android.widget.GridView.onMeasure(GridView.java:934)
05-05 22:39:42.608: ERROR/AndroidRuntime(739): at
android.view.View.measure(View.java:8171)
05-05 22:39:42.608: ERROR/AndroidRuntime(739): at
android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
05-05 22:39:42.608: ERROR/AndroidRuntime(739): at
android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1012)
05-05 22:39:42.608: ERROR/AndroidRuntime(739): at
android.widget.LinearLayout.measureVertical(LinearLayout.java:381)
05-05 22:39:42.608: ERROR/AndroidRuntime(739): at
android.widget.LinearLayout.onMeasure(LinearLayout.java:304)
05-05 22:39:42.608: ERROR/AndroidRuntime(739): at
android.view.View.measure(View.java:8171)
05-05 22:39:42.608: ERROR/AndroidRuntime(739): at
android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
05-05 22:39:42.608: ERROR/AndroidRuntime(739): at
android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
05-05 22:39:42.608: ERROR/AndroidRuntime(739): at
android.view.View.measure(View.java:8171)
05-05 22:39:42.608: ERROR/AndroidRuntime(739): at
android.widget.LinearLayout.measureVertical(LinearLayout.java:526)
05-05 22:39:42.608: ERROR/AndroidRuntime(739): at
android.widget.LinearLayout.onMeasure(LinearLayout.java:304)
05-05 22:39:42.608: ERROR/AndroidRuntime(739): at
android.view.View.measure(View.java:8171)
05-05 22:39:42.608: ERROR/AndroidRuntime(739): at
android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
05-05 22:39:42.608: ERROR/AndroidRuntime(739): at
android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
05-05 22:39:42.608: ERROR/AndroidRuntime(739): at
android.view.View.measure(View.java:8171)
05-05 22:39:42.608: ERROR/AndroidRuntime(739): at
android.view.ViewRoot.performTraversals(ViewRoot.java:801)
05-05 22:39:42.608: ERROR/AndroidRuntime(739): at
android.view.ViewRoot.handleMessage(ViewRoot.java:1727)
05-05 22:39:42.608: ERROR/AndroidRuntime(739): at
android.os.Handler.dispatchMessage(Handler.java:99)
05-05 22:39:42.608: ERROR/AndroidRuntime(739): at
android.os.Looper.loop(Looper.java:123)
05-05 22:39:42.608: ERROR/AndroidRuntime(739): at
android.app.ActivityThread.main(ActivityThread.java:4627)
05-05 22:39:42.608: ERROR/AndroidRuntime(739): at
java.lang.reflect.Method.invokeNative(Native Method)
05-05 22:39:42.608: ERROR/AndroidRuntime(739): at
java.lang.reflect.Method.invoke(Method.java:521)
05-05 22:39:42.608: ERROR/AndroidRuntime(739): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-05 22:39:42.608: ERROR/AndroidRuntime(739): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-05 22:39:42.608: ERROR/AndroidRuntime(739): at
dalvik.system.NativeStart.main(Native Method)
05-05 22:39:42.638: WARN/ActivityManager(64): Force finishing activity
ImageViewExample.ImageViewExample/.ImageViewExample
05-05 22:39:43.157: WARN/ActivityManager(64): Activity pause timeout for
HistoryRecord{43fb0c88 ImageViewExample.ImageViewExample/.ImageViewExample}
This will print your files to the logcat, but note that this code has to be located in some method, not just in the class.
for (String fName : fileNames)
{
Log.i("MYAPPTAG", fName);
}
Related
I would like to create applications forming charts based on data from parse.com. I have read some examples and tutorials but still have problem with displaying charts. Below is my code:
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.util.Log;
import com.parse.GetCallback;
import com.parse.ParseException;
import com.parse.ParseObject;
import com.parse.ParseQuery;
import org.achartengine.ChartFactory;
import org.achartengine.GraphicalView;
import org.achartengine.chart.PointStyle;
import org.achartengine.model.XYMultipleSeriesDataset;
import org.achartengine.model.XYSeries;
import org.achartengine.renderer.XYMultipleSeriesRenderer;
import org.achartengine.renderer.XYSeriesRenderer;
import java.util.ArrayList;
public class LineGraph {
public ArrayList<Integer> dataArray;
XYMultipleSeriesDataset dataset;
XYMultipleSeriesRenderer renderer;
public static boolean ClickEnabled = true;
public Intent getIntent(Context context) {
ArrayList<Integer> y = this.dataArray;
XYSeries seriesY = new XYSeries("Y");
for (int i = 0; i < y.size(); i++) {
seriesY.add(i, y.get(i));
}
dataset = new XYMultipleSeriesDataset();
dataset.addSeries(seriesY);
renderer.setPanEnabled(true, false);
renderer.setClickEnabled(ClickEnabled);
renderer.setBackgroundColor(Color.WHITE);
renderer.setApplyBackgroundColor(true);
renderer.setChartTitle("Simple data");
renderer.setAxesColor(Color.BLACK);
XYMultipleSeriesRenderer mRenderer = new XYMultipleSeriesRenderer();
XYSeriesRenderer renderer = new XYSeriesRenderer();
renderer.setColor(Color.RED);
renderer.setPointStyle(PointStyle.DIAMOND);
mRenderer.addSeriesRenderer(renderer);
Intent intent = ChartFactory.getLineChartIntent(context, dataset, mRenderer, "Line Graph Title");
return intent;
}
public void getData() {
ParseQuery<ParseObject> query = ParseQuery.getQuery("Counters_data");
query.getInBackground("lxFzCTeOcl", new GetCallback<ParseObject>() {
public void done(ParseObject parseObject, ParseException e) {
if (e == null) {
String object = parseObject.getString("value");
Integer objectValue = Integer.parseInt(object);
if (dataArray == null) {
dataArray = new ArrayList<Integer>();
dataArray.add(objectValue);
}
} else {
Log.d("score", "Error: " + e.getMessage());
}
}
});
}
}
And there is how I invoke charts:
public void lineGraphHandler(View view) {
LineGraph line = new LineGraph();
line.getData();
Intent lineIntent = line.getIntent(this);
startActivity(lineIntent);
}
And XML part:
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/counters"
android:onClick="lineGraphHandler"
android:text="Charts"
android:id="#+id/charts"/>
There is my logcat:
03-26 08:42:13.096 1229-1229/com.example.tst D/dalvikvm﹕ Late-enabling
CheckJNI 03-26 08:42:13.487 1229-1229/com.example.tst D/libEGL﹕ loaded
/system/lib/egl/libEGL_genymotion.so 03-26 08:42:13.491
1229-1229/com.example.tst D/﹕ HostConnection::get() New Host
Connection established 0xb94f4270, tid 1229 03-26 08:42:13.551
1229-1229/com.example.tst D/libEGL﹕ loaded
/system/lib/egl/libGLESv1_CM_genymotion.so 03-26 08:42:13.551
1229-1229/com.example.tst D/libEGL﹕ loaded
/system/lib/egl/libGLESv2_genymotion.so 03-26 08:42:14.035
1229-1229/com.example.tst W/EGL_genymotion﹕ eglSurfaceAttrib not
implemented 03-26 08:42:14.039 1229-1229/com.example.tst
E/OpenGLRenderer﹕ Getting MAX_TEXTURE_SIZE from GradienCache 03-26
08:42:14.043 1229-1229/com.example.tst E/OpenGLRenderer﹕
MAX_TEXTURE_SIZE: 4096 03-26 08:42:14.055 1229-1229/com.example.tst
E/OpenGLRenderer﹕ Getting MAX_TEXTURE_SIZE from
Caches::initConstraints() 03-26 08:42:14.063 1229-1229/com.example.tst
E/OpenGLRenderer﹕ MAX_TEXTURE_SIZE: 4096 03-26 08:42:14.063
1229-1229/com.example.tst D/OpenGLRenderer﹕ Enabling debug mode 0
03-26 08:42:50.327 1229-1229/com.example.tst D/dalvikvm﹕ GC_FOR_ALLOC
freed 200K, 8% free 2975K/3228K, paused 10ms, total 13ms 03-26
08:42:51.675 1229-1229/com.example.tst D/dalvikvm﹕ GC_FOR_ALLOC freed
431K, 14% free 3056K/3540K, paused 22ms, total 28ms 03-26 08:42:52.043
1229-1229/com.example.tst W/EGL_genymotion﹕ eglSurfaceAttrib not
implemented 03-26 08:42:53.543 1229-1229/com.example.tst
I/Choreographer﹕ Skipped 89 frames! The application may be doing too
much work on its main thread. 03-26 08:43:01.747
1229-1229/com.example.tst D/AndroidRuntime﹕ Shutting down VM 03-26
08:43:01.747 1229-1229/com.example.tst W/dalvikvm﹕ threadid=1: thread
exiting with uncaught exception (group=0xa4d8fb20) 03-26 08:43:01.767
1229-1229/com.example.tst E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.tst, PID: 1229 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.tst.LineGraph.getIntent(LineGraph.java:36) at
com.example.tst.MainActivity.lineGraphHandler(MainActivity.java:44)
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) 03-26 08:43:04.507
1229-1229/com.example.tst I/Process﹕ Sending signal. PID: 1229 SIG: 9
I don't understand where the problem is. My app starts but crashes immediately when I push "chart" button. Is it data type of problem or because I misunderstand something?
Thank you in advance.
I tried like this but still got crash:
public void done(ParseObject parseObject, ParseException e) {
if (e == null) {
String object = parseObject.getString("value");
Integer objectValue = Integer.parseInt(object);
if (dataArray == null) {
dataArray = new ArrayList<Integer>();
dataArray.add(objectValue);
ArrayList<Integer> y = dataArray;
XYSeries seriesY = new XYSeries("Y");
for (int i = 0; i < y.size(); i++) {
seriesY.add(i, y.get(i));
dataset = new XYMultipleSeriesDataset();
dataset.addSeries(seriesY);
}
}
Your getData() retrieves the data asynchronously. dataArray won't be initialized immediately when you call getIntent().
Wait for the async operation to complete before using the data there. For example, call the code requiring that data from the done() callback.
I'm trying to learn to build Android apps. This is my very first attempt. Everything was okay and when I would get to this activity (this is when someone would select rock) I could have it display Hello World. I tried to develop rules for winning and losing but whenever I select rock my app just crashes. Please take a look.
package ro.pa.sc;
import java.util.Random;
import android.annotation.TargetApi;
import android.app.Activity;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.NavUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
public class Rockvs extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
randombox();
setContentView(R.layout.activity_rockvs);
// Show the Up button in the action bar.
setupActionBar();
}
/**
* Set up the {#link android.app.ActionBar}, if the API is available.
*/
#TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void setupActionBar() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
getActionBar().setDisplayHomeAsUpEnabled(true);
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.rockvs, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
// This ID represents the Home or Up button. In the case of this
// activity, the Up button is shown. Use NavUtils to allow users
// to navigate up one level in the application structure. For
// more details, see the Navigation pattern on Android Design:
//
// http://developer.android.com/design/patterns/navigation.html#up- vs-back
//
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}
public void randombox()
{
Random r = new Random();
int pickedNumber=r.nextInt(2);
if (pickedNumber==1) {
win();
} else if (pickedNumber==2) {
lose();
} else if (pickedNumber==0){
tie();
}
}
public void win() {
String message = "Computer picked Scissors! You Won!";
TextView textView = new TextView(this);
textView.setTextSize(40);
textView.setText(message);
setContentView(textView);
}
public void lose() {
String message = "Computer picked Paper! You Lose!";
TextView textView = new TextView(this);
textView.setTextSize(40);
textView.setText(message);
setContentView(textView);
}
public void tie() {
String message = "Computer picked Rock! It's a Tie!";
TextView textView = new TextView(this);
textView.setTextSize(40);
textView.setText(message);
setContentView(textView);
}
}
Logcat output:
05-05 19:22:46.571: D/ActivityThread(15646): setTargetHeapUtilization:0.25
05-05 19:22:46.571: D/ActivityThread(15646): setTargetHeapIdealFree:8388608
05-05 19:22:46.581: D/ActivityThread(15646): setTargetHeapConcurrentStart:2097152
05-05 19:22:46.722: I/Adreno200-EGL(15646): <qeglDrvAPI_eglInitialize:269>: EGL 1.4 QUALCOMM build: (CL2803123)
05-05 19:22:46.722: I/Adreno200-EGL(15646): Build Date: 11/28/12 Wed
05-05 19:22:46.722: I/Adreno200-EGL(15646): Local Branch: D1L_JB_1736J_Disable_CPUMempool
05-05 19:22:46.722: I/Adreno200-EGL(15646): Remote Branch:
05-05 19:22:46.722: I/Adreno200-EGL(15646): Local Patches:
05-05 19:22:46.722: I/Adreno200-EGL(15646): Reconstruct Branch:
05-05 19:22:48.233: W/dalvikvm(15646): threadid=1: thread exiting with uncaught exception (group=0x4126c438)
05-05 19:22:48.253: E/AndroidRuntime(15646): FATAL EXCEPTION: main
05-05 19:22:48.253: E/AndroidRuntime(15646): java.lang.RuntimeException: Unable to start activity ComponentInfo{ro.pa.sc/ro.pa.sc.Rockvs}: android.view.InflateException: Binary XML file line #11: Error inflating class <unknown>
05-05 19:22:48.253: E/AndroidRuntime(15646): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2080)
05-05 19:22:48.253: E/AndroidRuntime(15646): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2105)
05-05 19:22:48.253: E/AndroidRuntime(15646): at android.app.ActivityThread.access$600(ActivityThread.java:137)
05-05 19:22:48.253: E/AndroidRuntime(15646): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1203)
05-05 19:22:48.253: E/AndroidRuntime(15646): at android.os.Handler.dispatchMessage(Handler.java:99)
05-05 19:22:48.253: E/AndroidRuntime(15646): at android.os.Looper.loop(Looper.java:137)
05-05 19:22:48.253: E/AndroidRuntime(15646): at android.app.ActivityThread.main(ActivityThread.java:4904)
05-05 19:22:48.253: E/AndroidRuntime(15646): at java.lang.reflect.Method.invokeNative(Native Method)
05-05 19:22:48.253: E/AndroidRuntime(15646): at java.lang.reflect.Method.invoke(Method.java:511)
05-05 19:22:48.253: E/AndroidRuntime(15646): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
05-05 19:22:48.253: E/AndroidRuntime(15646): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
05-05 19:22:48.253: E/AndroidRuntime(15646): at dalvik.system.NativeStart.main(Native Method)
05-05 19:22:48.253: E/AndroidRuntime(15646): Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class <unknown>
05-05 19:22:48.253: E/AndroidRuntime(15646): at android.view.LayoutInflater.createView(LayoutInflater.java:613)
05-05 19:22:48.253: E/AndroidRuntime(15646): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
05-05 19:22:48.253: E/AndroidRuntime(15646): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
05-05 19:22:48.253: E/AndroidRuntime(15646): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
05-05 19:22:48.253: E/AndroidRuntime(15646): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
05-05 19:22:48.253: E/AndroidRuntime(15646): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
05-05 19:22:48.253: E/AndroidRuntime(15646): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
05-05 19:22:48.253: E/AndroidRuntime(15646): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
05-05 19:22:48.253: E/AndroidRuntime(15646): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:321)
05-05 19:22:48.253: E/AndroidRuntime(15646): at android.app.Activity.setContentView(Activity.java:2087)
05-05 19:22:48.253: E/AndroidRuntime(15646): at ro.pa.sc.Rockvs.onCreate(Rockvs.java:20)
05-05 19:22:48.253: E/AndroidRuntime(15646): at android.app.Activity.performCreate(Activity.java:5232)
05-05 19:22:48.253: E/AndroidRuntime(15646): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1082)
05-05 19:22:48.253: E/AndroidRuntime(15646): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2044)
05-05 19:22:48.253: E/AndroidRuntime(15646): ... 11 more
05-05 19:22:48.253: E/AndroidRuntime(15646): Caused by: java.lang.reflect.InvocationTargetException
05-05 19:22:48.253: E/AndroidRuntime(15646): at java.lang.reflect.Constructor.constructNative(Native Method)
05-05 19:22:48.253: E/AndroidRuntime(15646): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
05-05 19:22:48.253: E/AndroidRuntime(15646): at android.view.LayoutInflater.createView(LayoutInflater.java:587)
05-05 19:22:48.253: E/AndroidRuntime(15646): ... 24 more
05-05 19:22:48.253: E/AndroidRuntime(15646): Caused by: android.content.res.Resources$NotFoundException: File You picked Rock! I hope you win! from drawable resource ID #0x7f050009: .xml extension required
05-05 19:22:48.253: E/AndroidRuntime(15646): at android.content.res.Resources.loadColorStateList(Resources.java:2094)
05-05 19:22:48.253: E/AndroidRuntime(15646): at android.content.res.TypedArray.getColorStateList(TypedArray.java:342)
05-05 19:22:48.253: E/AndroidRuntime(15646): at android.widget.TextView.<init>(TextView.java:820)
05-05 19:22:48.253: E/AndroidRuntime(15646): at android.widget.TextView.<init>(TextView.java:489)
05-05 19:22:48.253: E/AndroidRuntime(15646): ... 27 more
XML File :
<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"
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=".Rockvs" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="#string/pickedrock"
android:textColor="#string/pickedrock"
android:textSize="25sp" />
</RelativeLayout>
In your XML, the line:
android:textColor="#string/pickedrock"
is not correct - it should point to a color resource, not a string.
I'm new android programmer, and I don't know how to set new text of TextView after call by OnTabChangeListener. I've tried a lot of ways but each time was displayed weird error.
Edit: (Lastest code)
MainActivity.java:
package com.RobsoN;
import android.app.Activity;
import android.app.TabActivity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.widget.TabHost;
import android.widget.TextView;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.TabHost.TabSpec;
public class MainActivity extends TabActivity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final TabHost tabHost = getTabHost();
Log.i("App","App initialization");
TabSpec start = tabHost.newTabSpec("Start");
start.setIndicator("Start", getResources().getDrawable(android.R.drawable.ic_menu_rotate));
Intent photosIntent = new Intent(this, Start.class);
start.setContent(photosIntent);
TabSpec settings = tabHost.newTabSpec("Ustawienia");
settings.setIndicator("Ustawienia", getResources().getDrawable(android.R.drawable.ic_menu_manage));
Intent songsIntent = new Intent(this, Settings.class);
settings.setContent(songsIntent);
TabSpec info = tabHost.newTabSpec("Informacje");
info.setIndicator("Informacje", getResources().getDrawable(android.R.drawable.ic_menu_help));
Intent videosIntent = new Intent(this, Other.class);
info.setContent(videosIntent);
// Adding all TabSpec to TabHost
tabHost.addTab(start);
tabHost.addTab(settings);
tabHost.addTab(info);
tabHost.setOnTabChangedListener(new OnTabChangeListener(){
public void onTabChanged(String tabId) {
if(tabId.equals("Informacje"))
{
Other child = (Other) getTabHost().getChildAt(0).getContext(); //Error here: 1 java.lang.ClassCastException: com.RobsoN.MainActivity 2 com.RobsoN.MainActivity$1.onTabChanged(MainActivity.java:50)
child.refreshInfo();
}
}});
}
}
Other.java:
package com.RobsoN;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class Other extends Activity {
Button button_update;
TextView stat_lastestappversion;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tab_other);
stat_lastestappversion = (TextView) findViewById(R.id.stat_lastestappversion);
button_update = (Button) findViewById(R.id.button_update);
button_update.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
}
});
}
public void refreshInfo()
{
stat_lastestappversion = (TextView) findViewById(R.id.stat_lastestappversion);
stat_lastestappversion.setText("TEST TEST 321");
}
}
Error:
05-05 13:00:59.845: E/AndroidRuntime(314): FATAL EXCEPTION: main
05-05 13:00:59.845: E/AndroidRuntime(314): java.lang.ClassCastException: com.RobsoN.MainActivity
05-05 13:00:59.845: E/AndroidRuntime(314): at com.RobsoN.MainActivity$1.onTabChanged(MainActivity.java:50)
05-05 13:00:59.845: E/AndroidRuntime(314): at android.widget.TabHost.invokeOnTabChangeListener(TabHost.java:356)
05-05 13:00:59.845: E/AndroidRuntime(314): at android.widget.TabHost.setCurrentTab(TabHost.java:341)
05-05 13:00:59.845: E/AndroidRuntime(314): at android.widget.TabHost$2.onTabSelectionChanged(TabHost.java:129)
05-05 13:00:59.845: E/AndroidRuntime(314): at android.widget.TabWidget$TabClickListener.onClick(TabWidget.java:453)
05-05 13:00:59.845: E/AndroidRuntime(314): at android.view.View.performClick(View.java:2408)
05-05 13:00:59.845: E/AndroidRuntime(314): at android.view.View$PerformClick.run(View.java:8816)
05-05 13:00:59.845: E/AndroidRuntime(314): at android.os.Handler.handleCallback(Handler.java:587)
05-05 13:00:59.845: E/AndroidRuntime(314): at android.os.Handler.dispatchMessage(Handler.java:92)
05-05 13:00:59.845: E/AndroidRuntime(314): at android.os.Looper.loop(Looper.java:123)
05-05 13:00:59.845: E/AndroidRuntime(314): at android.app.ActivityThread.main(ActivityThread.java:4627)
05-05 13:00:59.845: E/AndroidRuntime(314): at java.lang.reflect.Method.invokeNative(Native Method)
05-05 13:00:59.845: E/AndroidRuntime(314): at java.lang.reflect.Method.invoke(Method.java:521)
05-05 13:00:59.845: E/AndroidRuntime(314): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-05 13:00:59.845: E/AndroidRuntime(314): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-05 13:00:59.845: E/AndroidRuntime(314): at dalvik.system.NativeStart.main(Native Method)
as Luksprog says you can not use direct intialization of activity like you did in java. As far I can see you want to show a textview in a child activity of your tab host. To do so you can use the following
Other child = (Other) getTabHost().getChildAt(0).getContext();
child.refreshInfo();
N.B.
As you are new android programmer it is highly recommended to start with Fragments. Tab concept is depcrecated long time ago. Old programmers may still work on it to support their existing programs but as a new programmer you better avoid it.
UPDATE:
You can do another thing
getTabHost().setCurrentTab(tabindex);
Other child= (Other) this.getCurrentActivity();
child.refreshInfo();
I am building a timetable app independently regarding school. I am now in the testing stage of my app and it just works fine on android version 2.3.6
However when I try to run it on a virtual device it's starts like normal.
However, after hitting a button which should execute the process to login, the apps returns the following errors:
01-05 00:52:23.180: E/AndroidRuntime(858): FATAL EXCEPTION: main
01-05 00:52:23.180: E/AndroidRuntime(858): java.lang.IllegalStateException: Could not execute method of the activity
01-05 00:52:23.180: E/AndroidRuntime(858): at android.view.View$1.onClick(View.java:3597)
01-05 00:52:23.180: E/AndroidRuntime(858): at android.view.View.performClick(View.java:4202)
01-05 00:52:23.180: E/AndroidRuntime(858): at android.view.View$PerformClick.run(View.java:17340)
01-05 00:52:23.180: E/AndroidRuntime(858): at android.os.Handler.handleCallback(Handler.java:725)
01-05 00:52:23.180: E/AndroidRuntime(858): at android.os.Handler.dispatchMessage(Handler.java:92)
01-05 00:52:23.180: E/AndroidRuntime(858): at android.os.Looper.loop(Looper.java:137)
01-05 00:52:23.180: E/AndroidRuntime(858): at android.app.ActivityThread.main(ActivityThread.java:5039)
01-05 00:52:23.180: E/AndroidRuntime(858): at java.lang.reflect.Method.invokeNative(Native Method)
01-05 00:52:23.180: E/AndroidRuntime(858): at java.lang.reflect.Method.invoke(Method.java:511)
01-05 00:52:23.180: E/AndroidRuntime(858): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
01-05 00:52:23.180: E/AndroidRuntime(858): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
01-05 00:52:23.180: E/AndroidRuntime(858): at dalvik.system.NativeStart.main(Native Method)
01-05 00:52:23.180: E/AndroidRuntime(858): Caused by: java.lang.reflect.InvocationTargetException
01-05 00:52:23.180: E/AndroidRuntime(858): at java.lang.reflect.Method.invokeNative(Native Method)
01-05 00:52:23.180: E/AndroidRuntime(858): at java.lang.reflect.Method.invoke(Method.java:511)
01-05 00:52:23.180: E/AndroidRuntime(858): at android.view.View$1.onClick(View.java:3592)
01-05 00:52:23.180: E/AndroidRuntime(858): ... 11 more
01-05 00:52:23.180: E/AndroidRuntime(858): Caused by: android.os.NetworkOnMainThreadException
01-05 00:52:23.180: E/AndroidRuntime(858): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1117)
01-05 00:52:23.180: E/AndroidRuntime(858): at java.net.InetAddress.lookupHostByName(InetAddress.java:385)
01-05 00:52:23.180: E/AndroidRuntime(858): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
01-05 00:52:23.180: E/AndroidRuntime(858): at java.net.InetAddress.getAllByName(InetAddress.java:214)
01-05 00:52:23.180: E/AndroidRuntime(858): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137)
01-05 00:52:23.180: E/AndroidRuntime(858): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
01-05 00:52:23.180: E/AndroidRuntime(858): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
01-05 00:52:23.180: E/AndroidRuntime(858): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
01-05 00:52:23.180: E/AndroidRuntime(858): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
01-05 00:52:23.180: E/AndroidRuntime(858): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
01-05 00:52:23.180: E/AndroidRuntime(858): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
01-05 00:52:23.180: E/AndroidRuntime(858): at com.mattle.timetable.JSONParser.getJSONFromUrl(JSONParser.java:42)
01-05 00:52:23.180: E/AndroidRuntime(858): at com.mattle.timetable.LoginView.doLogin(LoginView.java:129)
01-05 00:52:23.180: E/AndroidRuntime(858): ... 14 more
I use the jsonparser class from this page: http://www.androidhive.info/2012/01/android-json-parsing-tutorial/
My login code looks like this:
package com.mattle.timetable;
import static com.mattle.timetable.MainActivity.PREFS_NAME;
import java.io.BufferedReader;
import java.math.BigInteger;
import java.net.URI;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import com.google.android.gcm.GCMRegistrar;
import com.markupartist.android.widget.ActionBar;
public class LoginView extends Activity {
private JSONParser jsonParser;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login_view);
ActionBar actionBar = (ActionBar) findViewById(R.id.actionbar);
// You can also assign the title programmatically by passing a
// CharSequence or resource id.
actionBar.setTitle("Jouw Lesrooster");
}
#Override
public void onBackPressed() {
Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);
}
private String getStringResourceByName(String aString)
{
String packageName = "com.mattle.timetable";
int resId = getResources().getIdentifier(aString, "string", packageName);
return getString(resId);
}
private boolean haveNetworkConnection() {
boolean haveConnectedWifi = false;
boolean haveConnectedMobile = false;
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo[] netInfo = cm.getAllNetworkInfo();
for (NetworkInfo ni : netInfo) {
if (ni.getTypeName().equalsIgnoreCase("WIFI"))
if (ni.isConnected())
haveConnectedWifi = true;
if (ni.getTypeName().equalsIgnoreCase("MOBILE"))
if (ni.isConnected())
haveConnectedMobile = true;
}
return haveConnectedWifi || haveConnectedMobile;
}
public String sha1(String s) {
MessageDigest digest = null;
try {
digest = MessageDigest.getInstance("SHA-1");
} catch (NoSuchAlgorithmException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
digest.reset();
byte[] data = digest.digest(s.getBytes());
return String.format("%0" + (data.length*2) + "X", new BigInteger(1, data));
}
public void doRegister(View view) {
Intent gotoregister = new Intent(this, Register.class);
startActivity(gotoregister);
}
public void doLogin(View view) throws Exception {
BufferedReader in = null;
try{
if(haveNetworkConnection()) {
EditText getusername = (EditText) findViewById(R.id.username);
String username = getusername.getText().toString();
EditText getpassword = (EditText) findViewById(R.id.password);
String password = sha1(getpassword.getText().toString() + "SOMESALTHERENVM");
HttpClient client = new DefaultHttpClient();
URI website = new URI("SOMEURL");
HttpPost request = new HttpPost();
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("login_username", username));
nameValuePairs.add(new BasicNameValuePair("login_password", password));
jsonParser = new JSONParser();
JSONObject json = jsonParser.getJSONFromUrl("http://jouwlesrooster.nl/api/doLogin/", nameValuePairs);
try {
if (json.getString("success") != null) {
String res = json.getString("success");
if(Integer.parseInt(res) == 1){
//Log.d("MYTAG", "Print this in logcat...");
//Log.d("MYTAG", username + " ddd " + password);
getSharedPreferences("myLoginshit",MODE_PRIVATE)
.edit()
.putString("Username", username)
.putString("Password", password)
.commit();
GCMRegistrar.checkDevice(this);
GCMRegistrar.checkManifest(this);
String regId = GCMRegistrar.getRegistrationId(this);
if (regId.equals("")) {
GCMRegistrar.register(this, "***");
Log.i("test", "ddd");
// Toast.makeText(getApplicationContext(), "", Toast.LENGTH_LONG).show();
} else {
// Toast.makeText(getApplicationContext(), "Already registered", Toast.LENGTH_LONG).show();
// Log.v(TAG, "Already registered");
}
Intent gotomenu = new Intent(this, Menu.class);
startActivity(gotomenu);
}
}
} finally {
}
} else {
}
}finally{
if (in != null) {
try{
in.close();
}catch (Exception e) {
e.printStackTrace();
}
}
}
}
}
How can I solve this annoying error?
Thanks
Mattle
The problem is the doLogin()-method, which performs Network tasks on the UI-thread.
Looking at your StackTrace you can see:
Caused by: android.os.NetworkOnMainThreadException
this is thrown since Android "Ice Cream Sandwich". To get rid of it, put the Network code in an AsyncTask.
See this older question: How to fix android.os.NetworkOnMainThreadException?
It looks like your executing your doLogin() method from the UI-Thread (possibly some onClick method in a button).
You should not do that, because Network access are potentially slow and could freeze the UI. Use the AsyncTask class instead (see http://developer.android.com/reference/android/os/AsyncTask.html)
Its always better practice to have the UI work on UI-Thread and
Non-UI work on Non-UI Thread, but from HoneyComb version of Android
it became a Law and won't allowed any network operation in the UI
thread
In your case doLogin() is a blocking call, which you are calling from UI thread, where as it should be on the Non-UI thread.
To get rid of this use AsyncTask or Thread.
I have this code for an expandable list, I want to have a checkbox in the childgroups of the list view, and check if one of the checkboxes is checked.
The problem is that when I check if the checkbox is checked I get a NULL Pointer Exception.
Can you please tell me whats wrong?
here's my code - I've edited the code to inflate a view of the child_row.xml that holds that checkbox but I still get that null pointer, what am I doing wrong?!?!
package send.Shift;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import android.app.ExpandableListActivity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ExpandableListView;
import android.widget.SimpleExpandableListAdapter;
import android.widget.TextView;
public class Shifts extends ExpandableListActivity implements
OnCheckedChangeListener {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.list);
SimpleExpandableListAdapter expListAdapter = new SimpleExpandableListAdapter(
this, createGroupList(), R.layout.group_row,
new String[] { "Group Item" }, new int[] { R.id.row_name },
createChildList(), R.layout.child_row,
new String[] { "Sub Item" }, new int[] { R.id.grp_child });
getExpandableListView().setGroupIndicator(
getResources().getDrawable(R.drawable.expander_group));
ExpandableListView EX = (ExpandableListView) findViewById(android.R.id.list);
EX.setAdapter(expListAdapter);
final CheckBox childBox = (CheckBox) findViewById(R.id.childBOX);
final TextView choosenGroup = (TextView) findViewById(R.id.choosen);
LayoutInflater inflater = LayoutInflater.from(Shifts.this);
View view2 = inflater.inflate(R.layout.child_row, null);
childBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
// TODO Auto-generated method stub
if(childBox.isChecked() == true){
choosenGroup.setText("Shift Set");
}
}
});
}
Here is some of the Logcat log:
12-23 07:38:00.644: W/dalvikvm(880): threadid=1: thread exiting with uncaught exception (group=0x40015560)
12-23 07:38:00.654: E/AndroidRuntime(880): FATAL EXCEPTION: main
12-23 07:38:00.654: E/AndroidRuntime(880): java.lang.RuntimeException: Unable to start activity ComponentInfo{send.Shift/send.Shift.Shifts}: java.lang.NullPointerException
12-23 07:38:00.654: E/AndroidRuntime(880): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
12-23 07:38:00.654: E/AndroidRuntime(880): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
12-23 07:38:00.654: E/AndroidRuntime(880): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
12-23 07:38:00.654: E/AndroidRuntime(880): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
12-23 07:38:00.654: E/AndroidRuntime(880): at android.os.Handler.dispatchMessage(Handler.java:99)
12-23 07:38:00.654: E/AndroidRuntime(880): at android.os.Looper.loop(Looper.java:123)
12-23 07:38:00.654: E/AndroidRuntime(880): at android.app.ActivityThread.main(ActivityThread.java:3683)
12-23 07:38:00.654: E/AndroidRuntime(880): at java.lang.reflect.Method.invokeNative(Native Method)
12-23 07:38:00.654: E/AndroidRuntime(880): at java.lang.reflect.Method.invoke(Method.java:507)
12-23 07:38:00.654: E/AndroidRuntime(880): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
12-23 07:38:00.654: E/AndroidRuntime(880): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
12-23 07:38:00.654: E/AndroidRuntime(880): at dalvik.system.NativeStart.main(Native Method)
12-23 07:38:00.654: E/AndroidRuntime(880): Caused by: java.lang.NullPointerException
12-23 07:38:00.654: E/AndroidRuntime(880): at send.Shift.Shifts.onCreate(Shifts.java:41)
12-23 07:38:00.654: E/AndroidRuntime(880): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
12-23 07:38:00.654: E/AndroidRuntime(880): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
12-23 07:38:00.654: E/AndroidRuntime(880): ... 11 more
If you get a nullpointer on a certain line, something on that line is null. If it is the if(childBox.isChecked() line, probably childBox is null. Hard to say without the stack, but most probable cause is the line where you retrieve that checkbox.
final CheckBox childBox = (CheckBox) findViewById(R.id.childBOX);
Might be returning null, and this could be for several reasons. It could be your id is childBox instead of childBOX. Or that it is not in R.layout.list.
The best thing you can do is start debugging. What line is the error. Find the object that is null. Find out why it is null and if that is expected or not.
Instead of checking the childBox.isChecked() you can use the isChecked value. So your code would look like this:
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked == true){
choosenGroup.setText("Shift Set");
}
}
Check your layout list.xml I think this layout may is missing android:id="#+id/childBOX" for Check Box or android:id="#+id/choosen" for TextView
Check the folowin sample
<CheckBox android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/childBOX"/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/choosen"/>