I want to deploy a database along with my apk , so i modified my sqliteopenhelper as follows:
Code:
public class openingclass extends SQLiteOpenHelper
{
public openingclass(Context c) {
super(c,Db_NAME, null, DB_VERSION);
}
public void createDataBase() {
boolean dbExist;
try {
dbExist = checkDataBase();
} catch (SQLiteException e) {
e.printStackTrace();
throw new Error("database dose not exist");
}
if(dbExist){
//do nothing - database already exist
}else{
try {
copyDataBase();
} catch (IOException e) {
e.printStackTrace();
throw new Error("Error copying database");
}
//By calling this method and empty database will be created into the default system path
//of your application so we are gonna be able to overwrite that database with our database.
this.getReadableDatabase();
}
}
/**
* Check if the database already exist to avoid re-copying the file each time you open the application.
* @return true if it exists, false if it doesn't
*/
private boolean checkDataBase(){
SQLiteDatabase checkDB = null;
try{
String myPath = DB_PATH +"/"+ Db_NAME;
checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);
}catch(SQLiteException e){
//database does't exist yet.
throw new Error("database does't exist yet.");
}
if(checkDB != null){
checkDB.close();
}
return checkDB != null ? true : false;
}
/**
* Copies your database from your local assets-folder to the just created empty database in the
* system folder, from where it can be accessed and handled.
* This is done by transfering bytestream.
* */
private void copyDataBase() throws IOException{
//copyDataBase();
//Open your local db as the input stream
InputStream myInput = c1.getAssets().open(Db_NAME);
// Path to the just created empty db
String outFileName = DB_PATH +"/"+ Db_NAME;
File databaseFile = new File(DB_PATH);
// check if databases folder exists, if not create one and its subfolders
if (!databaseFile.exists()){
databaseFile.mkdir();
}
//Open the empty db as the output stream
OutputStream myOutput = new FileOutputStream(outFileName);
//transfer bytes from the inputfile to the outputfile
byte[] buffer = new byte[1024];
int length;
while ((length = myInput.read(buffer))>0){
myOutput.write(buffer, 0, length);
}
//Close the streams
myOutput.flush();
myOutput.close();
myInput.close();
}
@Override
public synchronized void close() {
if(myDataBase != null)
myDataBase.close();
super.close();
}
@Override
public void onCreate(SQLiteDatabase arg0) {
String S = "create table " +
TABLE_NAME +
" (" +
TABLE_COL_MAIL + " text primary key," +
TABLE_COL_NAME + " text," +
TABLE_COL_PASS + " text," +
TABLE_COL_PHO + " text," +
TABLE_COL_ADD + " text," +
TABLE_COL_GEN + " text," +
TABLE_COL_DOB + " text" +
");";
arg0.execSQL(S);
String S1 = "create table " +
SECOND_TABLE_NAME +
" (" +
TABLE_COL_USER + " text," +
TABLE_COL_PRODUCT + " text," +
TABLE_COL_QUANTITY + " integer" +
");";
arg0.execSQL(S1);
}
@Override
public void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2) {
// TODO Auto-generated method stub
}
The problem which people on other forums tell me is to do with the path. I have hard coded the path in my datamanager class as follows:
Code:
private final String DB_PATH="/data/data/com.example.shopkart/databases";
private final String Db_NAME = "dbshopkart.db";
I get the following error in my logcat on running on the device:
Code:
05-02 16:20:16.039: E/AndroidRuntime(9916): FATAL EXCEPTION: main
05-02 16:20:16.039: E/AndroidRuntime(9916): java.lang.Error: database does't exist yet.
05-02 16:20:16.039: E/AndroidRuntime(9916): at com.example.shopkart.datamanager$openingclass.checkDataBase(datamanager.java:112)
05-02 16:20:16.039: E/AndroidRuntime(9916): at com.example.shopkart.datamanager$openingclass.createDataBase(datamanager.java:63)
05-02 16:20:16.039: E/AndroidRuntime(9916): at com.example.shopkart.datamanager$openingclass.<init>(datamanager.java:56)
05-02 16:20:16.039: E/AndroidRuntime(9916): at com.example.shopkart.datamanager.<init>(datamanager.java:48)
05-02 16:20:16.039: E/AndroidRuntime(9916): at com.example.shopkart.MainActivity.onCreate(MainActivity.java:50)
05-02 16:20:16.039: E/AndroidRuntime(9916): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-02 16:20:16.039: E/AndroidRuntime(9916): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
05-02 16:20:16.039: E/AndroidRuntime(9916): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
05-02 16:20:16.039: E/AndroidRuntime(9916): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
05-02 16:20:16.039: E/AndroidRuntime(9916): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
05-02 16:20:16.039: E/AndroidRuntime(9916): at android.os.Handler.dispatchMessage(Handler.java:99)
05-02 16:20:16.039: E/AndroidRuntime(9916): at android.os.Looper.loop(Looper.java:130)
05-02 16:20:16.039: E/AndroidRuntime(9916): at android.app.ActivityThread.main(ActivityThread.java:3689)
05-02 16:20:16.039: E/AndroidRuntime(9916): at java.lang.reflect.Method.invokeNative(Native Method)
05-02 16:20:16.039: E/AndroidRuntime(9916): at java.lang.reflect.Method.invoke(Method.java:507)
05-02 16:20:16.039: E/AndroidRuntime(9916): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
05-02 16:20:16.039: E/AndroidRuntime(9916): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
05-02 16:20:16.039: E/AndroidRuntime(9916): at dalvik.system.NativeStart.main(Native Method)
05-02 16:25:32.835: E/Database(10275): sqlite3_open_v2("/data/data/com.example.shopkart/databases/dbshopkart.db", &handle, 1, NULL) failed
05-02 16:25:32.835: W/dalvikvm(10275): threadid=1: thread exiting with uncaught exception (group=0x40015578)
05-02 16:25:32.835: E/AndroidRuntime(10275): FATAL EXCEPTION: main
05-02 16:25:32.835: E/AndroidRuntime(10275): java.lang.Error: database does't exist yet.
05-02 16:25:32.835: E/AndroidRuntime(10275): at com.example.shopkart.datamanager$openingclass.checkDataBase(datamanager.java:112)
05-02 16:25:32.835: E/AndroidRuntime(10275): at com.example.shopkart.datamanager$openingclass.createDataBase(datamanager.java:63)
05-02 16:25:32.835: E/AndroidRuntime(10275): at com.example.shopkart.datamanager$openingclass.<init>(datamanager.java:56)
05-02 16:25:32.835: E/AndroidRuntime(10275): at com.example.shopkart.datamanager.<init>(datamanager.java:48)
05-02 16:25:32.835: E/AndroidRuntime(10275): at com.example.shopkart.MainActivity.onCreate(MainActivity.java:50)
05-02 16:25:32.835: E/AndroidRuntime(10275): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-02 16:25:32.835: E/AndroidRuntime(10275): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
05-02 16:25:32.835: E/AndroidRuntime(10275): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
05-02 16:25:32.835: E/AndroidRuntime(10275): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
05-02 16:25:32.835: E/AndroidRuntime(10275): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
05-02 16:25:32.835: E/AndroidRuntime(10275): at android.os.Handler.dispatchMessage(Handler.java:99)
05-02 16:25:32.835: E/AndroidRuntime(10275): at android.os.Looper.loop(Looper.java:130)
05-02 16:25:32.835: E/AndroidRuntime(10275): at android.app.ActivityThread.main(ActivityThread.java:3689)
05-02 16:25:32.835: E/AndroidRuntime(10275): at java.lang.reflect.Method.invokeNative(Native Method)
05-02 16:25:32.835: E/AndroidRuntime(10275): at java.lang.reflect.Method.invoke(Method.java:507)
05-02 16:25:32.835: E/AndroidRuntime(10275): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
05-02 16:25:32.835: E/AndroidRuntime(10275): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
05-02 16:25:32.835: E/AndroidRuntime(10275): at dalvik.system.NativeStart.main(Native Method)
The database seems to be not found.I have even put the database in the assets folder.Please help!
achtuhan M said:
I want to deploy a database along with my apk , so i modified my sqliteopenhelper as follows:
Code:
public class openingclass extends SQLiteOpenHelper
{
public openingclass(Context c) {
super(c,Db_NAME, null, DB_VERSION);
}
public void createDataBase() {
boolean dbExist;
try {
dbExist = checkDataBase();
} catch (SQLiteException e) {
e.printStackTrace();
throw new Error("database dose not exist");
}
if(dbExist){
//do nothing - database already exist
}else{
try {
copyDataBase();
} catch (IOException e) {
e.printStackTrace();
throw new Error("Error copying database");
}
//By calling this method and empty database will be created into the default system path
//of your application so we are gonna be able to overwrite that database with our database.
this.getReadableDatabase();
}
}
/**
* Check if the database already exist to avoid re-copying the file each time you open the application.
* @return true if it exists, false if it doesn't
*/
private boolean checkDataBase(){
SQLiteDatabase checkDB = null;
try{
String myPath = DB_PATH +"/"+ Db_NAME;
checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);
}catch(SQLiteException e){
//database does't exist yet.
throw new Error("database does't exist yet.");
}
if(checkDB != null){
checkDB.close();
}
return checkDB != null ? true : false;
}
/**
* Copies your database from your local assets-folder to the just created empty database in the
* system folder, from where it can be accessed and handled.
* This is done by transfering bytestream.
* */
private void copyDataBase() throws IOException{
//copyDataBase();
//Open your local db as the input stream
InputStream myInput = c1.getAssets().open(Db_NAME);
// Path to the just created empty db
String outFileName = DB_PATH +"/"+ Db_NAME;
File databaseFile = new File(DB_PATH);
// check if databases folder exists, if not create one and its subfolders
if (!databaseFile.exists()){
databaseFile.mkdir();
}
//Open the empty db as the output stream
OutputStream myOutput = new FileOutputStream(outFileName);
//transfer bytes from the inputfile to the outputfile
byte[] buffer = new byte[1024];
int length;
while ((length = myInput.read(buffer))>0){
myOutput.write(buffer, 0, length);
}
//Close the streams
myOutput.flush();
myOutput.close();
myInput.close();
}
@Override
public synchronized void close() {
if(myDataBase != null)
myDataBase.close();
super.close();
}
@Override
public void onCreate(SQLiteDatabase arg0) {
String S = "create table " +
TABLE_NAME +
" (" +
TABLE_COL_MAIL + " text primary key," +
TABLE_COL_NAME + " text," +
TABLE_COL_PASS + " text," +
TABLE_COL_PHO + " text," +
TABLE_COL_ADD + " text," +
TABLE_COL_GEN + " text," +
TABLE_COL_DOB + " text" +
");";
arg0.execSQL(S);
String S1 = "create table " +
SECOND_TABLE_NAME +
" (" +
TABLE_COL_USER + " text," +
TABLE_COL_PRODUCT + " text," +
TABLE_COL_QUANTITY + " integer" +
");";
arg0.execSQL(S1);
}
@Override
public void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2) {
// TODO Auto-generated method stub
}
The problem which people on other forums tell me is to do with the path. I have hard coded the path in my datamanager class as follows:
Code:
private final String DB_PATH="/data/data/com.example.shopkart/databases";
private final String Db_NAME = "dbshopkart.db";
I get the following error in my logcat on running on the device:
Code:
05-02 16:20:16.039: E/AndroidRuntime(9916): FATAL EXCEPTION: main
05-02 16:20:16.039: E/AndroidRuntime(9916): java.lang.Error: database does't exist yet.
05-02 16:20:16.039: E/AndroidRuntime(9916): at com.example.shopkart.datamanager$openingclass.checkDataBase(datamanager.java:112)
05-02 16:20:16.039: E/AndroidRuntime(9916): at com.example.shopkart.datamanager$openingclass.createDataBase(datamanager.java:63)
05-02 16:20:16.039: E/AndroidRuntime(9916): at com.example.shopkart.datamanager$openingclass.<init>(datamanager.java:56)
05-02 16:20:16.039: E/AndroidRuntime(9916): at com.example.shopkart.datamanager.<init>(datamanager.java:48)
05-02 16:20:16.039: E/AndroidRuntime(9916): at com.example.shopkart.MainActivity.onCreate(MainActivity.java:50)
05-02 16:20:16.039: E/AndroidRuntime(9916): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-02 16:20:16.039: E/AndroidRuntime(9916): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
05-02 16:20:16.039: E/AndroidRuntime(9916): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
05-02 16:20:16.039: E/AndroidRuntime(9916): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
05-02 16:20:16.039: E/AndroidRuntime(9916): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
05-02 16:20:16.039: E/AndroidRuntime(9916): at android.os.Handler.dispatchMessage(Handler.java:99)
05-02 16:20:16.039: E/AndroidRuntime(9916): at android.os.Looper.loop(Looper.java:130)
05-02 16:20:16.039: E/AndroidRuntime(9916): at android.app.ActivityThread.main(ActivityThread.java:3689)
05-02 16:20:16.039: E/AndroidRuntime(9916): at java.lang.reflect.Method.invokeNative(Native Method)
05-02 16:20:16.039: E/AndroidRuntime(9916): at java.lang.reflect.Method.invoke(Method.java:507)
05-02 16:20:16.039: E/AndroidRuntime(9916): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
05-02 16:20:16.039: E/AndroidRuntime(9916): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
05-02 16:20:16.039: E/AndroidRuntime(9916): at dalvik.system.NativeStart.main(Native Method)
05-02 16:25:32.835: E/Database(10275): sqlite3_open_v2("/data/data/com.example.shopkart/databases/dbshopkart.db", &handle, 1, NULL) failed
05-02 16:25:32.835: W/dalvikvm(10275): threadid=1: thread exiting with uncaught exception (group=0x40015578)
05-02 16:25:32.835: E/AndroidRuntime(10275): FATAL EXCEPTION: main
05-02 16:25:32.835: E/AndroidRuntime(10275): java.lang.Error: database does't exist yet.
05-02 16:25:32.835: E/AndroidRuntime(10275): at com.example.shopkart.datamanager$openingclass.checkDataBase(datamanager.java:112)
05-02 16:25:32.835: E/AndroidRuntime(10275): at com.example.shopkart.datamanager$openingclass.createDataBase(datamanager.java:63)
05-02 16:25:32.835: E/AndroidRuntime(10275): at com.example.shopkart.datamanager$openingclass.<init>(datamanager.java:56)
05-02 16:25:32.835: E/AndroidRuntime(10275): at com.example.shopkart.datamanager.<init>(datamanager.java:48)
05-02 16:25:32.835: E/AndroidRuntime(10275): at com.example.shopkart.MainActivity.onCreate(MainActivity.java:50)
05-02 16:25:32.835: E/AndroidRuntime(10275): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-02 16:25:32.835: E/AndroidRuntime(10275): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
05-02 16:25:32.835: E/AndroidRuntime(10275): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
05-02 16:25:32.835: E/AndroidRuntime(10275): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
05-02 16:25:32.835: E/AndroidRuntime(10275): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
05-02 16:25:32.835: E/AndroidRuntime(10275): at android.os.Handler.dispatchMessage(Handler.java:99)
05-02 16:25:32.835: E/AndroidRuntime(10275): at android.os.Looper.loop(Looper.java:130)
05-02 16:25:32.835: E/AndroidRuntime(10275): at android.app.ActivityThread.main(ActivityThread.java:3689)
05-02 16:25:32.835: E/AndroidRuntime(10275): at java.lang.reflect.Method.invokeNative(Native Method)
05-02 16:25:32.835: E/AndroidRuntime(10275): at java.lang.reflect.Method.invoke(Method.java:507)
05-02 16:25:32.835: E/AndroidRuntime(10275): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
05-02 16:25:32.835: E/AndroidRuntime(10275): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
05-02 16:25:32.835: E/AndroidRuntime(10275): at dalvik.system.NativeStart.main(Native Method)
The database seems to be not found.I have even put the database in the assets folder.Please help!
Click to expand...
Click to collapse
Have u created the android metadata table within the database?
DB File path
Here is my copyDatabase method. I used a File object to store the DB path. I was having the same issue.
Code:
public void copyDatabase(Context context) {
final File DB_PATH = context.getDatabasePath("phrasedb");
Log.i("Database",
"New database is being copied to device!");
byte[] buffer = new byte[1024];
OutputStream myOutput = null;
int length;
// Open your local db as the input stream
InputStream myInput = null;
File databaseFile = new File(DB_PATH.getPath());
Log.i("DATABASE", "File path " + DB_PATH.getPath());
if(!databaseFile.exists()){
databaseFile.mkdir();
Log.i("File", "File didn't exist...making dir!");
}
try
{
myInput = context.getAssets().open("phrasedb");
// transfer bytes from the inputfile to the
// outputfile
myOutput = new FileOutputStream(DB_PATH.getPath());
Log.i("DATABASE", "Destination path " + DB_PATH.getPath());
while((length = myInput.read(buffer)) > 0)
{
myOutput.write(buffer, 0, length);
Log.i("Database", "Copying...");
}
myOutput.close();
myOutput.flush();
myInput.close();
Log.i("Database",
"New database has been copied to device!");
}
catch(IOException e)
{
e.printStackTrace();
Log.e("exception", "Exception thrown while copying db!");
}
}
Related
Hello everyone I tried creating a simple calculator but when opening in my LWW it just force closes , so I am attaching the xmls and .java codes for your ready reference.
I am well versed in netbeans programming but new to android hence a helpful post will be really appreciated!
Bullet
MainActivity.java
Code:
package com.ptx.calcplus;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.EditText;
public class MainActivity extends Activity {
private EditText txtNum1;
private EditText txtNum2;
private EditText txtAns;
double a = Double.parseDouble(txtNum1.getText().toString()) ;
double b = Double.parseDouble(txtNum2.getText().toString());
double c=0;
public void add(double a,double b)
{
c=a+b;
txtAns.setText(""+c);
return;
}
public void sub(double a,double b)
{
c=a-b;
txtAns.setText(""+c);
return;
}
public void div(double a,double b)
{
if(b==0)
{
txtAns.setText("Number 2 can't be 0!");
}
else{
c=a/b;
txtAns.setText(""+c);
return;
}
}
public void mul(double a,double b)
{
c=a*b;
txtAns.setText(""+c);
return;
}
[user=439709]@override[/user]
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
[user=439709]@override[/user]
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;
}
}
strings.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">CalcPlus</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string>
<string name="btnPlus">+</string>
<string name="btnSub">-</string>
<string name="btnMul">*</string>
<string name="btnDiv">/</string>
<string name="txtNum2">Enter number 2 here</string>
<string name="txtNum1">Enter number 1 here</string>
<string name="txtAns">Result</string>
</resources>
activity_main.xml
Code:
<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=".MainActivity" >
<Button
android:id="@+id/btnMul"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/btnSub"
android:layout_alignBottom="@+id/btnSub"
android:layout_alignParentLeft="true"
android:text="@string/btnMul"
android:onClick="mul" />
<Button
android:id="@+id/btnSub"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="127dp"
android:layout_toRightOf="@+id/btnMul"
android:text="@string/btnSub"
android:onClick="sub" />
<Button
android:id="@+id/btnAdd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/btnSub"
android:layout_alignBottom="@+id/btnSub"
android:layout_toRightOf="@+id/btnSub"
android:text="@string/btnPlus"
android:onClick="add" />
<Button
android:id="@+id/btnDiv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/btnAdd"
android:layout_alignBottom="@+id/btnAdd"
android:layout_toRightOf="@+id/btnAdd"
android:text="@string/btnDiv"
android:onClick="div"/>
<EditText
android:id="@+id/txtNum2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/btnMul"
android:layout_alignLeft="@+id/btnMul"
android:layout_alignRight="@+id/btnDiv"
android:layout_marginBottom="90dp"
android:ems="10"
android:hint="@string/txtNum2"
android:inputType="numberDecimal" />
<EditText
android:id="@+id/txtNum1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/txtNum2"
android:layout_alignLeft="@+id/txtNum2"
android:layout_alignRight="@+id/txtNum2"
android:layout_marginBottom="39dp"
android:ems="10"
android:hint="@string/txtNum1"
android:inputType="numberDecimal" >
<requestFocus />
</EditText>
<EditText
android:id="@+id/txtAns"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/txtNum2"
android:layout_alignRight="@+id/btnDiv"
android:layout_below="@+id/btnMul"
android:layout_marginTop="40dp"
android:ems="10"
android:enabled="false"
android:hint="@string/txtAns"
android:linksClickable="false" />
</RelativeLayout>
Manifest
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ptx.calcplus"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.ptx.calcplus.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Hey BULLET, you seem to be on the right track but you've got a bit of tweaking to do.
Firstly, you need to tie all of your UI elements from XML to your activity. Do this in your on create method. My guess is that your force close is due to this line:
Code:
double a = Double.parseDouble(txtNum1.getText().toString()) ;
Your activity has no idea what txtNum1 is tied to, only that it is an EditText object. To set this up properly, keep your global edit text declarations and below is an example of what you'd add to your onCreate method:
Code:
txtNum1 = (EditText) findViewById(R.id.txtNum1);
You would need to do the same for your buttons and all of the elements that you have defined in your XML layout which you want to modify from your activity. (May I also suggest that you use a TextView instead of EditText to display the answer...)
Code:
Button buttonSubtract;
...
protected void onCreate(Bundle savedInstanceState) {
...
buttonSubtract = (Button) findViewById(R.id.btnSub);
...
}
You must also add methods for your buttons to wait for a click and perform the calculation methods you have written. To do this you would set up and onClickListener for each button.
I found TheNewBoston tutorials really handy when starting out. Here is an example of tying together the buttons and actions that they perform. It is very close to what you are trying to do.
http://www.youtube.com/watch?v=WjE-pWYElsE
Hope it helps. Feel free to ask any more questions.
Changed thing in accordance with video but still getting fc.
If possible could anyone paste the correct codes in my style?
BTW here are the code
strings.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">CalcPlus</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string>
<string name="btnp">+</string>
<string name="btns">-</string>
<string name="btnm">*</string>
<string name="btnd">/</string>
<string name="txt2">Enter number 2 here</string>
<string name="txt1">Enter number 1 here</string>
<string name="txta">Result</string>
</resources>
MainActivity.java
Code:
package com.ptx.calcplus;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends Activity {
private EditText txtN1;
private EditText txtN2;
private EditText txtAn;
Button Add,Sub,Div,Mul;
double a=Double.parseDouble(txtN1.getText().toString());
double b=Double.parseDouble(txtN2.getText().toString());
double c=0;
[user=439709]@override[/user]
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Add= (Button) findViewById(R.id.btnAdd);
Sub= (Button) findViewById(R.id.btnSub);
Div= (Button) findViewById(R.id.btnDiv);
Mul= (Button) findViewById(R.id.btnMul);
txtN1= (EditText) findViewById(R.id.txtNum1);
txtN2= (EditText) findViewById(R.id.txtNum2);
txtAn= (EditText) findViewById(R.id.txtAns);
Add.setOnClickListener(new View.OnClickListener() {
[user=439709]@override[/user]
public void onClick(View arg0) {
c=a+b;
txtAn.setText(""+c);
}
});
Sub.setOnClickListener(new View.OnClickListener() {
[user=439709]@override[/user]
public void onClick(View arg0) {
c=a+b;
txtAn.setText(""+c);
}
});
Mul.setOnClickListener(new View.OnClickListener() {
[user=439709]@override[/user]
public void onClick(View arg0) {
c=a+b;
txtAn.setText(""+c);
}
});
Div.setOnClickListener(new View.OnClickListener() {
[user=439709]@override[/user]
public void onClick(View arg0) {
c=a+b;
txtAn.setText(""+c);
}
});
}
[user=439709]@override[/user]
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;
}
}
activity_main.xml
Code:
<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=".MainActivity" >
<Button
android:id="@+id/btnMul"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/btnSub"
android:layout_alignBottom="@+id/btnSub"
android:layout_alignParentLeft="true"
android:text="@string/btnm"
android:onClick="mul" />
<Button
android:id="@+id/btnSub"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="127dp"
android:layout_toRightOf="@+id/btnMul"
android:text="@string/btns"
android:onClick="sub" />
<Button
android:id="@+id/btnAdd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/btnSub"
android:layout_alignBottom="@+id/btnSub"
android:layout_toRightOf="@+id/btnSub"
android:text="@string/btnp"
android:onClick="add" />
<Button
android:id="@+id/btnDiv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/btnAdd"
android:layout_alignBottom="@+id/btnAdd"
android:layout_toRightOf="@+id/btnAdd"
android:text="@string/btnd"
android:onClick="div"/>
<EditText
android:id="@+id/txtNum2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/btnMul"
android:layout_alignLeft="@+id/btnMul"
android:layout_alignRight="@+id/btnDiv"
android:layout_marginBottom="90dp"
android:ems="10"
android:hint="@string/txt2"
android:inputType="numberDecimal" />
<EditText
android:id="@+id/txtNum1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/txtNum2"
android:layout_alignLeft="@+id/txtNum2"
android:layout_alignRight="@+id/txtNum2"
android:layout_marginBottom="39dp"
android:ems="10"
android:hint="@string/txt1"
android:inputType="numberDecimal" >
<requestFocus />
</EditText>
<EditText
android:id="@+id/txtAns"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/txtNum2"
android:layout_alignRight="@+id/btnDiv"
android:layout_below="@+id/btnMul"
android:layout_marginTop="40dp"
android:ems="10"
android:enabled="false"
android:hint="@string/txta"
android:linksClickable="false" />
</RelativeLayout>
Please please help me out!
I've fixed it up a little and it runs perfectly on my phone.
MainActivity.java
Code:
package com.ptx.calcplus;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends Activity {
private EditText txtN1;
private EditText txtN2;
private EditText txtAn;
private Button Add, Sub, Div, Mul;
double a = 0, b = 0, c = 0;
[user=439709]@override[/user]
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Add = (Button) findViewById(R.id.btnAdd);
Sub = (Button) findViewById(R.id.btnSub);
Div = (Button) findViewById(R.id.btnDiv);
Mul = (Button) findViewById(R.id.btnMul);
txtN1 = (EditText) findViewById(R.id.txtNum1);
txtN2 = (EditText) findViewById(R.id.txtNum2);
txtAn = (EditText) findViewById(R.id.txtAns);
Add.setOnClickListener(new View.OnClickListener() {
[user=439709]@override[/user]
public void onClick(View arg0) {
a = Double.parseDouble(txtN1.getText().toString());
b = Double.parseDouble(txtN2.getText().toString());
c = a + b;
txtAn.setText(""+c);
}
});
Sub.setOnClickListener(new View.OnClickListener() {
[user=439709]@override[/user]
public void onClick(View arg0) {
a = Double.parseDouble(txtN1.getText().toString());
b = Double.parseDouble(txtN2.getText().toString());
txtAn.setText(""+c);
}
});
Mul.setOnClickListener(new View.OnClickListener() {
[user=439709]@override[/user]
public void onClick(View arg0) {
a = Double.parseDouble(txtN1.getText().toString());
b = Double.parseDouble(txtN2.getText().toString());
c = a * b;
txtAn.setText(""+c);
}
});
Div.setOnClickListener(new View.OnClickListener() {
[user=439709]@override[/user]
public void onClick(View arg0) {
a = Double.parseDouble(txtN1.getText().toString());
b = Double.parseDouble(txtN2.getText().toString());
c = a / b;
txtAn.setText(""+c);
}
});
}
[user=439709]@override[/user]
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
activity_main.xml
Code:
<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"
tools:context=".MainActivity" >
<Button
android:id="@+id/btnMul"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/btnSub"
android:layout_alignBottom="@+id/btnSub"
android:layout_alignParentLeft="true"
android:text="@string/btnm"
android:onClick="mul" />
<Button
android:id="@+id/btnSub"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="127dp"
android:layout_toRightOf="@+id/btnMul"
android:text="@string/btns"
android:onClick="sub" />
<Button
android:id="@+id/btnAdd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/btnSub"
android:layout_alignBottom="@+id/btnSub"
android:layout_toRightOf="@+id/btnSub"
android:text="@string/btnp"
android:onClick="add" />
<Button
android:id="@+id/btnDiv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/btnAdd"
android:layout_alignBottom="@+id/btnAdd"
android:layout_toRightOf="@+id/btnAdd"
android:text="@string/btnd"
android:onClick="div"/>
<EditText
android:id="@+id/txtNum2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/btnMul"
android:layout_alignLeft="@+id/btnMul"
android:layout_alignRight="@+id/btnDiv"
android:layout_marginBottom="90dp"
android:ems="10"
android:hint="@string/txt2"
android:inputType="numberDecimal" />
<EditText
android:id="@+id/txtNum1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/txtNum2"
android:layout_alignLeft="@+id/txtNum2"
android:layout_alignRight="@+id/txtNum2"
android:layout_marginBottom="39dp"
android:ems="10"
android:hint="@string/txt1"
android:inputType="numberDecimal" >
<requestFocus />
</EditText>
<EditText
android:id="@+id/txtAns"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/txtNum2"
android:layout_alignRight="@+id/btnDiv"
android:layout_below="@+id/btnMul"
android:layout_marginTop="40dp"
android:ems="10"
android:enabled="false"
android:hint="@string/txta"
android:linksClickable="false" />
</RelativeLayout>
I haven't touched the other files. Hope you get it working.
Works perfectly thank you.
Just tried to add dialog and clear, exit buttons but getting fc again. Please look into . I am really excited to make my first app.
Thank you once again
MainActivity.java
Code:
package com.ptx.calcplus;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends Activity {
private EditText txtN1;
private EditText txtN2;
private EditText txtAn;
private Button Add, Sub, Div, Mul, Clr, Ext;
private AlertDialog.Builder dlgAlert = new AlertDialog.Builder(this);
double a = 0, b = 0, c = 0;
[user=439709]@override[/user]
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Add = (Button) findViewById(R.id.btnAdd);
Sub = (Button) findViewById(R.id.btnSub);
Div = (Button) findViewById(R.id.btnDiv);
Mul = (Button) findViewById(R.id.btnMul);
Clr = (Button) findViewById(R.id.btnClr);
Ext = (Button) findViewById(R.id.btnExt);
txtN1 = (EditText) findViewById(R.id.txtNum1);
txtN2 = (EditText) findViewById(R.id.txtNum2);
txtAn = (EditText) findViewById(R.id.txtAns);
Add.setOnClickListener(new View.OnClickListener() {
[user=439709]@override[/user]
public void onClick(View arg0) {
a = Double.parseDouble(txtN1.getText().toString());
b = Double.parseDouble(txtN2.getText().toString());
if(txtN1.getText().toString().isEmpty()||txtN2.getText().toString().isEmpty()){
dlgAlert.setMessage("Please enter number in text box!");
dlgAlert.setTitle("Enter Number");
dlgAlert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {}});
dlgAlert.setCancelable(true);
dlgAlert.create().show();
}
else{
c=a+b;
txtAn.setText(""+c);
}
}
});
Sub.setOnClickListener(new View.OnClickListener() {
[user=439709]@override[/user]
public void onClick(View arg0) {
a = Double.parseDouble(txtN1.getText().toString());
b = Double.parseDouble(txtN2.getText().toString());
if(txtN1.getText().toString().isEmpty()||txtN2.getText().toString().isEmpty()){
dlgAlert.setMessage("Please enter number in text box!");
dlgAlert.setTitle("Enter Number");
dlgAlert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {}});
dlgAlert.setCancelable(true);
dlgAlert.create().show();
}
else{
c=a-b;
txtAn.setText(""+c);
}
}
});
Mul.setOnClickListener(new View.OnClickListener() {
[user=439709]@override[/user]
public void onClick(View arg0) {
a = Double.parseDouble(txtN1.getText().toString());
b = Double.parseDouble(txtN2.getText().toString());
if(txtN1.getText().toString().isEmpty()||txtN2.getText().toString().isEmpty()){
dlgAlert.setMessage("Please enter number in text box!");
dlgAlert.setTitle("Enter Number");
dlgAlert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {}});
dlgAlert.setCancelable(true);
dlgAlert.create().show();
}
else{
c=a*b;
txtAn.setText(""+c);
}
}
});
Div.setOnClickListener(new View.OnClickListener() {
[user=439709]@override[/user]
public void onClick(View arg0) {
a = Double.parseDouble(txtN1.getText().toString());
b = Double.parseDouble(txtN2.getText().toString());
if(txtN1.getText().toString().isEmpty()||txtN2.getText().toString().isEmpty()){
dlgAlert.setMessage("Please enter number in text box!");
dlgAlert.setTitle("Enter Number");
dlgAlert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {}});
dlgAlert.setCancelable(true);
dlgAlert.create().show();
}
else if(b==0)
{
dlgAlert.setMessage("Number can not be zero");
dlgAlert.setTitle("Divider Zero!");
dlgAlert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {}});
dlgAlert.setCancelable(true);
dlgAlert.create().show();
}
else{
c=a+b;
txtAn.setText(""+c);
}
}
});
Clr.setOnClickListener(new View.OnClickListener() {
[user=439709]@override[/user]
public void onClick(View arg0) {
txtN1.setText("");
txtN2.setText("");
txtAn.setText("");
}
});
Ext.setOnClickListener(new View.OnClickListener() {
[user=439709]@override[/user]
public void onClick(View arg0) {
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
});
}
[user=439709]@override[/user]
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;
}
}
activity_main.xml
Code:
<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"
tools:context=".MainActivity" >
<Button
android:id="@+id/btnMul"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/btnSub"
android:layout_alignBottom="@+id/btnSub"
android:layout_alignParentLeft="true"
android:text="@string/btnm"
android:onClick="mul" />
<Button
android:id="@+id/btnSub"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="127dp"
android:layout_toRightOf="@+id/btnMul"
android:text="@string/btns"
android:onClick="sub" />
<Button
android:id="@+id/btnAdd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/btnSub"
android:layout_alignBottom="@+id/btnSub"
android:layout_toRightOf="@+id/btnSub"
android:text="@string/btnp"
android:onClick="add" />
<Button
android:id="@+id/btnDiv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/btnAdd"
android:layout_alignBottom="@+id/btnAdd"
android:layout_toRightOf="@+id/btnAdd"
android:text="@string/btnd"
android:onClick="div"/>
<EditText
android:id="@+id/txtNum2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/btnMul"
android:layout_alignLeft="@+id/btnMul"
android:layout_alignRight="@+id/btnDiv"
android:layout_marginBottom="90dp"
android:ems="10"
android:hint="@string/txt2"
android:inputType="numberDecimal" />
<EditText
android:id="@+id/txtNum1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/txtNum2"
android:layout_alignLeft="@+id/txtNum2"
android:layout_alignRight="@+id/txtNum2"
android:layout_marginBottom="39dp"
android:ems="10"
android:hint="@string/txt1"
android:inputType="numberDecimal" >
<requestFocus />
</EditText>
<EditText
android:id="@+id/txtAns"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/btnMul"
android:ems="10"
android:enabled="false"
android:hint="@string/txta"
android:linksClickable="false" />
<Button
android:id="@+id/btnClr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/btnSub"
android:layout_below="@+id/txtAns"
android:layout_marginTop="21dp"
android:text="@string/btnc"
android:onClick="clr" />
<Button
android:id="@+id/btnExt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/btnClr"
android:layout_alignRight="@+id/txtAns"
android:text="@string/btne"
android:onClick="ext" />
</RelativeLayout>
Manifest
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ptx.calcplus"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.ptx.calcplus.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Strings.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">CalcPlus</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string>
<string name="btnp">+</string>
<string name="btns">-</string>
<string name="btnm">*</string>
<string name="btnd">/</string>
<string name="txt2">Enter number 2 here</string>
<string name="txt1">Enter number 1 here</string>
<string name="txta">Result</string>
<string name="btnc">Clear</string>
<string name="btne">Exit</string>
</resources>
Please help me out!
Instead of having people fix your errors, how about posting your logcat so we can give you ideas on how to fix them. You won't learn how to debug by having other people do it for you. Also, on your exit button click, all you need to do is "finish();" the activity. You don't need to launch an intent because then your app technically never terminates.
zalez said:
Instead of having people fix your errors, how about posting your logcat so we can give you ideas on how to fix them. You won't learn how to debug by having other people do it for you. Also, on your exit button click, all you need to do is "finish();" the activity. You don't need to launch an intent because then your app technically never terminates.
Click to expand...
Click to collapse
So here is the logcat
Code:
04-23 10:31:20.509: E/Trace(3960): error opening trace file: No such file or directory (2)
04-23 10:32:31.009: E/AndroidRuntime(4130): ... 11 more
This is not the part of the logcat we need.
If you want to finish the activity from the Listener, use that:
Code:
MainActivity.this.finish();
nikwen said:
This is not the part of the logcat we need.
If you want to finish the activity from the Listener, use that:
Code:
MainActivity.this.finish();
Click to expand...
Click to collapse
Pl reply how to get a logcat in eclipse!!
Bullet
[==)BULLET(==] said:
Pl reply how to get a logcat in eclipse!!
Bullet
Click to expand...
Click to collapse
Check this: http://www.youtube.com/watch?v=2AHJsRKa_J8
Will have a closer look at your source code later.
nikwen said:
Check this: http://www.youtube.com/watch?v=2AHJsRKa_J8
Will have a closer look at your source code later.
Click to expand...
Click to collapse
Please put those Log.i(String String); in my code where ever it is appropriate.
Here is the whole logcat. Please help!
04-23 05:36:12.523: E/Trace(831): error opening trace file: No such file or directory (2)
04-23 05:36:12.863: D/AndroidRuntime(831): Shutting down VM
04-23 05:36:12.893: W/dalvikvm(831): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
04-23 05:36:12.953: E/AndroidRuntime(831): FATAL EXCEPTION: main
04-23 05:36:12.953: E/AndroidRuntime(831): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.ptx.calcplus/com.ptx.calcplus.MainActivity}: java.lang.NullPointerException
04-23 05:36:12.953: E/AndroidRuntime(831): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2106)
04-23 05:36:12.953: E/AndroidRuntime(831): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
04-23 05:36:12.953: E/AndroidRuntime(831): at android.app.ActivityThread.access$600(ActivityThread.java:141)
04-23 05:36:12.953: E/AndroidRuntime(831): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
04-23 05:36:12.953: E/AndroidRuntime(831): at android.os.Handler.dispatchMessage(Handler.java:99)
04-23 05:36:12.953: E/AndroidRuntime(831): at android.os.Looper.loop(Looper.java:137)
04-23 05:36:12.953: E/AndroidRuntime(831): at android.app.ActivityThread.main(ActivityThread.java:5041)
04-23 05:36:12.953: E/AndroidRuntime(831): at java.lang.reflect.Method.invokeNative(Native Method)
04-23 05:36:12.953: E/AndroidRuntime(831): at java.lang.reflect.Method.invoke(Method.java:511)
04-23 05:36:12.953: E/AndroidRuntime(831): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
04-23 05:36:12.953: E/AndroidRuntime(831): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
04-23 05:36:12.953: E/AndroidRuntime(831): at dalvik.system.NativeStart.main(Native Method)
04-23 05:36:12.953: E/AndroidRuntime(831): Caused by: java.lang.NullPointerException
04-23 05:36:12.953: E/AndroidRuntime(831): at android.content.ContextWrapper.getApplicationInfo(ContextWrapper.java:140)
04-23 05:36:12.953: E/AndroidRuntime(831): at android.view.ContextThemeWrapper.getTheme(ContextThemeWrapper.java:103)
04-23 05:36:12.953: E/AndroidRuntime(831): at android.app.AlertDialog.resolveDialogTheme(AlertDialog.java:143)
04-23 05:36:12.953: E/AndroidRuntime(831): at android.app.AlertDialog$Builder.<init>(AlertDialog.java:360)
04-23 05:36:12.953: E/AndroidRuntime(831): at com.ptx.calcplus.MainActivity.<init>(MainActivity.java:17)
04-23 05:36:12.953: E/AndroidRuntime(831): at java.lang.Class.newInstanceImpl(Native Method)
04-23 05:36:12.953: E/AndroidRuntime(831): at java.lang.Class.newInstance(Class.java:1319)
04-23 05:36:12.953: E/AndroidRuntime(831): at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
04-23 05:36:12.953: E/AndroidRuntime(831): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
04-23 05:36:12.953: E/AndroidRuntime(831): ... 11 more
04-23 05:36:38.723: I/Process(831): Sending signal. PID: 831 SIG: 9
04-23 05:36:56.583: D/AndroidRuntime(867): Shutting down VM
04-23 05:36:56.644: W/dalvikvm(867): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
04-23 05:36:56.673: E/AndroidRuntime(867): FATAL EXCEPTION: main
04-23 05:36:56.673: E/AndroidRuntime(867): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.ptx.calcplus/com.ptx.calcplus.MainActivity}: java.lang.NullPointerException
04-23 05:36:56.673: E/AndroidRuntime(867): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2106)
04-23 05:36:56.673: E/AndroidRuntime(867): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
04-23 05:36:56.673: E/AndroidRuntime(867): at android.app.ActivityThread.access$600(ActivityThread.java:141)
04-23 05:36:56.673: E/AndroidRuntime(867): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
04-23 05:36:56.673: E/AndroidRuntime(867): at android.os.Handler.dispatchMessage(Handler.java:99)
04-23 05:36:56.673: E/AndroidRuntime(867): at android.os.Looper.loop(Looper.java:137)
04-23 05:36:56.673: E/AndroidRuntime(867): at android.app.ActivityThread.main(ActivityThread.java:5041)
04-23 05:36:56.673: E/AndroidRuntime(867): at java.lang.reflect.Method.invokeNative(Native Method)
04-23 05:36:56.673: E/AndroidRuntime(867): at java.lang.reflect.Method.invoke(Method.java:511)
04-23 05:36:56.673: E/AndroidRuntime(867): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
04-23 05:36:56.673: E/AndroidRuntime(867): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
04-23 05:36:56.673: E/AndroidRuntime(867): at dalvik.system.NativeStart.main(Native Method)
04-23 05:36:56.673: E/AndroidRuntime(867): Caused by: java.lang.NullPointerException
04-23 05:36:56.673: E/AndroidRuntime(867): at android.content.ContextWrapper.getApplicationInfo(ContextWrapper.java:140)
04-23 05:36:56.673: E/AndroidRuntime(867): at android.view.ContextThemeWrapper.getTheme(ContextThemeWrapper.java:103)
04-23 05:36:56.673: E/AndroidRuntime(867): at android.app.AlertDialog.resolveDialogTheme(AlertDialog.java:143)
04-23 05:36:56.673: E/AndroidRuntime(867): at android.app.AlertDialog$Builder.<init>(AlertDialog.java:360)
04-23 05:36:56.673: E/AndroidRuntime(867): at com.ptx.calcplus.MainActivity.<init>(MainActivity.java:17)
04-23 05:36:56.673: E/AndroidRuntime(867): at java.lang.Class.newInstanceImpl(Native Method)
04-23 05:36:56.673: E/AndroidRuntime(867): at java.lang.Class.newInstance(Class.java:1319)
04-23 05:36:56.673: E/AndroidRuntime(867): at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
04-23 05:36:56.673: E/AndroidRuntime(867): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
04-23 05:36:56.673: E/AndroidRuntime(867): ... 11 more
04-23 05:37:00.153: I/Process(867): Sending signal. PID: 867 SIG: 9
04-23 05:37:16.343: E/Trace(884): error opening trace file: No such file or directory (2)
04-23 05:37:16.564: D/AndroidRuntime(884): Shutting down VM
04-23 05:37:16.564: W/dalvikvm(884): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
04-23 05:37:16.613: E/AndroidRuntime(884): FATAL EXCEPTION: main
04-23 05:37:16.613: E/AndroidRuntime(884): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.ptx.calcplus/com.ptx.calcplus.MainActivity}: java.lang.NullPointerException
04-23 05:37:16.613: E/AndroidRuntime(884): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2106)
04-23 05:37:16.613: E/AndroidRuntime(884): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
04-23 05:37:16.613: E/AndroidRuntime(884): at android.app.ActivityThread.access$600(ActivityThread.java:141)
04-23 05:37:16.613: E/AndroidRuntime(884): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
04-23 05:37:16.613: E/AndroidRuntime(884): at android.os.Handler.dispatchMessage(Handler.java:99)
04-23 05:37:16.613: E/AndroidRuntime(884): at android.os.Looper.loop(Looper.java:137)
04-23 05:37:16.613: E/AndroidRuntime(884): at android.app.ActivityThread.main(ActivityThread.java:5041)
04-23 05:37:16.613: E/AndroidRuntime(884): at java.lang.reflect.Method.invokeNative(Native Method)
04-23 05:37:16.613: E/AndroidRuntime(884): at java.lang.reflect.Method.invoke(Method.java:511)
04-23 05:37:16.613: E/AndroidRuntime(884): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
04-23 05:37:16.613: E/AndroidRuntime(884): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
04-23 05:37:16.613: E/AndroidRuntime(884): at dalvik.system.NativeStart.main(Native Method)
04-23 05:37:16.613: E/AndroidRuntime(884): Caused by: java.lang.NullPointerException
04-23 05:37:16.613: E/AndroidRuntime(884): at android.content.ContextWrapper.getApplicationInfo(ContextWrapper.java:140)
04-23 05:37:16.613: E/AndroidRuntime(884): at android.view.ContextThemeWrapper.getTheme(ContextThemeWrapper.java:103)
04-23 05:37:16.613: E/AndroidRuntime(884): at android.app.AlertDialog.resolveDialogTheme(AlertDialog.java:143)
04-23 05:37:16.613: E/AndroidRuntime(884): at android.app.AlertDialog$Builder.<init>(AlertDialog.java:360)
04-23 05:37:16.613: E/AndroidRuntime(884): at com.ptx.calcplus.MainActivity.<init>(MainActivity.java:17)
04-23 05:37:16.613: E/AndroidRuntime(884): at java.lang.Class.newInstanceImpl(Native Method)
04-23 05:37:16.613: E/AndroidRuntime(884): at java.lang.Class.newInstance(Class.java:1319)
04-23 05:37:16.613: E/AndroidRuntime(884): at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
04-23 05:37:16.613: E/AndroidRuntime(884): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
04-23 05:37:16.613: E/AndroidRuntime(884): ... 11 more
04-23 05:38:20.383: D/AndroidRuntime(946): Shutting down VM
04-23 05:38:20.383: W/dalvikvm(946): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
04-23 05:38:20.444: E/AndroidRuntime(946): FATAL EXCEPTION: main
04-23 05:38:20.444: E/AndroidRuntime(946): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.ptx.calcplus/com.ptx.calcplus.MainActivity}: java.lang.NullPointerException
04-23 05:38:20.444: E/AndroidRuntime(946): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2106)
04-23 05:38:20.444: E/AndroidRuntime(946): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
04-23 05:38:20.444: E/AndroidRuntime(946): at android.app.ActivityThread.access$600(ActivityThread.java:141)
04-23 05:38:20.444: E/AndroidRuntime(946): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
04-23 05:38:20.444: E/AndroidRuntime(946): at android.os.Handler.dispatchMessage(Handler.java:99)
04-23 05:38:20.444: E/AndroidRuntime(946): at android.os.Looper.loop(Looper.java:137)
04-23 05:38:20.444: E/AndroidRuntime(946): at android.app.ActivityThread.main(ActivityThread.java:5041)
04-23 05:38:20.444: E/AndroidRuntime(946): at java.lang.reflect.Method.invokeNative(Native Method)
04-23 05:38:20.444: E/AndroidRuntime(946): at java.lang.reflect.Method.invoke(Method.java:511)
04-23 05:38:20.444: E/AndroidRuntime(946): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
04-23 05:38:20.444: E/AndroidRuntime(946): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
04-23 05:38:20.444: E/AndroidRuntime(946): at dalvik.system.NativeStart.main(Native Method)
04-23 05:38:20.444: E/AndroidRuntime(946): Caused by: java.lang.NullPointerException
04-23 05:38:20.444: E/AndroidRuntime(946): at android.content.ContextWrapper.getApplicationInfo(ContextWrapper.java:140)
04-23 05:38:20.444: E/AndroidRuntime(946): at android.view.ContextThemeWrapper.getTheme(ContextThemeWrapper.java:103)
04-23 05:38:20.444: E/AndroidRuntime(946): at android.app.AlertDialog.resolveDialogTheme(AlertDialog.java:143)
04-23 05:38:20.444: E/AndroidRuntime(946): at android.app.AlertDialog$Builder.<init>(AlertDialog.java:360)
04-23 05:38:20.444: E/AndroidRuntime(946): at com.ptx.calcplus.MainActivity.<init>(MainActivity.java:17)
04-23 05:38:20.444: E/AndroidRuntime(946): at java.lang.Class.newInstanceImpl(Native Method)
04-23 05:38:20.444: E/AndroidRuntime(946): at java.lang.Class.newInstance(Class.java:1319)
04-23 05:38:20.444: E/AndroidRuntime(946): at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
04-23 05:38:20.444: E/AndroidRuntime(946): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
04-23 05:38:20.444: E/AndroidRuntime(946): ... 11 more
04-23 05:50:13.903: E/Trace(1245): error opening trace file: No such file or directory (2)
04-23 05:50:14.063: D/AndroidRuntime(1245): Shutting down VM
04-23 05:50:14.103: W/dalvikvm(1245): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
04-23 05:50:14.133: E/AndroidRuntime(1245): FATAL EXCEPTION: main
04-23 05:50:14.133: E/AndroidRuntime(1245): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.ptx.calcplus/com.ptx.calcplus.MainActivity}: java.lang.NullPointerException
04-23 05:50:14.133: E/AndroidRuntime(1245): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2106)
04-23 05:50:14.133: E/AndroidRuntime(1245): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
04-23 05:50:14.133: E/AndroidRuntime(1245): at android.app.ActivityThread.access$600(ActivityThread.java:141)
04-23 05:50:14.133: E/AndroidRuntime(1245): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
04-23 05:50:14.133: E/AndroidRuntime(1245): at android.os.Handler.dispatchMessage(Handler.java:99)
04-23 05:50:14.133: E/AndroidRuntime(1245): at android.os.Looper.loop(Looper.java:137)
04-23 05:50:14.133: E/AndroidRuntime(1245): at android.app.ActivityThread.main(ActivityThread.java:5041)
04-23 05:50:14.133: E/AndroidRuntime(1245): at java.lang.reflect.Method.invokeNative(Native Method)
04-23 05:50:14.133: E/AndroidRuntime(1245): at java.lang.reflect.Method.invoke(Method.java:511)
04-23 05:50:14.133: E/AndroidRuntime(1245): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
04-23 05:50:14.133: E/AndroidRuntime(1245): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
04-23 05:50:14.133: E/AndroidRuntime(1245): at dalvik.system.NativeStart.main(Native Method)
04-23 05:50:14.133: E/AndroidRuntime(1245): Caused by: java.lang.NullPointerException
04-23 05:50:14.133: E/AndroidRuntime(1245): at android.content.ContextWrapper.getApplicationInfo(ContextWrapper.java:140)
04-23 05:50:14.133: E/AndroidRuntime(1245): at android.view.ContextThemeWrapper.getTheme(ContextThemeWrapper.java:103)
04-23 05:50:14.133: E/AndroidRuntime(1245): at android.app.AlertDialog.resolveDialogTheme(AlertDialog.java:143)
04-23 05:50:14.133: E/AndroidRuntime(1245): at android.app.AlertDialog$Builder.<init>(AlertDialog.java:360)
04-23 05:50:14.133: E/AndroidRuntime(1245): at com.ptx.calcplus.MainActivity.<init>(MainActivity.java:17)
04-23 05:50:14.133: E/AndroidRuntime(1245): at java.lang.Class.newInstanceImpl(Native Method)
04-23 05:50:14.133: E/AndroidRuntime(1245): at java.lang.Class.newInstance(Class.java:1319)
04-23 05:50:14.133: E/AndroidRuntime(1245): at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
04-23 05:50:14.133: E/AndroidRuntime(1245): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
04-23 05:50:14.133: E/AndroidRuntime(1245): ... 11 more
04-23 05:50:14.223: I/Process(1245): Sending signal. PID: 1245 SIG: 9
04-23 05:50:24.554: E/Trace(1262): error opening trace file: No such file or directory (2)
04-23 05:50:24.754: D/AndroidRuntime(1262): Shutting down VM
04-23 05:50:24.764: W/dalvikvm(1262): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
04-23 05:50:24.814: E/AndroidRuntime(1262): FATAL EXCEPTION: main
04-23 05:50:24.814: E/AndroidRuntime(1262): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.ptx.calcplus/com.ptx.calcplus.MainActivity}: java.lang.NullPointerException
04-23 05:50:24.814: E/AndroidRuntime(1262): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2106)
04-23 05:50:24.814: E/AndroidRuntime(1262): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
04-23 05:50:24.814: E/AndroidRuntime(1262): at android.app.ActivityThread.access$600(ActivityThread.java:141)
04-23 05:50:24.814: E/AndroidRuntime(1262): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
04-23 05:50:24.814: E/AndroidRuntime(1262): at android.os.Handler.dispatchMessage(Handler.java:99)
04-23 05:50:24.814: E/AndroidRuntime(1262): at android.os.Looper.loop(Looper.java:137)
04-23 05:50:24.814: E/AndroidRuntime(1262): at android.app.ActivityThread.main(ActivityThread.java:5041)
04-23 05:50:24.814: E/AndroidRuntime(1262): at java.lang.reflect.Method.invokeNative(Native Method)
04-23 05:50:24.814: E/AndroidRuntime(1262): at java.lang.reflect.Method.invoke(Method.java:511)
04-23 05:50:24.814: E/AndroidRuntime(1262): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
04-23 05:50:24.814: E/AndroidRuntime(1262): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
04-23 05:50:24.814: E/AndroidRuntime(1262): at dalvik.system.NativeStart.main(Native Method)
04-23 05:50:24.814: E/AndroidRuntime(1262): Caused by: java.lang.NullPointerException
04-23 05:50:24.814: E/AndroidRuntime(1262): at android.content.ContextWrapper.getApplicationInfo(ContextWrapper.java:140)
04-23 05:50:24.814: E/AndroidRuntime(1262): at android.view.ContextThemeWrapper.getTheme(ContextThemeWrapper.java:103)
04-23 05:50:24.814: E/AndroidRuntime(1262): at android.app.AlertDialog.resolveDialogTheme(AlertDialog.java:143)
04-23 05:50:24.814: E/AndroidRuntime(1262): at android.app.AlertDialog$Builder.<init>(AlertDialog.java:360)
04-23 05:50:24.814: E/AndroidRuntime(1262): at com.ptx.calcplus.MainActivity.<init>(MainActivity.java:17)
04-23 05:50:24.814: E/AndroidRuntime(1262): at java.lang.Class.newInstanceImpl(Native Method)
04-23 05:50:24.814: E/AndroidRuntime(1262): at java.lang.Class.newInstance(Class.java:1319)
04-23 05:50:24.814: E/AndroidRuntime(1262): at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
04-23 05:50:24.814: E/AndroidRuntime(1262): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
04-23 05:50:24.814: E/AndroidRuntime(1262): ... 11 more
04-23 05:53:39.893: E/Trace(1352): error opening trace file: No such file or directory (2)
04-23 05:53:40.044: D/AndroidRuntime(1352): Shutting down VM
04-23 05:53:40.044: W/dalvikvm(1352): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
04-23 05:53:40.063: E/AndroidRuntime(1352): FATAL EXCEPTION: main
04-23 05:53:40.063: E/AndroidRuntime(1352): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.ptx.calcplus/com.ptx.calcplus.MainActivity}: java.lang.NullPointerException
04-23 05:53:40.063: E/AndroidRuntime(1352): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2106)
04-23 05:53:40.063: E/AndroidRuntime(1352): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
04-23 05:53:40.063: E/AndroidRuntime(1352): at android.app.ActivityThread.access$600(ActivityThread.java:141)
04-23 05:53:40.063: E/AndroidRuntime(1352): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
04-23 05:53:40.063: E/AndroidRuntime(1352): at android.os.Handler.dispatchMessage(Handler.java:99)
04-23 05:53:40.063: E/AndroidRuntime(1352): at android.os.Looper.loop(Looper.java:137)
04-23 05:53:40.063: E/AndroidRuntime(1352): at android.app.ActivityThread.main(ActivityThread.java:5041)
04-23 05:53:40.063: E/AndroidRuntime(1352): at java.lang.reflect.Method.invokeNative(Native Method)
04-23 05:53:40.063: E/AndroidRuntime(1352): at java.lang.reflect.Method.invoke(Method.java:511)
04-23 05:53:40.063: E/AndroidRuntime(1352): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
04-23 05:53:40.063: E/AndroidRuntime(1352): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
04-23 05:53:40.063: E/AndroidRuntime(1352): at dalvik.system.NativeStart.main(Native Method)
04-23 05:53:40.063: E/AndroidRuntime(1352): Caused by: java.lang.NullPointerException
04-23 05:53:40.063: E/AndroidRuntime(1352): at android.content.ContextWrapper.getApplicationInfo(ContextWrapper.java:140)
04-23 05:53:40.063: E/AndroidRuntime(1352): at android.view.ContextThemeWrapper.getTheme(ContextThemeWrapper.java:103)
04-23 05:53:40.063: E/AndroidRuntime(1352): at android.app.AlertDialog.resolveDialogTheme(AlertDialog.java:143)
04-23 05:53:40.063: E/AndroidRuntime(1352): at android.app.AlertDialog$Builder.<init>(AlertDialog.java:360)
04-23 05:53:40.063: E/AndroidRuntime(1352): at com.ptx.calcplus.MainActivity.<init>(MainActivity.java:17)
04-23 05:53:40.063: E/AndroidRuntime(1352): at java.lang.Class.newInstanceImpl(Native Method)
04-23 05:53:40.063: E/AndroidRuntime(1352): at java.lang.Class.newInstance(Class.java:1319)
04-23 05:53:40.063: E/AndroidRuntime(1352): at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
04-23 05:53:40.063: E/AndroidRuntime(1352): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
04-23 05:53:40.063: E/AndroidRuntime(1352): ... 11 more
04-23 05:53:40.106: I/Process(1352): Sending signal. PID: 1352 SIG: 9
04-23 05:57:17.853: D/AndroidRuntime(1452): Shutting down VM
04-23 05:57:17.853: W/dalvikvm(1452): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
04-23 05:57:17.873: E/AndroidRuntime(1452): FATAL EXCEPTION: main
04-23 05:57:17.873: E/AndroidRuntime(1452): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.ptx.calcplus/com.ptx.calcplus.MainActivity}: java.lang.NullPointerException
04-23 05:57:17.873: E/AndroidRuntime(1452): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2106)
04-23 05:57:17.873: E/AndroidRuntime(1452): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
04-23 05:57:17.873: E/AndroidRuntime(1452): at android.app.ActivityThread.access$600(ActivityThread.java:141)
04-23 05:57:17.873: E/AndroidRuntime(1452): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
04-23 05:57:17.873: E/AndroidRuntime(1452): at android.os.Handler.dispatchMessage(Handler.java:99)
04-23 05:57:17.873: E/AndroidRuntime(1452): at android.os.Looper.loop(Looper.java:137)
04-23 05:57:17.873: E/AndroidRuntime(1452): at android.app.ActivityThread.main(ActivityThread.java:5041)
04-23 05:57:17.873: E/AndroidRuntime(1452): at java.lang.reflect.Method.invokeNative(Native Method)
04-23 05:57:17.873: E/AndroidRuntime(1452): at java.lang.reflect.Method.invoke(Method.java:511)
04-23 05:57:17.873: E/AndroidRuntime(1452): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
04-23 05:57:17.873: E/AndroidRuntime(1452): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
04-23 05:57:17.873: E/AndroidRuntime(1452): at dalvik.system.NativeStart.main(Native Method)
04-23 05:57:17.873: E/AndroidRuntime(1452): Caused by: java.lang.NullPointerException
04-23 05:57:17.873: E/AndroidRuntime(1452): at android.content.ContextWrapper.getApplicationInfo(ContextWrapper.java:140)
04-23 05:57:17.873: E/AndroidRuntime(1452): at android.view.ContextThemeWrapper.getTheme(ContextThemeWrapper.java:103)
04-23 05:57:17.873: E/AndroidRuntime(1452): at android.app.AlertDialog.resolveDialogTheme(AlertDialog.java:143)
04-23 05:57:17.873: E/AndroidRuntime(1452): at android.app.AlertDialog$Builder.<init>(AlertDialog.java:360)
04-23 05:57:17.873: E/AndroidRuntime(1452): at com.ptx.calcplus.MainActivity.<init>(MainActivity.java:18)
04-23 05:57:17.873: E/AndroidRuntime(1452): at java.lang.Class.newInstanceImpl(Native Method)
04-23 05:57:17.873: E/AndroidRuntime(1452): at java.lang.Class.newInstance(Class.java:1319)
04-23 05:57:17.873: E/AndroidRuntime(1452): at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
04-23 05:57:17.873: E/AndroidRuntime(1452): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
04-23 05:57:17.873: E/AndroidRuntime(1452): ... 11 more
Click to expand...
Click to collapse
[==)BULLET(==] said:
Please put those Log.i(String String); in my code where ever it is appropriate.
Here is the whole logcat. Please help!
Click to expand...
Click to collapse
They are not needed. I just wanted to show you how to get the log.
I will check the code later on my computer.
Thanks for the log.
---------- Post added at 03:04 PM ---------- Previous post was at 02:10 PM ----------
[==)BULLET(==] said:
Works perfectly thank you.
Just tried to add dialog and clear, exit buttons but getting fc again. Please look into . I am really excited to make my first app.
Thank you once again
MainActivity.java
Code:
package com.ptx.calcplus;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends Activity {
private EditText txtN1;
private EditText txtN2;
private EditText txtAn;
private Button Add, Sub, Div, Mul, Clr, Ext;
private AlertDialog.Builder dlgAlert = new AlertDialog.Builder(this);
double a = 0, b = 0, c = 0;
[user=439709]@override[/user]
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Add = (Button) findViewById(R.id.btnAdd);
Sub = (Button) findViewById(R.id.btnSub);
Div = (Button) findViewById(R.id.btnDiv);
Mul = (Button) findViewById(R.id.btnMul);
Clr = (Button) findViewById(R.id.btnClr);
Ext = (Button) findViewById(R.id.btnExt);
txtN1 = (EditText) findViewById(R.id.txtNum1);
txtN2 = (EditText) findViewById(R.id.txtNum2);
txtAn = (EditText) findViewById(R.id.txtAns);
Add.setOnClickListener(new View.OnClickListener() {
[user=439709]@override[/user]
public void onClick(View arg0) {
a = Double.parseDouble(txtN1.getText().toString());
b = Double.parseDouble(txtN2.getText().toString());
if(txtN1.getText().toString().isEmpty()||txtN2.getText().toString().isEmpty()){
dlgAlert.setMessage("Please enter number in text box!");
dlgAlert.setTitle("Enter Number");
dlgAlert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {}});
dlgAlert.setCancelable(true);
dlgAlert.create().show();
}
else{
c=a+b;
txtAn.setText(""+c);
}
}
});
Sub.setOnClickListener(new View.OnClickListener() {
[user=439709]@override[/user]
public void onClick(View arg0) {
a = Double.parseDouble(txtN1.getText().toString());
b = Double.parseDouble(txtN2.getText().toString());
if(txtN1.getText().toString().isEmpty()||txtN2.getText().toString().isEmpty()){
dlgAlert.setMessage("Please enter number in text box!");
dlgAlert.setTitle("Enter Number");
dlgAlert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {}});
dlgAlert.setCancelable(true);
dlgAlert.create().show();
}
else{
c=a-b;
txtAn.setText(""+c);
}
}
});
Mul.setOnClickListener(new View.OnClickListener() {
[user=439709]@override[/user]
public void onClick(View arg0) {
a = Double.parseDouble(txtN1.getText().toString());
b = Double.parseDouble(txtN2.getText().toString());
if(txtN1.getText().toString().isEmpty()||txtN2.getText().toString().isEmpty()){
dlgAlert.setMessage("Please enter number in text box!");
dlgAlert.setTitle("Enter Number");
dlgAlert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {}});
dlgAlert.setCancelable(true);
dlgAlert.create().show();
}
else{
c=a*b;
txtAn.setText(""+c);
}
}
});
Div.setOnClickListener(new View.OnClickListener() {
[user=439709]@override[/user]
public void onClick(View arg0) {
a = Double.parseDouble(txtN1.getText().toString());
b = Double.parseDouble(txtN2.getText().toString());
if(txtN1.getText().toString().isEmpty()||txtN2.getText().toString().isEmpty()){
dlgAlert.setMessage("Please enter number in text box!");
dlgAlert.setTitle("Enter Number");
dlgAlert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {}});
dlgAlert.setCancelable(true);
dlgAlert.create().show();
}
else if(b==0)
{
dlgAlert.setMessage("Number can not be zero");
dlgAlert.setTitle("Divider Zero!");
dlgAlert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {}});
dlgAlert.setCancelable(true);
dlgAlert.create().show();
}
else{
c=a+b;
txtAn.setText(""+c);
}
}
});
Clr.setOnClickListener(new View.OnClickListener() {
[user=439709]@override[/user]
public void onClick(View arg0) {
txtN1.setText("");
txtN2.setText("");
txtAn.setText("");
}
});
Ext.setOnClickListener(new View.OnClickListener() {
[user=439709]@override[/user]
public void onClick(View arg0) {
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
});
}
[user=439709]@override[/user]
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;
}
}
Please help me out!
Click to expand...
Click to collapse
It is a similar mistake. You cannot do anything related with Android views in your field declarations.
You need to do it in your onCreate method, if you load the layout from a xml, after the setContentView method. So change it to this:
MainActivity.java
Code:
package com.ptx.calcplus;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends Activity {
private EditText txtN1;
private EditText txtN2;
private EditText txtAn;
private Button Add, Sub, Div, Mul, Clr, Ext;
private AlertDialog.Builder dlgAlert;
double a = 0, b = 0, c = 0;
[user=439709]@override[/user]
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Add = (Button) findViewById(R.id.btnAdd);
... //your other stuff
dlgAlert = new AlertDialog.Builder(this);
...
This should work. Try it.
You're targetting min sdk of 8, which doesn't allow checking if string ".isEmpty()", which IF I'M NOT WRONG, is not included in older version of Android due to different version of Java. So I've changed it to check if the length is less than 0 before calculating.
Code:
.length() < 1
Secondly, you're converting the values of the Textbox BEFORE you check if the input is empty or not. Check before converting. Because if your input is empty, it is unable to convert a NULL into a double.
Lastly, one small error. Your DIVIDE is still PLUS. I've corrected it for you.
Sorry for the late reply! Hope there ain't any error.
Oh, one small tip. Try reading up "Try and Catch" for Android. Good for preventing force closing of apps.
Code:
package com.example.caltest;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends Activity {
private EditText txtN1;
private EditText txtN2;
private EditText txtAn;
private Button Add, Sub, Div, Mul, Clr, Ext;
private AlertDialog.Builder dlgAlert;
double a = 0, b = 0, c = 0;
[user=439709]@override[/user]
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
dlgAlert = new AlertDialog.Builder(MainActivity.this);
Add = (Button) findViewById(R.id.btnAdd);
Sub = (Button) findViewById(R.id.btnSub);
Div = (Button) findViewById(R.id.btnDiv);
Mul = (Button) findViewById(R.id.btnMul);
Clr = (Button) findViewById(R.id.btnClr);
Ext = (Button) findViewById(R.id.btnExt);
txtN1 = (EditText) findViewById(R.id.txtNum1);
txtN2 = (EditText) findViewById(R.id.txtNum2);
txtAn = (EditText) findViewById(R.id.txtAns);
Add.setOnClickListener(new View.OnClickListener() {
[user=439709]@override[/user]
public void onClick(View arg0) {
if (txtN1.getText().toString().length() < 1
|| txtN2.getText().toString().length() < 1) {
dlgAlert.setMessage("Please enter number in text box!");
dlgAlert.setTitle("Enter Number");
dlgAlert.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
}
});
dlgAlert.setCancelable(true);
dlgAlert.create().show();
} else {
a = Double.parseDouble(txtN1.getText().toString());
b = Double.parseDouble(txtN2.getText().toString());
c = a + b;
txtAn.setText("" + c);
}
}
});
Sub.setOnClickListener(new View.OnClickListener() {
[user=439709]@override[/user]
public void onClick(View arg0) {
if (txtN1.getText().toString().length() < 1
|| txtN2.getText().toString().length() < 1) {
dlgAlert.setMessage("Please enter number in text box!");
dlgAlert.setTitle("Enter Number");
dlgAlert.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
}
});
dlgAlert.setCancelable(true);
dlgAlert.create().show();
} else {
a = Double.parseDouble(txtN1.getText().toString());
b = Double.parseDouble(txtN2.getText().toString());
c = a - b;
txtAn.setText("" + c);
}
}
});
Mul.setOnClickListener(new View.OnClickListener() {
[user=439709]@override[/user]
public void onClick(View arg0) {
if (txtN1.getText().toString().length() < 1
|| txtN2.getText().toString().length() < 1) {
dlgAlert.setMessage("Please enter number in text box!");
dlgAlert.setTitle("Enter Number");
dlgAlert.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
}
});
dlgAlert.setCancelable(true);
dlgAlert.create().show();
} else {
a = Double.parseDouble(txtN1.getText().toString());
b = Double.parseDouble(txtN2.getText().toString());
c = a * b;
txtAn.setText("" + c);
}
}
});
Div.setOnClickListener(new View.OnClickListener() {
[user=439709]@override[/user]
public void onClick(View arg0) {
if (txtN1.getText().toString().length() < 1
|| txtN2.getText().toString().length() < 1) {
dlgAlert.setMessage("Please enter number in text box!");
dlgAlert.setTitle("Enter Number");
dlgAlert.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
}
});
dlgAlert.setCancelable(true);
dlgAlert.create().show();
} else if (b == 0) {
dlgAlert.setMessage("Number can not be zero");
dlgAlert.setTitle("Divider Zero!");
dlgAlert.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
}
});
dlgAlert.setCancelable(true);
dlgAlert.create().show();
} else {
a = Double.parseDouble(txtN1.getText().toString());
b = Double.parseDouble(txtN2.getText().toString());
c = a/b;
txtAn.setText("" + c);
}
}
});
Clr.setOnClickListener(new View.OnClickListener() {
[user=439709]@override[/user]
public void onClick(View arg0) {
txtN1.setText("");
txtN2.setText("");
txtAn.setText("");
}
});
Ext.setOnClickListener(new View.OnClickListener() {
[user=439709]@override[/user]
public void onClick(View arg0) {
finish();
}
});
}
[user=439709]@override[/user]
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;
}
}
@nikwen @frenzyboi
Thank you to both of you from the bottom of my heart.
Really feeling awesome after seeing my first app running and rocking.
Any tips for what to do next?
Once again thank you to both of you!!
Sincere Regards
Bullet
[==)BULLET(==] said:
@nikwen @frenzyboi
Thank you both of you from the bottom of my heart.
Real feeling awesome after seeing my first app running and rocking.
Any tips for what to do next?
Once again thank you to both of you!!
Sincere Regards
Bullet
Click to expand...
Click to collapse
You are welcome.
My tips (because you asked me ):
I have started many projects and finished few of them.
The point is: Make an app you NEED or one you think of "That would be VERY cool".
The ones I have needed have always been the ones I have finished.
Good luck.
(Maybe consider creating a game or build an app that does annoying things automatically which you normally have to do yourself.)
nikwen said:
You are welcome.
My tips (because you asked me ):
I have started many projects and finished few of them.
The point is: Make an app you NEED or one you think of "That would be VERY cool".
The ones I have needed have always been the ones I have finished.
Good luck.
(Maybe consider creating a game or build an app that does annoying things automatically which you normally have to do yourself.)
Click to expand...
Click to collapse
I agree with nikwen. The apps you use will be the apps you finish. My advice to you would be to start your calculator over. Try to do it from start to finish and add features or improve on ones you currently have. For instance, add a feature that logs your input and calculation similar to the calculators that print on what they are doing on paper. Once you get the basics down, then you should move on to something more advanced.
Learn and love your logcats. It will help you so much in the debug process.
Im trying to start a simple app and i need to display on a SurfaceView the preview of the cam as soon as the App start.
i added the permission to the manifest:
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
and my code:
Code:
import android.content.Context;
import android.hardware.Camera;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
public class MainActivity extends SurfaceView implements SurfaceHolder.Callback{
SurfaceView mSurfaceView;
private SurfaceHolder mHolder;
public Camera camera = null;
public MainActivity(Context context) {
super(context);
mSurfaceView = (SurfaceView) findViewById(R.id.surfaceView);
mHolder = mSurfaceView.getHolder();
mHolder.addCallback(this);
mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}
[user=439709]@override[/user]
public void surfaceCreated(SurfaceHolder holder) {
camera = Camera.open();
try{
camera.setPreviewDisplay(mHolder);
} catch(Exception e){
}
}
[user=439709]@override[/user]
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
Camera.Parameters params = camera.getParameters();
params.setPreviewSize(width,height);
camera.setParameters(params);
camera.startPreview();
}
[user=439709]@override[/user]
public void surfaceDestroyed(SurfaceHolder holder) {
camera.stopPreview();
camera = null;
}
}
Ive looked for many tutorial and all technically do the same or smiliart stuff. But the app crashes. I cant find a solution
LogCat
Code:
06-01 12:39:12.456 616-841/system_process I/ActivityManager: START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.example.droidcam/.MainActivity bnds=[240,408][240,408]} from pid 861
06-01 12:39:12.596 616-841/system_process D/dalvikvm: GC_FOR_ALLOC freed 1352K, 16% free 11518K/13560K, paused 112ms, total 118ms
06-01 12:39:12.636 2744-2744/? D/dalvikvm: Late-enabling CheckJNI
06-01 12:39:12.646 616-881/system_process I/ActivityManager: Start proc com.example.droidcam for activity com.example.droidcam/.MainActivity: pid=2744 uid=10019 gids={50019, 1006, 1028}
06-01 12:39:12.746 2744-2744/com.example.droidcam E/Trace: error opening trace file: No such file or directory (2)
06-01 12:39:12.826 2744-2744/com.example.droidcam D/dalvikvm: newInstance failed: no <init>()
06-01 12:39:12.836 2744-2744/com.example.droidcam D/AndroidRuntime: Shutting down VM
06-01 12:39:12.836 2744-2744/com.example.droidcam W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x2b5d9930)
06-01 12:39:12.836 2744-2744/com.example.droidcam E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.droidcam/com.example.droidcam.MainActivity}: java.lang.InstantiationException: can't instantiate class com.example.droidcam.MainActivity; no empty constructor
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2223)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2357)
at android.app.ActivityThread.access$600(ActivityThread.java:153)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1247)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5226)
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:795)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.InstantiationException: can't instantiate class com.example.droidcam.MainActivity; no empty constructor
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1319)
at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2214)
... 11 more
06-01 12:39:12.836 616-1341/system_process W/ActivityManager: Force finishing activity com.example.droidcam/.MainActivity
06-01 12:39:12.986 616-650/system_process D/dalvikvm: GC_FOR_ALLOC freed 1696K, 24% free 10472K/13772K, paused 76ms, total 77ms
06-01 12:39:13.387 616-647/system_process W/ActivityManager: Activity pause timeout for ActivityRecord{2bd8aff0 u0 com.example.droidcam/.MainActivity}
06-01 12:39:18.952 2744-2744/? I/Process: Sending signal. PID: 2744 SIG: 9
06-01 12:39:18.952 616-943/system_process I/ActivityManager: Process com.example.droidcam (pid 2744) has died.
06-01 12:39:19.002 616-616/system_process W/InputMethodManagerService: Window already focused, ignoring focus gain of: [email protected] attribute=null, token = [email protected]
Please put your code into code tags.
EDIT: Thanks.
and Post/check logcats.
just saying it crashes is too vague.
out of ideas said:
and Post/check logcats.
just saying it crashes is too vague.
Click to expand...
Click to collapse
On Eclipse i know how to show the windows of the LogCat, but cant really find it here on Android Studio.
Im a bit newby about this sorry, coming from PHP using just Notepad.
Guess i found it, added log cat
I saw some tutorial like this, im not sure why it doesnt start.
Is it for te onCreate method missing? but i saw that for other works anyway like this
Btw i've also triyed an other way, but stills give me errors. i could upload that one too, different logcat.
Hope one of the two could be solved
Code:
import android.app.Activity;
import android.hardware.Camera;
import android.os.Bundle;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import java.io.IOException;
public class MainActivity extends Activity implements SurfaceHolder.Callback{
/* VARIABILI PRIVATE */
private SurfaceView mSurfaceView;
private SurfaceHolder mSurfaceHolder;
private Camera mCamera;
/** Called when the activity is first created. */
[user=439709]@override[/user]
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mSurfaceView = (SurfaceView)findViewById(R.id.surfaceView);
mSurfaceHolder = mSurfaceView.getHolder();
mSurfaceHolder.addCallback(this);
mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}
[user=439709]@override[/user]
public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
Camera.Parameters params = mCamera.getParameters();
params.setPreviewSize(arg2, arg3);
mCamera.setParameters(params);
try {
//lancio la preview
mCamera.setPreviewDisplay(arg0);
mCamera.startPreview();
} catch (IOException e) {
//gestione errore
}
}
[user=439709]@override[/user]
public void surfaceCreated(SurfaceHolder holder) {
mCamera = Camera.open();
}
[user=439709]@override[/user]
public void surfaceDestroyed(SurfaceHolder holder) {
mCamera.stopPreview();
mCamera.release();
}
logcat
Code:
06-01 13:32:31.187 616-661/system_process I/ActivityManager: Start proc com.android.vending for service com.android.vending/com.google.android.finsky.services.ContentSyncService: pid=25552 uid=10005 gids={50005, 3003, 1015, 1028}
06-01 13:32:31.227 25552-25552/com.android.vending E/Trace: error opening trace file: No such file or directory (2)
06-01 13:32:31.387 616-841/system_process I/ActivityManager: START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.example.droidcam/.MainActivity bnds=[240,408][240,408]} from pid 861
06-01 13:32:31.437 25566-25566/? D/dalvikvm: Late-enabling CheckJNI
06-01 13:32:31.447 616-1341/system_process I/ActivityManager: Start proc com.example.droidcam for activity com.example.droidcam/.MainActivity: pid=25566 uid=10019 gids={50019, 1006, 1028}
06-01 13:32:31.607 25566-25566/com.example.droidcam E/Trace: error opening trace file: No such file or directory (2)
06-01 13:32:31.787 25552-25552/com.android.vending D/Finsky: [1] FinskyApp.onCreate: Initializing network with DFE https://android.clients.google.com/fdfe/
06-01 13:32:31.987 25552-25552/com.android.vending D/Finsky: [1] DailyHygiene.goMakeHygieneIfDirty: No need to run daily hygiene.
06-01 13:32:32.037 25552-25552/com.android.vending W/Settings: Setting download_manager_max_bytes_over_mobile has moved from android.provider.Settings.Secure to android.provider.Settings.Global.
06-01 13:32:32.037 25552-25552/com.android.vending W/Settings: Setting download_manager_recommended_max_bytes_over_mobile has moved from android.provider.Settings.Secure to android.provider.Settings.Global.
06-01 13:32:32.178 616-881/system_process D/dalvikvm: GC_FOR_ALLOC freed 656K, 26% free 11321K/15124K, paused 82ms, total 86ms
06-01 13:32:32.238 25566-25566/com.example.droidcam D/libEGL: loaded /system/lib/egl/libEGL_adreno200.so
06-01 13:32:32.258 25566-25566/com.example.droidcam D/libEGL: loaded /system/lib/egl/libGLESv1_CM_adreno200.so
06-01 13:32:32.258 25566-25566/com.example.droidcam D/libEGL: loaded /system/lib/egl/libGLESv2_adreno200.so
06-01 13:32:32.268 25566-25566/com.example.droidcam I/Adreno200-EGL: <qeglDrvAPI_eglInitialize:294>: EGL 1.4 QUALCOMM build: AU_LINUX_ANDROID_JB.04.01.01.00.036_msm8960_JB_CL2644550_release_AU (CL2644550)
Build Date: 07/31/12 Tue
Local Branch:
Remote Branch: quic/master
Local Patches: NONE
Reconstruct Branch: AU_LINUX_ANDROID_JB.04.01.01.00.036 + NOTHING
06-01 13:32:32.318 25566-25566/com.example.droidcam D/OpenGLRenderer: Enabling debug mode 0
06-01 13:32:32.348 256-515/? I/AwesomePlayer: setDataSource_l(URL suppressed)
06-01 13:32:32.378 256-25622/? D/MediaExtractor: returning default extractor
06-01 13:32:32.388 256-515/? I/AwesomePlayer: setDataSource_l(URL suppressed)
06-01 13:32:32.408 256-25626/? D/MediaExtractor: returning default extractor
06-01 13:32:32.408 256-515/? I/CameraClient: Opening camera 0
06-01 13:32:32.408 256-515/? W/ServiceManager: Permission failure: com.sonyericsson.permission.CAMERA_EXTENDED from uid=10019 pid=25566
06-01 13:32:32.438 256-25630/? I/caladbolg: 3348999538 cald_camctrl.c (6713) 25630 P [SVR] -945967758 + Cald_CamCtrl_PowerUp
06-01 13:32:32.438 256-25630/? I/caladbolg: 3348999630 cald_camctrl.c (7484) 25630 P [SVR] -945967666 + Cald_CamCtrl_FSM_Func_PowerUp
06-01 13:32:32.438 256-25630/? I/caladbolg: 3349003170 cald_hal_qct.c (2789) 25630 P [HAL] -945964126 + Cald_Hal_Qct_If_PowerUp
06-01 13:32:32.438 256-25630/? I/caladbolg: 3349003323 cald_hal_qct.c (2847) 25630 P [HAL] -945963973 - Cald_Hal_Qct_If_PowerUp (0)
06-01 13:32:32.438 256-25630/? I/caladbolg: 3349004665 cald_camctrl.c (7563) 25630 P [SVR] -945962631 - Cald_CamCtrl_FSM_Func_PowerUp (0)
06-01 13:32:32.438 256-25630/? I/caladbolg: 3349004726 cald_camctrl.c (6720) 25630 P [SVR] -945962570 - Cald_CamCtrl_PowerUp (0)
06-01 13:32:32.448 256-25630/? E/caladbolg: 3349014431 cald_camctrl.c (11888) 25630 E [SVR] PreviewSize Invalid param: value[402x527]
06-01 13:32:32.458 25566-25566/com.example.droidcam D/AndroidRuntime: Shutting down VM
06-01 13:32:32.458 25566-25566/com.example.droidcam W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x2b5d9930)
06-01 13:32:32.488 25566-25566/com.example.droidcam E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: setParameters failed
at android.hardware.Camera.native_setParameters(Native Method)
at android.hardware.Camera.setParameters(Camera.java:1496)
at com.example.droidcam.MainActivity.surfaceChanged(MainActivity.java:41)
at android.view.SurfaceView.updateWindow(SurfaceView.java:580)
at android.view.SurfaceView.access$000(SurfaceView.java:86)
at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:174)
at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:680)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1842)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:989)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4351)
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:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5226)
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:795)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
at dalvik.system.NativeStart.main(Native Method)
06-01 13:32:32.498 616-943/system_process W/ActivityManager: Force finishing activity com.example.droidcam/.MainActivity
06-01 13:32:32.688 25552-25552/com.android.vending D/Finsky: [1] 2.run: Loaded library for account: [i1YaFxIWaZrcOQ26zxNX5K0RvvY]
06-01 13:32:32.688 25552-25552/com.android.vending D/Finsky: [1] 2.run: Finished loading 1 libraries.
06-01 13:32:32.908 25552-25552/com.android.vending D/Finsky: [1] 5.onFinished: Installation state replication succeeded.
06-01 13:32:33.018 616-647/system_process W/ActivityManager: Activity pause timeout for ActivityRecord{2b946870 u0 com.example.droidcam/.MainActivity}
In Android you normally do not use the constructor of an Activity for anything.
Use the onCreate method instead.
EDIT: The log says that the constructor must be empty.
nikwen said:
In Android you normally do not use the constructor of an Activity for anything.
Use the onCreate method instead.
EDIT: The log says that the constructor must be empty.
Click to expand...
Click to collapse
I thought about that (even if i saw video tutorial doing it) so i tried wht onCreate method and now it seams to give problem with the setParameters?
Ive uploaded the new code and logcats before
Ah. Check this: http://stackoverflow.com/questions/3890381/camera-setparameters-failed-in-android
nikwen said:
Ah. Check this: http://stackoverflow.com/questions/3890381/camera-setparameters-failed-in-android
Click to expand...
Click to collapse
i tryed that at th beggin, and didnt work, in fact i tried it again and still give me the same error apparently
While I'm still learning myself, it looks like you are getting a failed camera permission. And then it tries to pass in an invalid parameter to the camera.
deniel said:
I/CameraClient: Opening camera 0
06-01 13:32:32.408 256-515/? W/ServiceManager: Permission failure: com.sonyericsson.permission.CAMERA_EXTENDED from uid=10019 pid=25566
06-01 13:32:32.448 256-25630/? E/caladbolg: 3349014431 cald_camctrl.c (11888) 25630 E [SVR] PreviewSize Invalid param: value[402x527]
[/CODE]
Click to expand...
Click to collapse
Sent from a Toasted Devil
netwokz said:
While I'm still learning myself, it looks like you are getting a failed camera permission. And then it tries to pass in an invalid parameter to the camera.
Sent from a Toasted Devil
Click to expand...
Click to collapse
But cant understand which one and how should i do. it ryed the 2 ways everybody does
What phone are you trying this on? Have you tried it in an emulator?
After getting home and I was able to try your second piece of code. It looks like it is a problem with <CODE>params.setPreviewSize(arg2, arg3);</CODE>, it doesn't like the width and height arguments. I found THIS(second answer). and after plugging it into your code it was working for me. If you like I can show you the modified code, altho its real easy to plug in.
netwokz said:
After getting home and I was able to try your second piece of code. It looks like it is a problem with <CODE>params.setPreviewSize(arg2, arg3);</CODE>, it doesn't like the width and height arguments. I found THIS(second answer). and after plugging it into your code it was working for me. If you like I can show you the modified code, altho its real easy to plug in.
Click to expand...
Click to collapse
i tryed his first example and finally i get his "distoted" image. When i'll have time ill try the rets thnk u very much
ill try this:
Code:
Camera.Size getBestPreviewSize(int width, int height, Camera.Parameters parameters) {
Camera.Size result=null;
float dr = Float.MAX_VALUE;
float ratio = (float)width/(float)height;
for (Camera.Size size : parameters.getSupportedPreviewSizes()) {
float r = (float)size.width/(float)size.height;
if( Math.abs(r - ratio) < dr && size.width <= width && size.height <= height ) {
dr = Math.abs(r - ratio);
result = size;
}
}
return result;
}
Code:
ublic void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
// Now that the size is known, set up the camera parameters and begin
// the preview.
if (isPreviewRunning) {
mCamera.stopPreview();
}
Camera.Parameters parameters = mCamera.getParameters();
List<Size> sizes = parameters.getSupportedPreviewSizes();
Size optimalSize = getBestPreviewSize( w, h, parameters);
parameters.setPreviewSize(optimalSize.width, optimalSize.height);
mCamera.setParameters(parameters);
mCamera.startPreview();
isPreviewRunning =true;
}
im not sure abot the 3rd parameter of the getBestPreviewSize method which one is it. Like this is still distorted
Yeah, I could never fix the distortion back when I was trying my camera app. But I think I will tinker with it again. Keep this updated if you find anything, I will also.
Sent from a Toasted Devil
Hello,
I am currently trying to have a webview that listens to a long click and loads a website once longclicked.
However, it crashes and i would love to find out why, or how to fix it
I do have to state that this crash Occurs on Samsung and LG hardware, but not on the Nexus 4 or the Emulator (Nexus 7)
Code:
package com.example.homehub;
import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnLongClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;
public class MainActivity extends Activity {
WebView webView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Go Fullscreen (Just in case)
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
// Display the layout
setContentView(R.layout.activity_main);
// Define the Web View
webView = (WebView) findViewById(R.id.webView1);
// Setup
webView.getSettings().setCacheMode( WebSettings.LOAD_DEFAULT );
webView.setLongClickable(true);
// Handle Links internally
webView.setWebViewClient(new WebViewClient() { });
// Using Latest Chrome Client
webView.setWebChromeClient(new WebChromeClient());
// Browser Settings
webView.getSettings().setAllowFileAccess( true );
webView.getSettings().setAppCacheEnabled( true );
webView.getSettings().setJavaScriptEnabled( true );
// Go to Default URL
webView.loadUrl("http://google.com" );
// Long Click Listener
webView.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
// Grab URL
String webUrl = webView.getUrl();
// Show the URL (This works)
Toast.makeText(getApplicationContext(), webUrl, Toast.LENGTH_SHORT).show();
// This request crashes
webView.loadUrl("http://www.yahoo.com");
return true;
}
});
}
// Back Button behaviour (Either browser back, or exit)
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
WebView webView = (WebView) findViewById(R.id.webView1);
if(event.getAction() == KeyEvent.ACTION_DOWN){
switch(keyCode)
{
case KeyEvent.KEYCODE_BACK:
if(webView.canGoBack()){
webView.goBack();
}else{
finish();
}
return true;
}
}
return super.onKeyDown(keyCode, event);
}
}
And my Logcat:
Code:
12-01 01:48:40.579: W/dalvikvm(15534): threadid=1: thread exiting with uncaught exception (group=0x418eac08)
12-01 01:48:40.584: E/AndroidRuntime(15534): FATAL EXCEPTION: main
12-01 01:48:40.584: E/AndroidRuntime(15534): Process: com.example.homehub, PID: 15534
12-01 01:48:40.584: E/AndroidRuntime(15534): java.lang.NullPointerException
12-01 01:48:40.584: E/AndroidRuntime(15534): at com.android.org.chromium.content.browser.LongPressDetector.dispatchLongPress(LongPressDetector.java:158)
12-01 01:48:40.584: E/AndroidRuntime(15534): at com.android.org.chromium.content.browser.LongPressDetector.access$000(LongPressDetector.java:21)
12-01 01:48:40.584: E/AndroidRuntime(15534): at com.android.org.chromium.content.browser.LongPressDetector$LongPressHandler.handleMessage(LongPressDetector.java:58)
12-01 01:48:40.584: E/AndroidRuntime(15534): at android.os.Handler.dispatchMessage(Handler.java:102)
12-01 01:48:40.584: E/AndroidRuntime(15534): at android.os.Looper.loop(Looper.java:146)
12-01 01:48:40.584: E/AndroidRuntime(15534): at android.app.ActivityThread.main(ActivityThread.java:5653)
12-01 01:48:40.584: E/AndroidRuntime(15534): at java.lang.reflect.Method.invokeNative(Native Method)
12-01 01:48:40.584: E/AndroidRuntime(15534): at java.lang.reflect.Method.invoke(Method.java:515)
12-01 01:48:40.584: E/AndroidRuntime(15534): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
12-01 01:48:40.584: E/AndroidRuntime(15534): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
12-01 01:48:40.584: E/AndroidRuntime(15534): at dalvik.system.NativeStart.main(Native Method)
I am getting a NullPointerException after the build but once my phone tries to launch the app. I do not understand where the problem is. Im just learning to code and this app is simply supposed to make a toast pop up Long if the checkbox is clicked and short if it isnt.
Code:
package universaltruth.toastee;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends ActionBarActivity {
public CheckBox longToast = (CheckBox) findViewById(R.id.checkbox);
public EditText editText = (EditText) findViewById(R.id.toastText);
public int toastLength = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
addListenerOnlongToast();
}
public void addListenerOnlongToast(){
longToast.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
if(((CheckBox) view).isChecked()){
toastLength = '1';
}
}
});
}
public void toastMessage(View view){
String message = editText.getText().toString();
Toast.makeText(getApplicationContext(),message, (toastLength == 0) ? Toast.LENGTH_SHORT : Toast.LENGTH_LONG).show();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
LogCat:
02-08 12:48:34.718 6684-6684/universaltruth.toastee D/AndroidRuntime﹕ Shutting down VM
02-08 12:48:34.718 6684-6684/universaltruth.toastee W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x4191bda0)
02-08 12:48:34.718 6684-6684/universaltruth.toastee E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: universaltruth.toastee, PID: 6684
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{universaltruth.toastee/universaltruth.toastee.MainActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2408)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2599)
at android.app.ActivityThread.access$900(ActivityThread.java:174)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5748)
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:1291)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at android.app.Activity.findViewById(Activity.java:2014)
at universaltruth.toastee.MainActivity.<init>(MainActivity.java:19)
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1208)
at android.app.Instrumentation.newActivity(Instrumentation.java:1067)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2399)
************at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2599)
************at android.app.ActivityThread.access$900(ActivityThread.java:174)
************at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)
************at android.os.Handler.dispatchMessage(Handler.java:102)
************at android.os.Looper.loop(Looper.java:146)
************at android.app.ActivityThread.main(ActivityThread.java:5748)
************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:1291)
************at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
************at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132)
************at dalvik.system.NativeStart.main(Native Method)
02-08 13:00:50.672 9121-9121/universaltruth.toastee I/SELinux﹕ Function: selinux_android_load_priority , priority [3] , priority version is VE=SEPF_SM-N910F_4.4.4_A024
02-08 13:00:50.672 9121-9121/universaltruth.toastee E/SELinux﹕ [DEBUG] get_category: variable seinfocat: default sensitivity: NULL, cateogry: NULL
02-08 13:00:50.672 9121-9121/universaltruth.toastee E/dalvikvm﹕ >>>>> Normal User
02-08 13:00:50.672 9121-9121/universaltruth.toastee E/dalvikvm﹕ >>>>> universaltruth.toastee [ userId:0 | appId:10384 ]
02-08 13:00:50.682 9121-9121/universaltruth.toastee E/SELinux﹕ [DEBUG] get_category: variable seinfocat: default sensitivity: NULL, cateogry: NULL
02-08 13:00:50.682 9121-9121/universaltruth.toastee D/dalvikvm﹕ Late-enabling CheckJNI
02-08 13:00:50.682 9121-9121/universaltruth.toastee I/libpersona﹕ KNOX_SDCARD checking this for 10384
02-08 13:00:50.682 9121-9121/universaltruth.toastee I/libpersona﹕ KNOX_SDCARD not a persona
02-08 13:00:50.752 9121-9121/universaltruth.toastee D/TimaKeyStoreProvider﹕ in addTimaSignatureService
02-08 13:00:50.762 9121-9121/universaltruth.toastee D/TimaKeyStoreProvider﹕ Cannot add TimaSignature Service, License check Failed
02-08 13:00:50.762 9121-9121/universaltruth.toastee D/ActivityThread﹕ Added TimaKesytore provider
02-08 13:00:50.922 9121-9121/universaltruth.toastee D/AndroidRuntime﹕ Shutting down VM
02-08 13:00:50.922 9121-9121/universaltruth.toastee W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x4191bda0)
02-08 13:00:50.922 9121-9121/universaltruth.toastee E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: universaltruth.toastee, PID: 9121
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{universaltruth.toastee/universaltruth.toastee.MainActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2408)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2599)
at android.app.ActivityThread.access$900(ActivityThread.java:174)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5748)
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:1291)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at android.app.Activity.findViewById(Activity.java:2014)
at universaltruth.toastee.MainActivity.<init>(MainActivity.java:16)
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1208)
at android.app.Instrumentation.newActivity(Instrumentation.java:1067)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2399)
************at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2599)
************at android.app.ActivityThread.access$900(ActivityThread.java:174)
************at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)
************at android.os.Handler.dispatchMessage(Handler.java:102)
************at android.os.Looper.loop(Looper.java:146)
************at android.app.ActivityThread.main(ActivityThread.java:5748)
************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:1291)
************at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
************at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132)
************at dalvik.system.NativeStart.main(Native Method)
02-08 13:00:55.232 9121-9121/universaltruth.toastee I/Process﹕ Sending signal. PID: 9121 SIG: 9
Forgive me if I am not posting this correctly. This is my first time. I am open to any and all feedback. Thank you.
Your problem is that you initialize the longToast checkbox outside of a method. But findViewById only returns a result if called after a call to setContentView(...), which is done in onCreate. So: put your initialization code into onCreate, after setContentView and it will work fine
--------------------
Phone: Nexus 4
OS: rooted Lollipop LRX21T
Bootloader: unlocked
Recovery: TWRP 2.8.2.0
Masrepus said:
Your problem is that you initialize the longToast checkbox outside of a method. But findViewById only returns a result if called after a call to setContentView(...), which is done in onCreate. So: put your initialization code into onCreate, after setContentView and it will work fine
Click to expand...
Click to collapse
Hey Masrepus,
Thanks a bunch for answering me.
I have moved the initializations to the on create after the setContentView. I am still getting the null pointer exception. Do you have any further advice?
UniversalTruth said:
Hey Masrepus,
Thanks a bunch for answering me.
I have moved the initializations to the on create after the setContentView. I am still getting the null pointer exception. Do you have any further advice?
Click to expand...
Click to collapse
Can you edit the first post with the new code (and new logcat)?
Yes, grab a new log and post it on pastebin
Then link the log from here
Hey guys,
I'm having a problem figuring out a way to store the geofences that my app creates, in order to load them when I run the app again. The purpose is to show a list of geofences created by the user.
I tried to serialize them using Java's Serialization and I also tried to use Gson to convert them into a Json string. The problem with Gson it's when I try to load them, it gives me an error message saying that Geofence is not a class. (which is true, it's an interface).
logcat:
Code:
09-09 21:37:16.148 18137-18137/? D/dalvikvm﹕ Late-enabling CheckJNI
09-09 21:37:17.515 18137-18137/? I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.internal.widget.TintTypedArray.getChangingConfigurations
09-09 21:37:17.515 18137-18137/? W/dalvikvm﹕ VFY: unable to resolve virtual method 614: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
09-09 21:37:17.515 18137-18137/? D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
09-09 21:37:17.515 18137-18137/? I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.internal.widget.TintTypedArray.getType
09-09 21:37:17.515 18137-18137/? W/dalvikvm﹕ VFY: unable to resolve virtual method 636: Landroid/content/res/TypedArray;.getType (I)I
09-09 21:37:17.515 18137-18137/? D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
09-09 21:37:18.133 18137-18137/? D/GoogleAPIMsg﹕ Construcao do Client Google
09-09 21:37:18.164 18137-18137/? D/Manager﹕ Loading Geofences...
09-09 21:37:18.203 18137-18137/? D/AndroidRuntime﹕ Shutting down VM
09-09 21:37:18.203 18137-18137/? W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x419307c0)
09-09 21:37:18.234 18137-18137/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.smartlocation.wilcocsjrxxlxpto/com.smartlocation.wilcocsjrxxlxpto.HomeScreen}: java.lang.RuntimeException: Unable to invoke no-args constructor for interface com.google.android.gms.location.Geofence. Register an InstanceCreator with Gson for this type may fix this problem.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2339)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2389)
at android.app.ActivityThread.access$600(ActivityThread.java:153)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1269)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5289)
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:739)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.RuntimeException: Unable to invoke no-args constructor for interface com.google.android.gms.location.Geofence. Register an InstanceCreator with Gson for this type may fix this problem.
at com.google.gson.internal.ConstructorConstructor$12.construct(ConstructorConstructor.java:210)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:186)
at com.google.gson.Gson.fromJson(Gson.java:810)
at com.google.gson.Gson.fromJson(Gson.java:775)
at com.google.gson.Gson.fromJson(Gson.java:724)
at com.google.gson.Gson.fromJson(Gson.java:696)
at com.smartlocation.wilcocsjrxxlxpto.core.Manager.loadGeofences(Manager.java:203)
at com.smartlocation.wilcocsjrxxlxpto.HomeScreen.load(HomeScreen.java:252)
at com.smartlocation.wilcocsjrxxlxpto.HomeScreen.onCreate(HomeScreen.java:66)
at android.app.Activity.performCreate(Activity.java:5133)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2293)
************at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2389)
************at android.app.ActivityThread.access$600(ActivityThread.java:153)
************at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1269)
************at android.os.Handler.dispatchMessage(Handler.java:99)
************at android.os.Looper.loop(Looper.java:137)
************at android.app.ActivityThread.main(ActivityThread.java:5289)
************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:739)
************at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
************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:525)
at com.google.gson.internal.UnsafeAllocator$1.newInstance(UnsafeAllocator.java:48)
at com.google.gson.internal.ConstructorConstructor$12.construct(ConstructorConstructor.java:207)
************at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:186)
************at com.google.gson.Gson.fromJson(Gson.java:810)
************at com.google.gson.Gson.fromJson(Gson.java:775)
************at com.google.gson.Gson.fromJson(Gson.java:724)
************at com.google.gson.Gson.fromJson(Gson.java:696)
************at com.smartlocation.wilcocsjrxxlxpto.core.Manager.loadGeofences(Manager.java:203)
************at com.smartlocation.wilcocsjrxxlxpto.HomeScreen.load(HomeScreen.java:252)
************at com.smartlocation.wilcocsjrxxlxpto.HomeScreen.onCreate(HomeScreen.java:66)
************at android.app.Activity.performCreate(Activity.java:5133)
************at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
************at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2293)
************at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2389)
************at android.app.ActivityThread.access$600(ActivityThread.java:153)
************at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1269)
************at android.os.Handler.dispatchMessage(Handler.java:99)
************at android.os.Looper.loop(Looper.java:137)
************at android.app.ActivityThread.main(ActivityThread.java:5289)
************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:739)
************at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
************at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.InstantiationException: can't instantiate class com.google.android.gms.location.Geofence; abstract class or interface
at sun.misc.Unsafe.allocateInstance(Native Method)
************at java.lang.reflect.Method.invokeNative(Native Method)
************at java.lang.reflect.Method.invoke(Method.java:525)
************at com.google.gson.internal.UnsafeAllocator$1.newInstance(UnsafeAllocator.java:48)
************at com.google.gson.internal.ConstructorConstructor$12.construct(ConstructorConstructor.java:207)
************at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:186)
************at com.google.gson.Gson.fromJson(Gson.java:810)
************at com.google.gson.Gson.fromJson(Gson.java:775)
************at com.google.gson.Gson.fromJson(Gson.java:724)
************at com.google.gson.Gson.fromJson(Gson.java:696)
************at com.smartlocation.wilcocsjrxxlxpto.core.Manager.loadGeofences(Manager.java:203)
************at com.smartlocation.wilcocsjrxxlxpto.HomeScreen.load(HomeScreen.java:252)
************at com.smartlocation.wilcocsjrxxlxpto.HomeScreen.onCreate(HomeScreen.java:66)
************at android.app.Activity.performCreate(Activity.java:5133)
************at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
************at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2293)
************at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2389)
************at android.app.ActivityThread.access$600(ActivityThread.java:153)
************at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1269)
************at android.os.Handler.dispatchMessage(Handler.java:99)
************at android.os.Looper.loop(Looper.java:137)
************at android.app.ActivityThread.main(ActivityThread.java:5289)
************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:739)
************at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
************at dalvik.system.NativeStart.main(Native Method)
09-09 21:37:18.648 18137-18137/? I/Process﹕ Sending signal. PID: 18137 SIG: 9
code:
Code:
public class Manager implements ResultCallback<Status>, LocationListener {
// Tag para fazer debug
protected static final String MAN = "Manager";
protected static final String SMS = "eventSMS";
protected static final String RING = "eventRing";
private Context mAppContext;
private GoogleApiClient mGoogleApiClient;
private LocationRequest mLocationRequest;
// Listas de Geofences
private TreeMap<String, Geofence> mGeofences;
private TreeMap<String, Event> mEvents;
private int mCounterActiveGeofences;
private PendingIntent mGeofencePendingIntent;
private Intent updateLocIntent;
/* Save */
private Gson gson;
private SharedPreferences prefs;
public Manager(Context context, GoogleApiClient googleApiClient){
mGeofences = new TreeMap<String, Geofence>();
mEvents = new TreeMap<String, Event>();
mGeofencePendingIntent = null;
mAppContext = context;
mGoogleApiClient = googleApiClient;
mCounterActiveGeofences = 0;
prefs = context.getSharedPreferences(Constants.Geofences, Context.MODE_PRIVATE);
gson = new Gson();
}
...
public void saveGeofences(){
String json;
Geofence geofence;
SharedPreferences.Editor editor = prefs.edit();
Log.d(MAN, "Saving Geofences...");
for (Map.Entry<String, Geofence> entry : mGeofences.entrySet()) {
geofence = mGeofences.get(entry.getKey());
json = gson.toJson(geofence);
editor.putString(geofence.getRequestId(), json);
Log.d(MAN, geofence.getRequestId() + " json: " + json);
}
editor.apply();
}
public void loadGeofences(){
Map<String, ?> keys = prefs.getAll();
Log.d(MAN, "Loading Geofences...");
for (Map.Entry<String, ?> entry : keys.entrySet()) {
String jsonString = prefs.getString(entry.getKey(), null);
Geofence geofence = gson.fromJson(jsonString, Geofence.class);
Log.d(MAN, geofence.getRequestId());
mGeofences.put(geofence.getRequestId(), geofence);
}
}
}
Thank you in advance.
wilcocsjr said:
Hey guys,
I'm having a problem figuring out a way to store the geofences that my app creates, in order to load them when I run the app again. The purpose is to show a list of geofences created by the user.
I tried to serialize them using Java's Serialization and I also tried to use Gson to convert them into a Json string. The problem with Gson it's when I try to load them, it gives me an error message saying that Geofence is not a class. (which is true, it's an interface).
Thank you in advance.
Click to expand...
Click to collapse
Could you show your code and show logcat read sticky thread how to post development questions
Sent from my SM-G530H using XDA Free mobile app
AndroidFire said:
Could you show your code and show logcat read sticky thread how to post development questions
Sent from my SM-G530H using XDA Free mobile app
Click to expand...
Click to collapse
Just edited the original post, sorry about that