My custom pageadapter is getting NullPointerException at instantiateItem. However, if I use this adapter as an inner-class then there is no error.
My custom pageadapter class
class MyPagesAdapter extends PagerAdapter {
String mPageData[]; //Stores the text to swipe.
LayoutInflater inflater; //Used to create individual pages
ViewPager vp;
public MyPagesAdapter(String pageData[])
{
mPageData = pageData;
}
#Override
public int getCount() {
return mPageData.length;
}
#Override
public Object instantiateItem(ViewGroup container, int position) {
View page = inflater.inflate(R.layout.page, null);
((TextView)page.findViewById(R.id.textMessage)).setText(mPageData[position]);
((ViewPager) container).addView(page, 0);
return page;
}
#Override
public boolean isViewFromObject(View arg0, Object arg1) {
return arg0==(View)arg1;
}
#Override
public void destroyItem(ViewGroup container, int position, Object object) {
((ViewPager) container).removeView((View) object);
object=null;
}
}
Here is mainActivity class
public class MainActivity extends Activity {
String pageData[]; //Stores the text to swipe.
LayoutInflater inflater; //Used to create individual pages
ViewPager vp; //Reference
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
pageData=getResources().getStringArray(R.array.desserts);
//get an inflater to be used to create single pages
inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
//Reference ViewPager defined in activity
vp=(ViewPager)findViewById(R.id.viewPager);
//set the adapter that will create the individual pages
vp.setAdapter(new MyPagesAdapter(pageData));
}}
Here is Error:
07-03 10:02:07.269: D/dalvikvm(1391): Not late-enabling CheckJNI (already on)
07-03 10:02:07.289: D/AndroidRuntime(1391): Shutting down VM
07-03 10:02:07.289: W/dalvikvm(1391): threadid=1: thread exiting with uncaught exception (group=0xb5004180)
07-03 10:02:07.339: E/AndroidRuntime(1391): FATAL EXCEPTION: main
07-03 10:02:07.339: E/AndroidRuntime(1391): java.lang.NullPointerException
07-03 10:02:07.339: E/AndroidRuntime(1391): at com.example.viewpager2.MyPagesAdapter.instantiateItem(MyPagesAdapter.java:30)
07-03 10:02:07.339: E/AndroidRuntime(1391): at android.support.v4.view.ViewPager.addNewItem(ViewPager.java:869)
07-03 10:02:07.339: E/AndroidRuntime(1391): at android.support.v4.view.ViewPager.populate(ViewPager.java:1019)
07-03 10:02:07.339: E/AndroidRuntime(1391): at android.support.v4.view.ViewPager.populate(ViewPager.java:951)
07-03 10:02:07.339: E/AndroidRuntime(1391): at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1473)
07-03 10:02:07.339: E/AndroidRuntime(1391): at android.view.View.measure(View.java:12723)
07-03 10:02:07.339: E/AndroidRuntime(1391): at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:594)
07-03 10:02:07.339: E/AndroidRuntime(1391): at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:376)
07-03 10:02:07.339: E/AndroidRuntime(1391): at android.view.View.measure(View.java:12723)
07-03 10:02:07.339: E/AndroidRuntime(1391): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4698)
07-03 10:02:07.339: E/AndroidRuntime(1391): at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
07-03 10:02:07.339: E/AndroidRuntime(1391): at android.view.View.measure(View.java:12723)
07-03 10:02:07.339: E/AndroidRuntime(1391): at android.widget.LinearLayout.measureVertical(LinearLayout.java:812)
07-03 10:02:07.339: E/AndroidRuntime(1391): at android.widget.LinearLayout.onMeasure(LinearLayout.java:553)
07-03 10:02:07.339: E/AndroidRuntime(1391): at android.view.View.measure(View.java:12723)
07-03 10:02:07.339: E/AndroidRuntime(1391): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4698)
07-03 10:02:07.339: E/AndroidRuntime(1391): at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
07-03 10:02:07.339: E/AndroidRuntime(1391): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2092)
07-03 10:02:07.339: E/AndroidRuntime(1391): at android.view.View.measure(View.java:12723)
07-03 10:02:07.339: E/AndroidRuntime(1391): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1064)
07-03 10:02:07.339: E/AndroidRuntime(1391): at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2442)
07-03 10:02:07.339: E/AndroidRuntime(1391): at android.os.Handler.dispatchMessage(Handler.java:99)
07-03 10:02:07.339: E/AndroidRuntime(1391): at android.os.Looper.loop(Looper.java:137)
07-03 10:02:07.339: E/AndroidRuntime(1391): at android.app.ActivityThread.main(ActivityThread.java:4424)
07-03 10:02:07.339: E/AndroidRuntime(1391): at java.lang.reflect.Method.invokeNative(Native Method)
07-03 10:02:07.339: E/AndroidRuntime(1391): at java.lang.reflect.Method.invoke(Method.java:511)
07-03 10:02:07.339: E/AndroidRuntime(1391): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
07-03 10:02:07.339: E/AndroidRuntime(1391): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
07-03 10:02:07.339: E/AndroidRuntime(1391): at dalvik.system.NativeStart.main(Native Method)
07-03 10:02:07.780: I/dalvikvm(1391): threadid=3: reacting to signal 3
07-03 10:02:07.780: I/dalvikvm(1391): Wrote stack traces to '/data/anr/traces.txt'
07-03 10:02:07.958: I/dalvikvm(1391): threadid=3: reacting to signal 3
07-03 10:02:07.958: I/dalvikvm(1391): Wrote stack traces to '/data/anr/traces.txt'
Update:
one solution could be passing the inflater to pageadapter class from activity
vp.setAdapter(new MyPagesAdapter(pageData,inflater));
in pageadapter class
public MyPagesAdapter(String pageData[], LayoutInflater minflater)
{
mPageData = pageData;
inflater = minflater;
}
or simply stablish Layoutinflater in pageadapter class
LayoutInflater inflater = (LayoutInflater) container.getContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
Related
I'm getting a NullPointerException while trying to start an Activity which contains a ListView .
In the getView method of the adapter class, the exception happens when the setText function of a textView is being called .
The code bellow is my adapter class:
public class QuestionsListAdapter extends ArrayAdapter<Question> {
Context context;
List<Question> questions;
public QuestionsListAdapter(Context context, List<Question> questions){
super(context, R.layout.list_item_question, questions);
this.context = context;
this.questions = questions;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater vi = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = vi.inflate(R.layout.list_item_question, null);
Question question = questions.get(position);
TextView tv = (TextView) view.findViewById(R.id.question_list_item_string);
Log.i(TableCreator.LOG_TAG, question.toString()); //this works fine and the string is not null .
tv.setText(question.toString()+""); //NULL POINTER EXCEPTION .
return view;
}
}
As you see, I've logged the string in the logcat and it works just fine, but the next line makes the mistake .
And this is the logcat output:
05-27 13:24:02.979 5325-5325/org.kabiri.operationcheklist I/Operation Checklist﹕ |-Question-> id:1 summary:mySummary comment:myComment solution:mySolution ownerList:dummyOwner
05-27 13:24:02.979 5325-5325/org.kabiri.operationcheklist D/AndroidRuntime﹕ Shutting down VM
05-27 13:24:02.979 5325-5325/org.kabiri.operationcheklist W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0xb0f5f648)
05-27 13:24:02.979 5325-5325/org.kabiri.operationcheklist E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.NullPointerException
at org.kabiri.operationchecklist.adapter.QuestionsListAdapter.getView(QuestionsListAdapter.java:43)
at android.widget.AbsListView.obtainView(AbsListView.java:2177)
at android.widget.ListView.makeAndAddView(ListView.java:1840)
at android.widget.ListView.fillDown(ListView.java:675)
at android.widget.ListView.fillFromTop(ListView.java:736)
at android.widget.ListView.layoutChildren(ListView.java:1655)
at android.widget.AbsListView.onLayout(AbsListView.java:2012)
at android.view.View.layout(View.java:14289)
at android.view.ViewGroup.layout(ViewGroup.java:4562)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
at android.view.View.layout(View.java:14289)
at android.view.ViewGroup.layout(ViewGroup.java:4562)
at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
at android.view.View.layout(View.java:14289)
at android.view.ViewGroup.layout(ViewGroup.java:4562)
at android.support.v7.internal.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:502)
at android.view.View.layout(View.java:14289)
at android.view.ViewGroup.layout(ViewGroup.java:4562)
at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
at android.view.View.layout(View.java:14289)
at android.view.ViewGroup.layout(ViewGroup.java:4562)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
at android.view.View.layout(View.java:14289)
at android.view.ViewGroup.layout(ViewGroup.java:4562)
at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
at android.view.View.layout(View.java:14289)
at android.view.ViewGroup.layout(ViewGroup.java:4562)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1976)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1730)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1004)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5481)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
at android.view.Choreographer.doCallbacks(Choreographer.java:562)
at android.view.Choreographer.doFrame(Choreographer.java:532)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
at android.os.Handler.handleCallback(Handler.java:730)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
The logcat shows that the error happens on this line of my adapter class:
tv.setText(question.toString()+"");
I really appreciate your help .
You already know where the problem is!
tv.setText(question.toString()+"");
is causing the NPE that means the TextView tv is null. And that means that the line
TextView tv = (TextView) view.findViewById(R.id.question_list_item_string);
is not able to find the TextView. Check the question_list_item_string id and make sure it matches the id in your list_item_question.xml file
I've been trying to get my list view to work for quite some time now, I just changed my listener from onClick to onItemClick to handle listview items better but the app crashes once again, my code below, any help would be appreciated.
Class:
public class ListViewAdapterProduct extends BaseAdapter {
Context mContext;
ListView listView = (ListView) findViewById(R.id.listview1);
listView.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View v, int position, long id){
Resources res = mContext.getResources();
productTitleArray = res.getStringArray(R.array.titles_product);
for (String productTitle : productTitleArray)
{
if(productTitle.equals("productOne"))
{
Log.d("Msg", "Found");
}
else
{
Log.d("Msg", "Not Found");
}
}
}
});
My previous post:
Compare XML String From Java Class When Item In ListView Is Clicked
Logcat:
03-30 16:40:39.027: E/AndroidRuntime(811): FATAL EXCEPTION: main
03-30 16:40:39.027: E/AndroidRuntime(811): java.lang.NullPointerException
03-30 16:40:39.027: E/AndroidRuntime(811): at com.twostarii.test.ListViewAdapterproduct.getView(ListViewAdapterproduct.java:91)
03-30 16:40:39.027: E/AndroidRuntime(811): at android.widget.AbsListView.obtainView(AbsListView.java:2159)
03-30 16:40:39.027: E/AndroidRuntime(811): at android.widget.ListView.makeAndAddView(ListView.java:1831)
03-30 16:40:39.027: E/AndroidRuntime(811): at android.widget.ListView.fillDown(ListView.java:674)
03-30 16:40:39.027: E/AndroidRuntime(811): at android.widget.ListView.fillFromTop(ListView.java:735)
03-30 16:40:39.027: E/AndroidRuntime(811): at android.widget.ListView.layoutChildren(ListView.java:1652)
03-30 16:40:39.027: E/AndroidRuntime(811): at android.widget.AbsListView.onLayout(AbsListView.java:1994)
03-30 16:40:39.027: E/AndroidRuntime(811): at android.view.View.layout(View.java:14008)
03-30 16:40:39.027: E/AndroidRuntime(811): at android.view.ViewGroup.layout(ViewGroup.java:4373)
03-30 16:40:39.027: E/AndroidRuntime(811): at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1021)
03-30 16:40:39.027: E/AndroidRuntime(811): at android.view.View.layout(View.java:14008)
03-30 16:40:39.027: E/AndroidRuntime(811): at android.view.ViewGroup.layout(ViewGroup.java:4373)
03-30 16:40:39.027: E/AndroidRuntime(811): at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
03-30 16:40:39.027: E/AndroidRuntime(811): at android.view.View.layout(View.java:14008)
03-30 16:40:39.027: E/AndroidRuntime(811): at android.view.ViewGroup.layout(ViewGroup.java:4373)
03-30 16:40:39.027: E/AndroidRuntime(811): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1663)
03-30 16:40:39.027: E/AndroidRuntime(811): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1521)
03-30 16:40:39.027: E/AndroidRuntime(811): at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
03-30 16:40:39.027: E/AndroidRuntime(811): at android.view.View.layout(View.java:14008)
03-30 16:40:39.027: E/AndroidRuntime(811): at android.view.ViewGroup.layout(ViewGroup.java:4373)
03-30 16:40:39.027: E/AndroidRuntime(811): at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
03-30 16:40:39.027: E/AndroidRuntime(811): at android.view.View.layout(View.java:14008)
03-30 16:40:39.027: E/AndroidRuntime(811): at android.view.ViewGroup.layout(ViewGroup.java:4373)
03-30 16:40:39.027: E/AndroidRuntime(811): at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1892)
03-30 16:40:39.027: E/AndroidRuntime(811): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1711)
03-30 16:40:39.027: E/AndroidRuntime(811): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:989)
03-30 16:40:39.027: E/AndroidRuntime(811): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4351)
03-30 16:40:39.027: E/AndroidRuntime(811): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
03-30 16:40:39.027: E/AndroidRuntime(811): at android.view.Choreographer.doCallbacks(Choreographer.java:562)
03-30 16:40:39.027: E/AndroidRuntime(811): at android.view.Choreographer.doFrame(Choreographer.java:532)
03-30 16:40:39.027: E/AndroidRuntime(811): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
03-30 16:40:39.027: E/AndroidRuntime(811): at android.os.Handler.handleCallback(Handler.java:725)
03-30 16:40:39.027: E/AndroidRuntime(811): at android.os.Handler.dispatchMessage(Handler.java:92)
03-30 16:40:39.027: E/AndroidRuntime(811): at android.os.Looper.loop(Looper.java:137)
03-30 16:40:39.027: E/AndroidRuntime(811): at android.app.ActivityThread.main(ActivityThread.java:5041)
03-30 16:40:39.027: E/AndroidRuntime(811): at java.lang.reflect.Method.invokeNative(Native Method)
03-30 16:40:39.027: E/AndroidRuntime(811): at java.lang.reflect.Method.invoke(Method.java:511)
03-30 16:40:39.027: E/AndroidRuntime(811): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
03-30 16:40:39.027: E/AndroidRuntime(811): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
03-30 16:40:39.027: E/AndroidRuntime(811): at dalvik.system.NativeStart.main(Native Method)
Activity:
public class MainActivityproduct extends MainActivity {
ListView list;
ListViewAdapterproduct adapter;
EditText editsearch;
String[] position;
String[] productTitles;
String[] productDescriptions;
int[] images={
R.drawable.list_product_one,
R.drawable.list_product_two,
R.drawable.list_product_three,
};
ArrayList<ClassproductList> arraylist = new ArrayList<ClassproductList>();
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
position = new String[] { "1", "2", "3"};
Resources res = getResources();
productTitles = res.getStringArray(R.array.titles_product);
productDescriptions = res.getStringArray(R.array.descriptions_product);
list = (ListView) findViewById(R.id.listview1);
list.setAdapter(adapter);
for (int i = 0; i < position.length; i++)
{
ClassproductList wp = new ClassproductList(productTitles[i], productDescriptions[i],images[i]);
arraylist.add(wp);
}
adapter = new ListViewAdapterproduct(this, arraylist);
list.setAdapter(adapter);
editsearch = (EditText) findViewById(R.id.search);
editsearch.addTextChangedListener(new TextWatcher() {
#Override
public void afterTextChanged(Editable arg0) {
String text = editsearch.getText().toString().toLowerCase(Locale.getDefault());
adapter.filter(text);
}
#Override
public void beforeTextChanged(CharSequence arg0, int arg1,
int arg2, int arg3) {
}
public void onTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
You have declared the mContext, but you have not initialized it.
You can do this in the constructor of your adapter:
public class ListViewAdapterProduct extends BaseAdapter {
Context mContext;
// the construcor that initializes the context
public ListViewAdapterProduct(Context c){
mContext = c;
}
...
However, the trace that you have posted, suggest that the problem is in your adapter's getView() method, on line 91. You should check that also.
ListViewAdapterproduct.getView(ListViewAdapterproduct.java:91)
Edit:
list.setAdapter(adapter);
In this line the adapter is null, you did not initialize it... (you set your adapter twice, first with null).
It is a good practise to define your variables locally, and make them class variable only when you actually need it. This way its harder to forget about initialization.
you have a problem in Context mContext; is null
in your activity set mContext = this; so mContext would be the activity context you will be able to use the resources
this is the correct code :
since your already sent this in your adapter you need to catch it there
public class ListViewAdapterProduct extends BaseAdapter {
Context mContext;
ArrayList<ClassproductList> arraylist;
ListView listView = (ListView) findViewById(R.id.listview1);
//add this
public ListViewAdapterProduct (Context mContext,ArrayList<ClassproductList> arraylist)
{
this.mContext = mContext;
this.arraylist = arraylist;
}
SOLVED !!!
I changed back from onItemClick (complicated to use with custom adapter) to onClick (simple to use with custom adapter) and applied:
view.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
String mytitle=holder.title.getText().toString();
if(mytitle.equals("ProductOne")){
Intent intent1 = new Intent(mContext, ProductClass.ProductOne);
mContext.startActivity(intent1);
...
}
}
Had to add:
String mytitle=holder.title.getText().toString();
I have been working on an app to use a phone's/tablet's camera flash as a flashlight. Everything seemed to be working fine but when I tested it on my Droid Bionic running Android 4.1.2, the app failed to turn on the flash even though it said it did. Here is the java code I used:
package com.example.flash;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.hardware.Camera;
import android.hardware.Camera.Parameters;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends Activity {
private boolean isFlashOn = false;
private Camera camera;
private Button button;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (Button) findViewById(R.id.buttonFlashlight);
Context context = this;
PackageManager pm = context.getPackageManager();
if(!pm.hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
Log.e("err", "Device has no camera!");
Toast.makeText(getApplicationContext(),
"Your device doesn't have camera!",Toast.LENGTH_SHORT).show();
return;
}
camera = Camera.open();
final Parameters p = camera.getParameters();
button.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
if (isFlashOn) {
Log.i("info", "torch is turned off!");
p.setFlashMode(Parameters.FLASH_MODE_OFF);
camera.setParameters(p);
isFlashOn = false;
button.setText("Tap to turn flashlight on.");
}
else {
Log.i("info", "torch is turned on!");
p.setFlashMode(Parameters.FLASH_MODE_TORCH);
camera.setParameters(p);
isFlashOn = true;
button.setText("Tap to turn flashlight off.");
}
}
});
}
#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;
}
#Override
protected void onStop() {
super.onStop();
if (camera != null) {
camera.release();
}
}}
Is this code correct or did I miss something?
Logcat:
07-03 18:48:29.064: E/Trace(773): error opening trace file: No such file or directory (2)
07-03 18:48:30.535: D/Camera(773): app passed NULL surface
07-03 18:48:31.023: D/libEGL(773): loaded /system/lib/egl/libEGL_emulation.so
07-03 18:48:31.073: D/(773): HostConnection::get() New Host Connection established 0x2a13c3c0, tid 773
07-03 18:48:31.123: D/libEGL(773): loaded /system/lib/egl/libGLESv1_CM_emulation.so
07-03 18:48:31.173: D/libEGL(773): loaded /system/lib/egl/libGLESv2_emulation.so
07-03 18:48:31.406: W/EGL_emulation(773): eglSurfaceAttrib not implemented
07-03 18:48:31.433: D/OpenGLRenderer(773): Enabling debug mode 0
07-03 18:48:31.723: I/Choreographer(773): Skipped 58 frames! The application may be doing too much work on its main thread.
07-03 18:49:05.923: D/dalvikvm(773): GC_CONCURRENT freed 202K, 12% free 2623K/2956K, paused 74ms+25ms, total 234ms
07-03 18:49:06.216: W/EGL_emulation(773): eglSurfaceAttrib not implemented
07-03 18:49:09.584: D/Camera(773): app passed NULL surface
07-03 18:49:09.853: W/EGL_emulation(773): eglSurfaceAttrib not implemented
07-03 18:49:11.813: I/info(773): torch is turned on!
07-03 18:49:13.467: I/info(773): torch is turned off!
07-03 18:49:16.263: W/EGL_emulation(773): eglSurfaceAttrib not implemented
07-03 18:49:16.713: D/AndroidRuntime(773): Shutting down VM
07-03 18:49:16.713: W/dalvikvm(773): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
07-03 18:49:16.936: E/AndroidRuntime(773): FATAL EXCEPTION: main
07-03 18:49:16.936: E/AndroidRuntime(773): java.lang.RuntimeException: Method called after release()
07-03 18:49:16.936: E/AndroidRuntime(773): at android.hardware.Camera._stopPreview(Native Method)
07-03 18:49:16.936: E/AndroidRuntime(773): at android.hardware.Camera.stopPreview(Camera.java:543)
07-03 18:49:16.936: E/AndroidRuntime(773): at com.example.flash.MainActivity.surfaceDestroyed(MainActivity.java:140)
07-03 18:49:16.936: E/AndroidRuntime(773): at android.view.SurfaceView.updateWindow(SurfaceView.java:553)
07-03 18:49:16.936: E/AndroidRuntime(773): at android.view.SurfaceView.onWindowVisibilityChanged(SurfaceView.java:231)
07-03 18:49:16.936: E/AndroidRuntime(773): at android.view.View.dispatchWindowVisibilityChanged(View.java:7544)
07-03 18:49:16.936: E/AndroidRuntime(773): at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1039)
07-03 18:49:16.936: E/AndroidRuntime(773): at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1039)
07-03 18:49:16.936: E/AndroidRuntime(773): at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1039)
07-03 18:49:16.936: E/AndroidRuntime(773): at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1039)
07-03 18:49:16.936: E/AndroidRuntime(773): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1211)
07-03 18:49:16.936: E/AndroidRuntime(773): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:989)
07-03 18:49:16.936: E/AndroidRuntime(773): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4351)
07-03 18:49:16.936: E/AndroidRuntime(773): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
07-03 18:49:16.936: E/AndroidRuntime(773): at android.view.Choreographer.doCallbacks(Choreographer.java:562)
07-03 18:49:16.936: E/AndroidRuntime(773): at android.view.Choreographer.doFrame(Choreographer.java:532)
07-03 18:49:16.936: E/AndroidRuntime(773): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
07-03 18:49:16.936: E/AndroidRuntime(773): at android.os.Handler.handleCallback(Handler.java:725)
07-03 18:49:16.936: E/AndroidRuntime(773): at android.os.Handler.dispatchMessage(Handler.java:92)
07-03 18:49:16.936: E/AndroidRuntime(773): at android.os.Looper.loop(Looper.java:137)
07-03 18:49:16.936: E/AndroidRuntime(773): at android.app.ActivityThread.main(ActivityThread.java:5041)
07-03 18:49:16.936: E/AndroidRuntime(773): at java.lang.reflect.Method.invokeNative(Native Method)
07-03 18:49:16.936: E/AndroidRuntime(773): at java.lang.reflect.Method.invoke(Method.java:511)
07-03 18:49:16.936: E/AndroidRuntime(773): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
07-03 18:49:16.936: E/AndroidRuntime(773): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
07-03 18:49:16.936: E/AndroidRuntime(773): at dalvik.system.NativeStart.main(Native Method)
07-03 18:49:24.854: E/Trace(811): error opening trace file: No such file or directory (2)
07-03 18:49:25.413: D/libEGL(811): loaded /system/lib/egl/libEGL_emulation.so
07-03 18:49:25.567: D/(811): HostConnection::get() New Host Connection established 0x2a15f570, tid 811
07-03 18:49:25.643: D/libEGL(811): loaded /system/lib/egl/libGLESv1_CM_emulation.so
07-03 18:49:25.663: D/libEGL(811): loaded /system/lib/egl/libGLESv2_emulation.so
07-03 18:49:25.934: W/EGL_emulation(811): eglSurfaceAttrib not implemented
07-03 18:49:25.963: D/OpenGLRenderer(811): Enabling debug mode 0
07-03 18:53:12.298: D/Camera(811): app passed NULL surface
07-03 18:53:12.723: D/dalvikvm(811): GC_CONCURRENT freed 172K, 11% free 2600K/2904K, paused 9ms+165ms, total 421ms
07-03 18:53:12.934: E/EGL_emulation(811): rcCreateWindowSurface returned 0
07-03 18:53:12.934: E/EGL_emulation(811): tid 811: eglCreateWindowSurface(631): error 0x3003 (EGL_BAD_ALLOC)
07-03 18:53:12.943: D/AndroidRuntime(811): Shutting down VM
07-03 18:53:12.943: W/dalvikvm(811): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
07-03 18:53:13.033: E/AndroidRuntime(811): FATAL EXCEPTION: main
07-03 18:53:13.033: E/AndroidRuntime(811): java.lang.RuntimeException: createWindowSurface failed EGL_BAD_ALLOC
07-03 18:53:13.033: E/AndroidRuntime(811): at android.view.HardwareRenderer$GlRenderer.createSurface(HardwareRenderer.java:1064)
07-03 18:53:13.033: E/AndroidRuntime(811): at android.view.HardwareRenderer$GlRenderer.createEglSurface(HardwareRenderer.java:961)
07-03 18:53:13.033: E/AndroidRuntime(811): at android.view.HardwareRenderer$GlRenderer.initialize(HardwareRenderer.java:787)
07-03 18:53:13.033: E/AndroidRuntime(811): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1502)
07-03 18:53:13.033: E/AndroidRuntime(811): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:989)
07-03 18:53:13.033: E/AndroidRuntime(811): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4351)
07-03 18:53:13.033: E/AndroidRuntime(811): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
07-03 18:53:13.033: E/AndroidRuntime(811): at android.view.Choreographer.doCallbacks(Choreographer.java:562)
07-03 18:53:13.033: E/AndroidRuntime(811): at android.view.Choreographer.doFrame(Choreographer.java:532)
07-03 18:53:13.033: E/AndroidRuntime(811): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
07-03 18:53:13.033: E/AndroidRuntime(811): at android.os.Handler.handleCallback(Handler.java:725)
07-03 18:53:13.033: E/AndroidRuntime(811): at android.os.Handler.dispatchMessage(Handler.java:92)
07-03 18:53:13.033: E/AndroidRuntime(811): at android.os.Looper.loop(Looper.java:137)
07-03 18:53:13.033: E/AndroidRuntime(811): at android.app.ActivityThread.main(ActivityThread.java:5041)
07-03 18:53:13.033: E/AndroidRuntime(811): at java.lang.reflect.Method.invokeNative(Native Method)
07-03 18:53:13.033: E/AndroidRuntime(811): at java.lang.reflect.Method.invoke(Method.java:511)
07-03 18:53:13.033: E/AndroidRuntime(811): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
07-03 18:53:13.033: E/AndroidRuntime(811): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
07-03 18:53:13.033: E/AndroidRuntime(811): at dalvik.system.NativeStart.main(Native Method)
UPDATE
I think the key is you are running Android 4.1.2. Since Android 4.0, if you want to use the Camera Device, even if you only want to use the flash, you are forced to use a SurfaceView.
In the previous answer (below), I gave you a link to a Torch app which uses SurfaceView. Try it or adapt it to your code.
PREVIOUS ANSWER:
As stated in many other cases (like this one), you may be facing a Device-Specific issue that is quite common in the Android world.
Although getSupportedFlashModes() may return FLASH_MODE_TORCH on nearly every device, many of them don't actually support it.
Anyway, you could try these:
Use camera.startPreview(); after camera = Camera.open();
Try setting FLASH_MODE_OFF initially (before camera.startPreview();).
Check if this Torch app works in your device. In case it does, you have the source code to compare it to yours.
Download a Torch app from the Play Store to test if it's a device issue or not.
Post the issue in a Droid Bionic support forum.
UPDATE: I would say the final keyword is a problem in your code. Try changing it to:
//camera = Camera.open();
//final Parameters p = camera.getParameters();
button.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
if (isFlashOn) {
Log.i("info", "torch is turned off!");
cam.stopPreview();
cam.release();
isFlashOn = false;
button.setText("Tap to turn flashlight on.");
}
else {
Log.i("info", "torch is turned on!");
camera = Camera.open();
Parameters p = camera.getParameters();
p.setFlashMode(Parameters.FLASH_MODE_OFF);
camera.setParameters(p);
camera.startPreview();
p.setFlashMode(Parameters.FLASH_MODE_TORCH);
camera.setParameters(p);
isFlashOn = true;
button.setText("Tap to turn flashlight off.");
}
}
});
user the permission "android.permission.FLASHLIGHT" in the manifest
<uses-permission android:name="android.permission.FLASHLIGHT" />
<uses-permission android:name="android.permission.CAMERA" />
I'm not getting a direct error in Eclipse.. but when trying to run this on my phone it doesn't open the activity and then my phone resets. I might be using the array adapter wrong.. but here's my code files:
Java File
package creativecoders.periodictable;
import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class AM extends Activity {
private ListView amList;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.am);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
#Override
public void onStart() {
super.onStart();
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this, R.array.AM, android.R.layout.simple_list_item_1);
amList.setAdapter(adapter);
}
public void onPause() {
super.onPause();
finish();
}
public void onStop() {
super.onStop();
finish();
}
public void onDestroy() {
super.onDestroy();
finish();
}
}
XML Layout File
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
String File
<string-array name="AM">
<item> ONE </item>
<item> TWO </item>
<item> THREE </item>
</string-array>
EDIT: Log file:
04-20 23:10:07.660: D/AndroidRuntime(284): Shutting down VM
04-20 23:10:07.660: W/dalvikvm(284): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
04-20 23:10:07.670: E/AndroidRuntime(284): FATAL EXCEPTION: main
04-20 23:10:07.670: E/AndroidRuntime(284): java.lang.RuntimeException: Unable to start activity ComponentInfo{creativecoders.periodictable/creativecoders.periodictable.AM}: java.lang.NullPointerException
04-20 23:10:07.670: E/AndroidRuntime(284): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
04-20 23:10:07.670: E/AndroidRuntime(284): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
04-20 23:10:07.670: E/AndroidRuntime(284): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
04-20 23:10:07.670: E/AndroidRuntime(284): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
04-20 23:10:07.670: E/AndroidRuntime(284): at android.os.Handler.dispatchMessage(Handler.java:99)
04-20 23:10:07.670: E/AndroidRuntime(284): at android.os.Looper.loop(Looper.java:123)
04-20 23:10:07.670: E/AndroidRuntime(284): at android.app.ActivityThread.main(ActivityThread.java:4627)
04-20 23:10:07.670: E/AndroidRuntime(284): at java.lang.reflect.Method.invokeNative(Native Method)
04-20 23:10:07.670: E/AndroidRuntime(284): at java.lang.reflect.Method.invoke(Method.java:521)
04-20 23:10:07.670: E/AndroidRuntime(284): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-20 23:10:07.670: E/AndroidRuntime(284): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-20 23:10:07.670: E/AndroidRuntime(284): at dalvik.system.NativeStart.main(Native Method)
04-20 23:10:07.670: E/AndroidRuntime(284): Caused by: java.lang.NullPointerException
04-20 23:10:07.670: E/AndroidRuntime(284): at creativecoders.periodictable.AM.onStart(AM.java:28)
04-20 23:10:07.670: E/AndroidRuntime(284): at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1129)
04-20 23:10:07.670: E/AndroidRuntime(284): at android.app.Activity.performStart(Activity.java:3781)
04-20 23:10:07.670: E/AndroidRuntime(284): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2636)
04-20 23:10:07.670: E/AndroidRuntime(284): ... 11 more
you did not initialize the ListView. in onCreate()
amList = (ListView)findViewById(R.id.listView1);
I'm trying to test if my android app works, it consists of 2 activity screens. There are no errors in my codes but my app won't run. It always gives me this error on the emulator "Unfortunately 'application name' has stopped."
Here is my Activity code
public class MainActivity extends Activity
{
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
View title = getWindow().findViewById(android.R.id.title);
View titleBar = (View) title.getParent();
titleBar.setBackgroundColor(Color.RED);
Button next=(Button)findViewById(R.id.DGButton);
next.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent myIntent=new Intent(view.getContext(),
Activity2.class);
startActivityForResult(myIntent, 0);
}});}
public void calculateClickHandler(View view)
{
if (view.getId() == R.id.CalculateButton)
{
EditText ageText = (EditText)findViewById
(R.id.AgeField);
EditText weightText = (EditText)findViewById
(R.id.WeightField);
EditText ftText = (EditText)findViewById
(R.id.HeightField);
EditText inText = (EditText)findViewById
(R.id.HeightField2);
RadioGroup weightRG = (RadioGroup) findViewById
(R.id.WeightRG);
RadioGroup sexRG = (RadioGroup) findViewById
(R.id.SexRG);
TextView resultText = (TextView)findViewById
(R.id.ResultLabel);
TextView normalBMIText = (TextView)findViewById
(R.id.NormalBMI);
TextView idealKgText = (TextView)findViewById
(R.id.IdealKgLabel);
TextView idealLbText = (TextView)findViewById
(R.id.IdealLbLabel);
int age = Integer.parseInt(ageText.getText
().toString());
double weight = Double.parseDouble
(weightText.getText().toString());
double ftheight = Double.parseDouble(ftText.getText
().toString());
double inheight = Double.parseDouble(inText.getText
().toString());
int checkedRadioButton1 =
weightRG.getCheckedRadioButtonId();
int checkedRadioButton2 =
sexRG.getCheckedRadioButtonId();
double bmiValue = calculateBMI(weight, ftheight,
inheight, checkedRadioButton1);
String bmiInterpretation1 = interpretBMI1(bmiValue);
String bmiInterpretation2 = interpretBMI2(age);
String bmiInterpretation3 = interpretBMI3(ftheight,
inheight, checkedRadioButton2);
String bmiInterpretation4 = interpretBMI4(ftheight,
inheight, checkedRadioButton2);
resultText.setText(bmiValue + " - " +
bmiInterpretation1);
normalBMIText.setText(""+bmiInterpretation2);
idealKgText.setText(""+bmiInterpretation3);
idealLbText.setText(""+bmiInterpretation4);
Intent intent1 = new Intent(MainActivity.this,
Activity2.class);
Bundle b = new Bundle();
b.putDouble("key", bmiValue);
intent1.putExtras(b);
startActivity(intent1);
}}
This is the error logcat:
12-26 02:50:45.606: E/AndroidRuntime(1776): FATAL EXCEPTION: main
12-26 02:50:45.606: E/AndroidRuntime(1776): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.bmicaldg/com.example.bmicaldg.MainActivity}: java.lang.NullPointerException
12-26 02:50:45.606: E/AndroidRuntime(1776): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
12-26 02:50:45.606: E/AndroidRuntime(1776): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
12-26 02:50:45.606: E/AndroidRuntime(1776): at android.app.ActivityThread.access$600(ActivityThread.java:141)
12-26 02:50:45.606: E/AndroidRuntime(1776): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
12-26 02:50:45.606: E/AndroidRuntime(1776): at android.os.Handler.dispatchMessage(Handler.java:99)
12-26 02:50:45.606: E/AndroidRuntime(1776): at android.os.Looper.loop(Looper.java:137)
12-26 02:50:45.606: E/AndroidRuntime(1776): at android.app.ActivityThread.main(ActivityThread.java:5039)
12-26 02:50:45.606: E/AndroidRuntime(1776): at java.lang.reflect.Method.invokeNative(Native Method)
12-26 02:50:45.606: E/AndroidRuntime(1776): at java.lang.reflect.Method.invoke(Method.java:511)
12-26 02:50:45.606: E/AndroidRuntime(1776): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
12-26 02:50:45.606: E/AndroidRuntime(1776): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
12-26 02:50:45.606: E/AndroidRuntime(1776): at dalvik.system.NativeStart.main(Native Method)
12-26 02:50:45.606: E/AndroidRuntime(1776): Caused by: java.lang.NullPointerException
12-26 02:50:45.606: E/AndroidRuntime(1776): at com.example.bmicaldg.MainActivity.onCreate(MainActivity.java:25)
12-26 02:50:45.606: E/AndroidRuntime(1776): at android.app.Activity.performCreate(Activity.java:5104)
12-26 02:50:45.606: E/AndroidRuntime(1776): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
12-26 02:50:45.606: E/AndroidRuntime(1776): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
12-26 02:50:45.606: E/AndroidRuntime(1776): ... 11 more
This is the debug logcat:
12-26 03:04:06.238: I/Process(1854): Sending signal. PID: 1854 SIG: 9
12-26 03:04:12.779: W/Trace(1876): Unexpected value from nativeGetEnabledTags: 0
12-26 03:04:12.837: W/Trace(1876): Unexpected value from nativeGetEnabledTags: 0
12-26 03:04:14.866: D/dalvikvm(1876): GC_CONCURRENT freed 76K, 7% free 2723K/2916K, paused 32ms+32ms, total 270ms
12-26 03:04:15.427: D/AndroidRuntime(1876): Shutting down VM
12-26 03:04:15.456: W/dalvikvm(1876): threadid=1: thread exiting with uncaught exception (group=0x40a70930)
12-26 03:04:15.546: E/AndroidRuntime(1876): FATAL EXCEPTION: main
12-26 03:04:15.546: E/AndroidRuntime(1876): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.bmicaldg/com.example.bmicaldg.MainActivity}: java.lang.NullPointerException
12-26 03:04:15.546: E/AndroidRuntime(1876): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
12-26 03:04:15.546: E/AndroidRuntime(1876): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
12-26 03:04:15.546: E/AndroidRuntime(1876): at android.app.ActivityThread.access$600(ActivityThread.java:141)
12-26 03:04:15.546: E/AndroidRuntime(1876): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
12-26 03:04:15.546: E/AndroidRuntime(1876): at android.os.Handler.dispatchMessage(Handler.java:99)
12-26 03:04:15.546: E/AndroidRuntime(1876): at android.os.Looper.loop(Looper.java:137)
12-26 03:04:15.546: E/AndroidRuntime(1876): at android.app.ActivityThread.main(ActivityThread.java:5039)
12-26 03:04:15.546: E/AndroidRuntime(1876): at java.lang.reflect.Method.invokeNative(Native Method)
12-26 03:04:15.546: E/AndroidRuntime(1876): at java.lang.reflect.Method.invoke(Method.java:511)
12-26 03:04:15.546: E/AndroidRuntime(1876): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
12-26 03:04:15.546: E/AndroidRuntime(1876): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
12-26 03:04:15.546: E/AndroidRuntime(1876): at dalvik.system.NativeStart.main(Native Method)
12-26 03:04:15.546: E/AndroidRuntime(1876): Caused by: java.lang.NullPointerException
12-26 03:04:15.546: E/AndroidRuntime(1876): at com.example.bmicaldg.MainActivity.onCreate(MainActivity.java:25)
12-26 03:04:15.546: E/AndroidRuntime(1876): at android.app.Activity.performCreate(Activity.java:5104)
12-26 03:04:15.546: E/AndroidRuntime(1876): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
12-26 03:04:15.546: E/AndroidRuntime(1876): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
12-26 03:04:15.546: E/AndroidRuntime(1876): ... 11 more
12-26 03:04:22.547: I/Process(1876): Sending signal. PID: 1876 SIG: 9
Any help is appreciated
02:50:45.606: E/AndroidRuntime(1776):
Caused by: java.lang.NullPointerException 12-26 02:50:45.606: E/AndroidRuntime(1776): at
com.example.bmicaldg.MainActivity.onCreate(MainActivity.java:25) 12-26
There is no code in your question so hard to tell how to fix, but based on stack trace, line 25 in MainActivity.java throwing NullPointerException. Code at line25 is some how resulting as null and you are trying to call some action on null reference which results in NullPointerException.
This is caused by NullPointerException. You might be accesing the null object which hasn't been initialized yet. You edit your question with your code, so that there would be chances of having my answer edited.
Caused by: java.lang.NullPointerException 12-26 02:50:45.606: E/AndroidRuntime(1776): at com.example.bmicaldg.MainActivity.onCreate(MainActivity.java:25)
This is where your error lies, line 25 of your MainActivity class. Whatever you are referencing is null.
Change your MainActivity onCreate code as:
public class MainActivity extends Activity
{
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
View title = getWindow().findViewById(android.R.id.title);
if (title != null) {
ViewParent titleBar = title.getParent();
if (titleBar != null && (titleBar instanceof View)) {
View parentView = (View)titleBar;
parentView.setBackgroundColor(Color.RED);
}
}
// Your Code here...