I'm trying to setup a method of executing one task if my application has been run previously - and another task if it has not.
To do this I have created a String runPrevious:
My problem is every time I attempt to execute the application I get a force close due to a null pointer exception here:
if (runPrevious.equals("yes")) {
which I don't understand - since I'm declaring the value of the String here:
String runPrevious = "No";
LOGCAT:
12-13 13:20:12.485: E/AndroidRuntime(1803): FATAL EXCEPTION: main
12-13 13:20:12.485: E/AndroidRuntime(1803): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.idg.omv/com.idg.omv.ui.phone.Home}: java.lang.NullPointerException
12-13 13:20:12.485: E/AndroidRuntime(1803): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2306)
12-13 13:20:12.485: E/AndroidRuntime(1803): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2358)
12-13 13:20:12.485: E/AndroidRuntime(1803): at android.app.ActivityThread.access$600(ActivityThread.java:156)
12-13 13:20:12.485: E/AndroidRuntime(1803): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1340)
12-13 13:20:12.485: E/AndroidRuntime(1803): at android.os.Handler.dispatchMessage(Handler.java:99)
12-13 13:20:12.485: E/AndroidRuntime(1803): at android.os.Looper.loop(Looper.java:153)
12-13 13:20:12.485: E/AndroidRuntime(1803): at android.app.ActivityThread.main(ActivityThread.java:5297)
12-13 13:20:12.485: E/AndroidRuntime(1803): at java.lang.reflect.Method.invokeNative(Native Method)
12-13 13:20:12.485: E/AndroidRuntime(1803): at java.lang.reflect.Method.invoke(Method.java:511)
12-13 13:20:12.485: E/AndroidRuntime(1803): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
12-13 13:20:12.485: E/AndroidRuntime(1803): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
12-13 13:20:12.485: E/AndroidRuntime(1803): at dalvik.system.NativeStart.main(Native Method)
12-13 13:20:12.485: E/AndroidRuntime(1803): Caused by: java.lang.NullPointerException
12-13 13:20:12.485: E/AndroidRuntime(1803): at com.idg.omv.ui.phone.Home.onCreate(Home.java:113)
12-13 13:20:12.485: E/AndroidRuntime(1803): at android.app.Activity.performCreate(Activity.java:5262)
12-13 13:20:12.485: E/AndroidRuntime(1803): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1081)
12-13 13:20:12.485: E/AndroidRuntime(1803): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2270)
12-13 13:20:12.485: E/AndroidRuntime(1803): ... 11 more
12-13 13:20:13.969: I/Process(1803): Sending signal. PID: 1803 SIG: 9
JAVA
public class Home extends YouTubeBaseActivity implements
VideoClickListener {
String runPrevious = "No";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.home);
String runPrevious = getIntent().getStringExtra("runPrevious");
if (runPrevious.equals("yes")) {
String playlist = getIntent().getStringExtra("playlist");
new GetYouTubeUserVideosTask(responseHandler, playlist).execute();
}else{
new GetYouTubeUserVideosTask(responseHandler, playlist).execute();
}
You are declaring it once again (probably with null value)
String runPrevious = getIntent().getStringExtra("runPrevious");
do not test strings for null if you are comparing them to a literal value. Instead use non-null-pointer succeptible compairsons.
In your case:
if ("yes".equals(runPrevious))
This will never throw a null pointer exception.
Related
I have called a function returnCurrentNameById() by passing the id of the particular row. But it gives an error.
String[] s1;
public String[] returnCurrentNameById(int k) throws SQLException{
String[] columns = new String[]{ KEY_ID1, KEY_NAME, Key_DOB, KEY_AGE, KEY_PHONE_NO, Key_EXPERIENCE, KEY_EMAIL, KEY_STATUS, KEY_STATUS};
SQLiteDatabase db3 = this.getReadableDatabase();
Cursor c = db3.query(DATA_BASE_TABLE_NAME1, columns, KEY_ID1 + "=" + k, null, null, null, null);
if (c != null){
c.moveToFirst();
for(int i = 0; i<=8; i++){
s1[i] = c.getString(i);
}
return s1;
}
return null;
}
The Log cat error report is:
02-15 16:38:13.424 1545-1545/world.com.my`enter code here`progect09 D/AndroidRuntime﹕ Shutting down VM
02-15 16:38:13.464 1545-1545/world.com.myprogect09 W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x2bc9a300)
02-15 16:38:13.533 1545-1545/world.com.myprogect09 E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.IllegalStateException: Could not execute method of the activity
at android.view.View$1.onClick(View.java:3591)
at android.view.View.performClick(View.java:4084)
at android.view.View$PerformClick.run(View.java:16966)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at android.view.View$1.onClick(View.java:3586)
at android.view.View.performClick(View.java:4084)
at android.view.View$PerformClick.run(View.java:16966)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at world.com.myprogect09.DataBaseSQL.returnCurrentNameById1(DataBaseSQL.java:209)
at world.com.myprogect09.ThirdActivity.isClicked(ThirdActivity.java:74)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at android.view.View$1.onClick(View.java:3586)
at android.view.View.performClick(View.java:4084)
at android.view.View$PerformClick.run(View.java:16966)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
02-15 16:38:34.491 1545-1545/world.com.myprogect09 I/Process﹕ Sending signal. PID: 1545 SIG: 9
You have not initialized your s1 array.
Use
s1 = new String[9];
to allocate an array of 9 elements.
Also check the return value of moveToFirst() so you don't get an exception in case the query returns no rows.
Replace
Cursor c = db3.query(DATA_BASE_TABLE_NAME1, columns, KEY_ID1 + "=" + k, null, null, null, null);
with
Cursor c = db3.query(DATA_BASE_TABLE_NAME1, columns, KEY_ID1 + " = ?", new String[]{String.valueOf(k)}, null, null, null);
I am about to freaking blow my brains out if I don't get this and I have no idea what is wrong. I am just trying to get the result from a query into a database file called Test that I made from SQLiteDatabase Browser.
I have MyDB class and my MainActivity class which just has a button and a textView (all this is for testing the query so it can be put into my app later). I'am trying to make it so that when you push that button it does the rawQuery in the MyDB class and then displays it on the textView. I will have the names for the rows match up with buttons in the app and will then be inserted in the raw query (SQL style) so that It will chose the proper result story based on the other columns.
I have tried this same hard coded query in queryMethodWithout() in my SQL Browser and it works just fine.
The logCat is giving me
IllegalStateException: could not execute method of the Activity
Caused by: java.lang.reflect.InvocationTargetException
Caused by: java.lang.NullPointerException
With this query I have everything hard coded to specific columns and a speific table just to make sure it all works but It won't print out into the text view, can someone please help?!
I know this is selfish but I am dying right meow!
Cursor from the MyDB class:
package com.example.dbquerytester;
import com.readystatesoftware.sqliteasset.SQLiteAssetHelper;
public class MyDB extends SQLiteAssetHelper{
public static final String DATABASE_NAME = "Test.db";
public static final int DATABASE_VERSION = 1;
Context context;
public MyDB(Context applicationContext) {
super(applicationContext, DATABASE_NAME, null, DATABASE_VERSION);
this.context = applicationContext;
}
public Cursor queryMethodWithout(){
SQLiteDatabase database = this.getReadableDatabase();
String storyQueryWithout1 = "SELECT story FROM Christian WHERE Target = 'Immediate' AND Target2 = 'Mother' AND Variable = 'Courage'";
Cursor cursor = database.rawQuery(storyQueryWithout, null);
return cursor;
}
And here's my MainActivity (The onClickQuery() method is the one that is called when the button is pressed):
public class Main_Activity extends Activity {
MyDB myDB;
private Cursor cursorQuery;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void displayMessage(String s){
TextView textView = (TextView) findViewById(R.id.textView1);
textView.setText(s);
}
public void openDB() throws SQLiteException{
myDB = new MyDB(this);
myDB.getReadableDatabase();
}
public void onClickQuery(View view){
openDB();
cursorQuery = myDB.queryMethodWithout();
cursorQuery.moveToFirst();
String story = cursorQuery.getString(0);
displayMessage(story);
}
protected void onDestroy(){
super.onDestroy();
cursorQuery.close();
myDB.close();
}
}
Here is my full LogCat!
07-17 11:47:34.760: D/(945): HostConnection::get() New Host Connection established 0xb823def0, tid 945
07-17 11:47:34.990: W/EGL_emulation(945): eglSurfaceAttrib not implemented
07-17 11:47:35.010: D/OpenGLRenderer(945): Enabling debug mode 0
07-17 11:47:37.770: I/SQLiteAssetHelper(945): successfully opened database Test.db
07-17 11:47:37.770: D/AndroidRuntime(945): Shutting down VM
07-17 11:47:37.780: W/dalvikvm(945): threadid=1: thread exiting with uncaught exception (group=0xb3a3dba8)
07-17 11:47:37.800: E/AndroidRuntime(945): FATAL EXCEPTION: main
07-17 11:47:37.800: E/AndroidRuntime(945): Process: com.example.dbquerytester, PID: 945
07-17 11:47:37.800: E/AndroidRuntime(945): java.lang.IllegalStateException: Could not execute method of the activity
07-17 11:47:37.800: E/AndroidRuntime(945): at android.view.View$1.onClick(View.java:3823)
07-17 11:47:37.800: E/AndroidRuntime(945): at android.view.View.performClick(View.java:4438)
07-17 11:47:37.800: E/AndroidRuntime(945): at android.view.View$PerformClick.run(View.java:18422)
07-17 11:47:37.800: E/AndroidRuntime(945): at android.os.Handler.handleCallback(Handler.java:733)
07-17 11:47:37.800: E/AndroidRuntime(945): at android.os.Handler.dispatchMessage(Handler.java:95)
07-17 11:47:37.800: E/AndroidRuntime(945): at android.os.Looper.loop(Looper.java:136)
07-17 11:47:37.800: E/AndroidRuntime(945): at android.app.ActivityThread.main(ActivityThread.java:5017)
07-17 11:47:37.800: E/AndroidRuntime(945): at java.lang.reflect.Method.invokeNative(Native Method)
07-17 11:47:37.800: E/AndroidRuntime(945): at java.lang.reflect.Method.invoke(Method.java:515)
07-17 11:47:37.800: E/AndroidRuntime(945): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
07-17 11:47:37.800: E/AndroidRuntime(945): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
07-17 11:47:37.800: E/AndroidRuntime(945): at dalvik.system.NativeStart.main(Native Method)
07-17 11:47:37.800: E/AndroidRuntime(945): Caused by: java.lang.reflect.InvocationTargetException
07-17 11:47:37.800: E/AndroidRuntime(945): at java.lang.reflect.Method.invokeNative(Native Method)
07-17 11:47:37.800: E/AndroidRuntime(945): at java.lang.reflect.Method.invoke(Method.java:515)
07-17 11:47:37.800: E/AndroidRuntime(945): at android.view.View$1.onClick(View.java:3818)
07-17 11:47:37.800: E/AndroidRuntime(945): ... 11 more
07-17 11:47:37.800: E/AndroidRuntime(945): Caused by: java.lang.NullPointerException
07-17 11:47:37.800: E/AndroidRuntime(945): at com.example.dbquerytester.MyDB.queryMethodWithout(MyDB.java:68)
07-17 11:47:37.800: E/AndroidRuntime(945): at com.example.dbquerytester.Main_Activity.onClickQuery(Main_Activity.java:67)
07-17 11:47:37.800: E/AndroidRuntime(945): ... 14 more
I am trying to parse a value through intent while switching between activities.
I know I should read values from last intent with getExtra but I don't know why it doesn't work.
Also when I switch between activities on button click, application crashes.
In activity main I read text from editText and put it in Intent:
public void schimba(View view){
int value = Integer.parseInt(instances.getText().toString());;
Intent intent = new Intent(this, Tabel.class);
intent.putExtra("max", value);
startActivity(intent);
}
When it switch to activity 2 I have this:
Intent intentObject = getIntent();
int value;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
value = intentObject.getIntExtra("max", 0);
/*
for(i=0;i<=value;i++)
{
LayoutInflater layoutinflate = null;
layoutinflate = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View rowview = layoutinflate.inflate( R.layout.activity_tabel, null);
}
*/
setContentView(R.layout.activity_tabel);
TextView showvalue;
showvalue = (TextView) findViewById(R.id.ShowValue);
showvalue.setText(""+value);
The idea is that I want to use this value in a for loop, I already know how to display the value in a textView but I don't need it, I wanna use it in for.
Logcat:
04-23 10:40:52.550: E/AndroidRuntime(1010): FATAL EXCEPTION: main
04-23 10:40:52.550: E/AndroidRuntime(1010): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.instances_temperature/com.example.instances_temperature.Tabel}: java.lang.NullPointerException
04-23 10:40:52.550: E/AndroidRuntime(1010): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
04-23 10:40:52.550: E/AndroidRuntime(1010): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
04-23 10:40:52.550: E/AndroidRuntime(1010): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
04-23 10:40:52.550: E/AndroidRuntime(1010): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
04-23 10:40:52.550: E/AndroidRuntime(1010): at android.os.Handler.dispatchMessage(Handler.java:99)
04-23 10:40:52.550: E/AndroidRuntime(1010): at android.os.Looper.loop(Looper.java:123)
04-23 10:40:52.550: E/AndroidRuntime(1010): at android.app.ActivityThread.main(ActivityThread.java:4627)
04-23 10:40:52.550: E/AndroidRuntime(1010): at java.lang.reflect.Method.invokeNative(Native Method)
04-23 10:40:52.550: E/AndroidRuntime(1010): at java.lang.reflect.Method.invoke(Method.java:521)
04-23 10:40:52.550: E/AndroidRuntime(1010): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-23 10:40:52.550: E/AndroidRuntime(1010): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-23 10:40:52.550: E/AndroidRuntime(1010): at dalvik.system.NativeStart.main(Native Method)
04-23 10:40:52.550: E/AndroidRuntime(1010): Caused by: java.lang.NullPointerException
04-23 10:40:52.550: E/AndroidRuntime(1010): at com.example.instances_temperature.Tabel.onCreate(Tabel.java:26)
04-23 10:40:52.550: E/AndroidRuntime(1010): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-23 10:40:52.550: E/AndroidRuntime(1010): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
04-23 10:40:52.550: E/AndroidRuntime(1010): ... 11 more
line 26 would be this:
value = intentObject.getIntExtra("max", 0);
You have to use the code below
int maxValue = getIntent().getExtras().getInt("max");
inside onCreate().
Hope it will solve your problem..
You have not declared intentObject...
Use this:
value = getIntent().getIntExtra("max", 0);
use this
value = getIntent().getStringExtra("max");
instead of this
value = intentObject.getIntExtra("max", 0);
When I try to run this line in order to hide the keyboard (I get the InputMethodManager):
this.context = context;
InputMethodManager mgr = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); //this line crashes the app
What should I do to fix it?
(I am running it from a fragment by the way)
Crash Log:
11-03 16:20:26.700: D/AndroidRuntime(2809): Shutting down VM
11-03 16:20:26.700: W/dalvikvm(2809): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
11-03 16:20:26.710: E/AndroidRuntime(2809): FATAL EXCEPTION: main
11-03 16:20:26.710: E/AndroidRuntime(2809): java.lang.NullPointerException
11-03 16:20:26.710: E/AndroidRuntime(2809): at co.emuze.tabtest1.Tab1$1.onClick(Tab1.java:32)
11-03 16:20:26.710: E/AndroidRuntime(2809): at android.view.View.performClick(View.java:4084)
11-03 16:20:26.710: E/AndroidRuntime(2809): at android.view.View$PerformClick.run(View.java:16966)
11-03 16:20:26.710: E/AndroidRuntime(2809): at android.os.Handler.handleCallback(Handler.java:615)
11-03 16:20:26.710: E/AndroidRuntime(2809): at android.os.Handler.dispatchMessage(Handler.java:92)
11-03 16:20:26.710: E/AndroidRuntime(2809): at android.os.Looper.loop(Looper.java:137)
11-03 16:20:26.710: E/AndroidRuntime(2809): at android.app.ActivityThread.main(ActivityThread.java:4745)
11-03 16:20:26.710: E/AndroidRuntime(2809): at java.lang.reflect.Method.invokeNative(Native Method)
11-03 16:20:26.710: E/AndroidRuntime(2809): at java.lang.reflect.Method.invoke(Method.java:511)
11-03 16:20:26.710: E/AndroidRuntime(2809): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
11-03 16:20:26.710: E/AndroidRuntime(2809): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-03 16:20:26.710: E/AndroidRuntime(2809): at dalvik.system.NativeStart.main(Native Method)
Full on click method:
public void onClick(View v) {
text1.setText(editText1.getText().toString());
InputMethodManager mgr = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
mgr.hideSoftInputFromWindow(editText1.getWindowToken(), 0);
}
It would appear context is null - you show the line this.context = context, and if the right hand side context is not a variable local to that method you're doing nothing. I think what you may be looking for is context = getApplicationContext()
Dont forget to use try catch blog because in case when your keyboard not open and if you use key key board hide code app crashed
User below code in Fragment
try {
InputMethodManager imm = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
} catch (Exception e) {
// TODO: handle exception
}
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...