This is my fourthpage class in my application. I am getting the error
unfortunately application has stopped working
I have no idea why am I getting this.
package student.a.a;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import java.text.DecimalFormat;
public class fourthpage extends Activity {
EditText txtb1, txtb2, txtb3, txtb4, txtb5;
Button btnper;
TextView lblgrade, lblper;
DecimalFormat df = new DecimalFormat("##.##");
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fourthxml);
// text boxes
txtb1 = (EditText) findViewById(R.id.txtb1);
txtb2 = (EditText) findViewById(R.id.txtb2);
txtb3 = (EditText) findViewById(R.id.txtb3);
txtb4 = (EditText) findViewById(R.id.txtb4);
txtb5 = (EditText) findViewById(R.id.txtb5);
// buttons
btnper = (Button) findViewById(R.id.btnper);
// labels/text view
lblgrade = (TextView) findViewById(R.id.lblgrade);
lblper = (TextView) findViewById(R.id.lblgrade);
}
String tb1 = txtb1.getText().toString();
String tb2 = txtb2.getText().toString();
String tb3 = txtb3.getText().toString();
String tb4 = txtb4.getText().toString();
String tb5 = txtb5.getText().toString();
double txb1 = Double.parseDouble(tb1);
double txb2 = Double.parseDouble(tb2);
double txb3 = Double.parseDouble(tb3);
double txb4 = Double.parseDouble(tb4);
double txb5 = Double.parseDouble(tb5);
double sum = 0;
double total = 0;
public void onClickper(View v) {
sum = txb1 + txb2 + txb3 + txb4 + txb5;
total = (sum / 500) * 100;
String tot = df.format(total);
lblper.setText(tot);
if (total <= 100) {
lblgrade.setText("Congratulations !! , Grade 'A+' ");
} else if (total <= 80) {
lblgrade.setText("Congratulations !! , Grade 'A'");
} else if (total <= 70) {
lblgrade.setText("Grade 'B'");
} else if (total <= 60) {
lblgrade.setText("Grade 'C'");
} else
lblgrade.setText("Failed");
}
}
This is the xml code of fourthpage. It contains 5 text boxes, a button and two textviews:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TableLayout
android:id="#+id/tableLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<GridLayout
android:id="#+id/gridLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView1"
android:layout_gravity="left"
android:text="Calculate your marks"
android:textAppearance="?android:attr/textAppearanceMedium" />
</GridLayout>
</TableRow>
<TableRow
android:id="#+id/tableRow7"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<GridLayout
android:id="#+id/gridLayout3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Space android:layout_gravity="fill_horizontal" />
</GridLayout>
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<GridLayout
android:id="#+id/gridLayout2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView2"
android:layout_gravity="left"
android:text="Subject 1"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/txtb1"
android:layout_width="162dp"
android:layout_gravity="fill_horizontal" >
<requestFocus />
</EditText>
</GridLayout>
</TableRow>
<TableRow
android:id="#+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<GridLayout
android:id="#+id/GridLayout01"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/TextView01"
android:layout_gravity="left"
android:text="Subject 2"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/txtb2"
android:layout_gravity="fill_horizontal" />
</GridLayout>
</TableRow>
<TableRow
android:id="#+id/tableRow4"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<GridLayout
android:id="#+id/GridLayout02"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/TextView02"
android:layout_gravity="left"
android:text="Subject 3"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/txtb3"
android:layout_gravity="fill_horizontal" />
</GridLayout>
</TableRow>
<TableRow
android:id="#+id/tableRow5"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<GridLayout
android:id="#+id/GridLayout03"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/TextView03"
android:layout_gravity="left"
android:text="Subject 4"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/txtb4"
android:layout_gravity="fill_horizontal" />
</GridLayout>
</TableRow>
<TableRow
android:id="#+id/tableRow6"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<GridLayout
android:id="#+id/GridLayout04"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/TextView04"
android:layout_gravity="left"
android:text="Subject 5"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/txtb5"
android:layout_gravity="fill_horizontal" />
</GridLayout>
</TableRow>
<TableRow
android:id="#+id/tableRow8"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<GridLayout
android:id="#+id/gridLayout4"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button
android:id="#+id/btnper"
android:layout_gravity="left"
android:text="Button" android:onClick="onClickper"/>
<Button
android:id="#+id/btngrade"
android:layout_gravity="left"
android:text="Button" />
</GridLayout>
</TableRow>
<TableRow
android:id="#+id/tableRow9"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<GridLayout
android:id="#+id/gridLayout5"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView3"
android:layout_gravity="left"
android:text="percentage is "
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="#+id/lblper"
android:layout_gravity="left"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
</GridLayout>
</TableRow>
<TableRow
android:id="#+id/tableRow10"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<GridLayout
android:id="#+id/gridLayout6"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView5"
android:layout_gravity="left"
android:text=" Grade is "
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="#+id/lblgrade"
android:layout_gravity="left"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
</GridLayout>
</TableRow>
</TableLayout>
</LinearLayout>
Here is androidmanifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="student.a.a"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="14" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:label="#string/app_name"
android:name=".StudentsinfoActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:label="#string/app_name"
android:name=".secondpage" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:label="#string/app_name"
android:name=".thirdpage" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:label="#string/app_name"
android:name=".fourthpage" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Here is my logcat:
08-09 16:32:00.970: W/dalvikvm(892): threadid=1: thread exiting with uncaught exception (group=0x409961f8)
08-09 16:32:00.980: E/AndroidRuntime(892): FATAL EXCEPTION: main
08-09 16:32:00.980: E/AndroidRuntime(892): java.lang.RuntimeException: Unable to start activity ComponentInfo{student.a.a/student.a.a.fourthpage}: java.lang.NumberFormatException: Invalid double: ""
08-09 16:32:00.980: E/AndroidRuntime(892): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1955)
08-09 16:32:00.980: E/AndroidRuntime(892): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
08-09 16:32:00.980: E/AndroidRuntime(892): at android.app.ActivityThread.access$600(ActivityThread.java:122)
08-09 16:32:00.980: E/AndroidRuntime(892): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
08-09 16:32:00.980: E/AndroidRuntime(892): at android.os.Handler.dispatchMessage(Handler.java:99)
08-09 16:32:00.980: E/AndroidRuntime(892): at android.os.Looper.loop(Looper.java:137)
08-09 16:32:00.980: E/AndroidRuntime(892): at android.app.ActivityThread.main(ActivityThread.java:4340)
08-09 16:32:00.980: E/AndroidRuntime(892): at java.lang.reflect.Method.invokeNative(Native Method)
08-09 16:32:00.980: E/AndroidRuntime(892): at java.lang.reflect.Method.invoke(Method.java:511)
08-09 16:32:00.980: E/AndroidRuntime(892): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
08-09 16:32:00.980: E/AndroidRuntime(892): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
08-09 16:32:00.980: E/AndroidRuntime(892): at dalvik.system.NativeStart.main(Native Method)
08-09 16:32:00.980: E/AndroidRuntime(892): Caused by: java.lang.NumberFormatException: Invalid double: ""
08-09 16:32:00.980: E/AndroidRuntime(892): at java.lang.StringToReal.invalidReal(StringToReal.java:63)
08-09 16:32:00.980: E/AndroidRuntime(892): at java.lang.StringToReal.parseDouble(StringToReal.java:248)
08-09 16:32:00.980: E/AndroidRuntime(892): at java.lang.Double.parseDouble(Double.java:295)
08-09 16:32:00.980: E/AndroidRuntime(892): at student.a.a.fourthpage.onCreate(fourthpage.java:61)
08-09 16:32:00.980: E/AndroidRuntime(892): at android.app.Activity.performCreate(Activity.java:4465)
08-09 16:32:00.980: E/AndroidRuntime(892): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
08-09 16:32:00.980: E/AndroidRuntime(892): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919)
08-09 16:32:00.980: E/AndroidRuntime(892): ... 11 more
Just because you have put your variable declarations after onCreate that does not mean this code will execute after onCreate. All your String members will be initialized before onCreate is called and before EditText members are initialized. Same goes for your double members.
String tb1 = txtb1.getText().toString();
String tb2 = txtb2.getText().toString();
String tb3 = txtb3.getText().toString();
String tb4 = txtb4.getText().toString();
String tb5 = txtb5.getText().toString();
double txb1= Double.parseDouble(tb1);
double txb2= Double.parseDouble(tb2);
double txb3= Double.parseDouble(tb3);
double txb4= Double.parseDouble(tb4);
double txb5= Double.parseDouble(tb5);
You have to move above initialization into onCreate and declare String and double members separately.
...
String tb1, tb2, tb3, tb4, tb5;
double txb1, txb2, txb, txb4, txb5;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fourthxml);
//text boxes
txtb1=(EditText)findViewById(R.id.txtb1);
txtb2=(EditText)findViewById(R.id.txtb2);
txtb3=(EditText)findViewById(R.id.txtb3);
txtb4=(EditText)findViewById(R.id.txtb4);
txtb5=(EditText)findViewById(R.id.txtb5);
//buttons
btnper=(Button)findViewById(R.id.btnper);
//labels/text view
lblgrade=(TextView)findViewById(R.id.lblgrade);
lblper=(TextView)findViewById(R.id.lblgrade);
tb1 = txtb1.getText().toString();
tb2 = txtb2.getText().toString();
tb3 = txtb3.getText().toString();
tb4 = txtb4.getText().toString();
tb5 = txtb5.getText().toString();
txb1= Double.parseDouble(tb1);
txb2= Double.parseDouble(tb2);
txb3= Double.parseDouble(tb3);
txb4= Double.parseDouble(tb4);
txb5= Double.parseDouble(tb5);
}
You are getting NumberFormatException because you are parsing empty string.
You can use following method to safely parse double or set its value to some default if string does not contain valid double value.
public double getDoubleOrDefault(String value, double defValue)
{
try
{
return Double.parseDouble(value);
}
catch (Exception ex)
{
return defValue;
}
}
txb1 = getDoubleOrDefault(tb1, 0.0);
Double.parseDouble documentation
Related
This question already has answers here:
Unfortunately MyApp has stopped. How can I solve this?
(23 answers)
Closed 4 years ago.
I made a quiz game with codes I found on github because I'm a newbie and I want to learn programming.
So, when I press the start button game crashes. I tried it without the other classes but it still crashes. There is my MainActivity class, MainActivity xml and AndroidManifest.
MainActivity.java
package com.proje.bilgiyarismasi.bilgiyarismasi;
import android.app.Activity;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
public class MainActivity extends AppCompatActivity {
ImageButton baslat,ayarlar;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
baslat = findViewById(R.id.baslatButonu);
ayarlar = findViewById(R.id.ayarlarButonu);
baslat.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(MainActivity.this, SoruAlani.class);
startActivity(intent);
finish();
}
});
ayarlar.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(MainActivity.this,Ayarlar.class);
startActivity(intent);
finish();
}
});
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/deepPurple"
tools:context="com.proje.bilgiyarismasi.bilgiyarismasi.MainActivity"
tools:layout_editor_absoluteY="25dp"
tools:layout_editor_absoluteX="0dp">
<TextView
android:id="#+id/logoIsim"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="56dp"
android:text="#string/logoIsim"
android:textColor="#color/orenji"
android:textSize="50sp"
tools:layout_editor_absoluteX="150dp"
tools:layout_editor_absoluteY="28dp" />
<ImageButton
android:id="#+id/baslatButonu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/logoIsim"
android:layout_centerHorizontal="true"
android:layout_marginTop="120dp"
app:srcCompat="#drawable/menu_1"
android:adjustViewBounds="true"
/>
<ImageView
android:id="#+id/playButton"
android:layout_width="72dp"
android:layout_height="72dp"
app:srcCompat="#drawable/play_button"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignBottom="#+id/baslatButonu"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginBottom="2dp"
android:gravity="center"/>
<TextView
android:id="#+id/basla"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#id/baslatButonu"
android:layout_alignEnd="#id/baslatButonu"
android:layout_alignLeft="#id/baslatButonu"
android:layout_alignRight="#id/baslatButonu"
android:layout_alignStart="#id/baslatButonu"
android:layout_alignTop="#id/baslatButonu"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_margin="1dp"
android:gravity="center"
android:text="#string/baslat"
android:textAlignment="center"
android:textSize="30sp"
android:textStyle="bold"
/>
<ImageButton
android:id="#+id/ayarlarButonu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/baslatButonu"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
app:srcCompat="#drawable/menu_1"
android:adjustViewBounds="true"
/>
<TextView
android:id="#+id/ayarlar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#id/ayarlarButonu"
android:layout_alignEnd="#id/ayarlarButonu"
android:layout_alignLeft="#id/ayarlarButonu"
android:layout_alignRight="#id/ayarlarButonu"
android:layout_alignStart="#id/ayarlarButonu"
android:layout_alignTop="#id/ayarlarButonu"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_margin="1dp"
android:gravity="center"
android:text="#string/ayarlar"
android:textAlignment="center"
android:textSize="30sp"
android:textStyle="bold" />
<ImageView
android:id="#+id/ayarla"
android:layout_width="72dp"
android:layout_height="72dp"
android:layout_alignBottom="#id/ayarlarButonu"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginBottom="2dp"
app:srcCompat="#drawable/settings_button"
android:adjustViewBounds="true"
/>
<TextView
android:id="#+id/sosyalMedya"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/ayarlarButonu"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp"
android:text="#string/sosyalMedya"
android:textAlignment="center"
android:textStyle="bold"
android:gravity="center"/>
<ImageButton
android:id="#+id/facebookLogo"
android:layout_width="72dp"
android:layout_height="72dp"
android:layout_alignTop="#id/sosyalMedya"
app:srcCompat="#drawable/facebook_logo"
android:adjustViewBounds="true"
android:background="#null"
android:scaleType="fitCenter"
android:layout_toLeftOf="#id/sosyalMedya"
android:layout_toStartOf="#id/sosyalMedya"
android:layout_marginTop="30dp"
/>
<ImageButton
android:id="#+id/twitterLogo"
android:layout_width="72dp"
android:layout_height="72dp"
android:layout_alignTop="#+id/sosyalMedya"
app:srcCompat="#drawable/twitter_logo"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
android:background="#null"
android:layout_centerInParent="true"
android:layout_marginTop="30dp"
/>
<ImageButton
android:id="#+id/slackLogo"
android:layout_width="72dp"
android:layout_height="72dp"
app:srcCompat="#drawable/slack_logo"
android:layout_alignTop="#+id/sosyalMedya"
android:adjustViewBounds="true"
android:background="#null"
android:scaleType="fitCenter"
android:layout_toRightOf="#id/sosyalMedya"
android:layout_toEndOf="#id/sosyalMedya"
android:layout_marginTop="30dp"
/>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.proje.bilgiyarismasi.bilgiyarismasi">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".TekrarOyna" />
<activity android:name=".OyunKazanma" />
<activity android:name=".SoruAlani" />
<activity android:name=".SureBitti">
</activity>
</application>
</manifest>
logcat
05-25 12:28:18.414 6393-6393/com.proje.bilgiyarismasi.bilgiyarismasi
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.proje.bilgiyarismasi.bilgiyarismasi, PID: 6393
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.proje.bilgiyarismasi.bilgiyarismasi/com.proje.bilgiyarismasi.bilgiyarismasi.SoruAlani}:
java.lang.RuntimeException: Font asset not found fonts/Bariol_Regular.otf
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.RuntimeException: Font asset not found
fonts/Bariol_Regular.otf
at android.graphics.Typeface.createFromAsset(Typeface.java:190)
at com.proje.bilgiyarismasi.bilgiyarismasi.SoruAlani.onCreate(SoruAlani.java:51)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
05-25 12:28:20.016 4207-6527/com.android.providers.calendar E/SQLiteLog:
(284) automatic index on view_events(_id)
05-25 12:28:26.129 1535-1602/system_process E/InputDispatcher: channel
'2cf4e81e
com.proje.bilgiyarismasi.bilgiyarismasi/com.proje.bilgiyarismasi.bilgiyarismasi.MainActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
Thanks for your help.
You have not casted the image buttons correctly.
Use this in onCreate()
baslat = (ImageButton)findViewById(R.id.baslatButonu);
ayarlar =(ImageButton) findViewById(R.id.ayarlarButonu);
And Declare this activity in manifest
<activity android:name=".Ayarlar">
From the logcat
**java.lang.RuntimeException: Font asset not found fonts/Bariol_Regular.otf**
Add this font file also
Bariol_Regular.otf
Check this link please
How to use custom font in Android Studio
In my app, i have a SplashScreen activity. I have setStateLocked error when i clicked on the app. I'm using Fortune Ship MTN-S730 running android 5.1.
Here is the onCreate method
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash_screen); /* logcat says error on this line */
}
The says the says that error is on the line with
setContentView(R.layout.activity_splash_screen);
here is the output from the logcat
setStateLocked: wasEnabled = false, mIsEnabled = false, wasTouchExplorationEnabled = false,
mIsTouchExplorationEnabled = false, wasHighTextContrastEnabled = false, mIsHighTextContrastEnabled = false
java.lang.Throwable: setStateLocked
at android.view.accessibility.AccessibilityManager.setStateLocked(AccessibilityManager.java:553)
at android.view.accessibility.AccessibilityManager.tryConnectToServiceLocked(AccessibilityManager.java:636)
at android.view.accessibility.AccessibilityManager.<init>(AccessibilityManager.java:226)
at android.view.accessibility.AccessibilityManager.getInstance(AccessibilityManager.java:206)
at android.view.View.setFlags(View.java:9843)
at android.view.ViewGroup.initViewGroup(ViewGroup.java:536)
at android.view.ViewGroup.<init>(ViewGroup.java:525)
at android.view.ViewGroup.<init>(ViewGroup.java:520)
at android.view.ViewGroup.<init>(ViewGroup.java:516)
at android.view.ViewGroup.<init>(ViewGroup.java:512)
at android.widget.FrameLayout.<init>(FrameLayout.java:119)
at com.android.internal.policy.impl.PhoneWindow$DecorView.<init>(PhoneWindow.java:2326)
at com.android.internal.policy.impl.PhoneWindow.generateDecor(PhoneWindow.java:3460)
at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:3846)
at com.android.internal.policy.impl.PhoneWindow.getDecorView(PhoneWindow.java:2042)
at android.support.v7.app.AppCompatDelegateImplV9.createSubDecor(AppCompatDelegateImplV9.java:371)
at android.support.v7.app.AppCompatDelegateImplV9.ensureSubDecor(AppCompatDelegateImplV9.java:320)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:281)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:143)
at com.cm_floraison.brandbook.gesu.SplashScreenActivity.onCreate(SplashScreenActivity.java:101)
at android.app.Activity.performCreate(Activity.java:6092)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1112)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2468)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2595)
at android.app.ActivityThread.access$800(ActivityThread.java:178)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1470)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5631)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)
Here is the manifest declaration of the activity
<activity
android:name=".gesu.SplashScreenActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/app_name"
android:theme="#style/FullscreenTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Also the content of activity_splash_screen.xml
<FrameLayout 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:background="#color/colorPrimary"
tools:context="com.cm_toure.myapp.gesu.SplashScreenActivity">
<!-- The primary full-screen view. This can be replaced with whatever view
is needed to present your content, e.g. VideoView, SurfaceView,
TextureView, etc. -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:id="#+id/fullscreen_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:adjustViewBounds="true"
android:contentDescription="#string/app_logo"
android:foregroundGravity="center"
android:keepScreenOn="true"
android:src="#drawable/ic_logo_brandbook_paysage_sur_fond_blanc"
/>
</LinearLayout>
<!-- This FrameLayout insets its children based on system windows using
android:fitsSystemWindows. -->
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<LinearLayout
android:id="#+id/fullscreen_content_controls"
style="?metaButtonBarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:orientation="vertical"
tools:ignore="UselessParent">
<ProgressBar
android:id="#+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|bottom"
android:layout_marginTop="10dp"
android:indeterminate="true"
android:indeterminateDrawable="#drawable/splash_spinner_style"/>
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="50dp"
android:layout_weight="1"
android:background="#color/colorPrimary"
android:text="#string/powered_by"
android:textAlignment="center"
android:textAllCaps="false"
android:textColor="#color/white"
android:textSize="18sp"/>
</LinearLayout>
</FrameLayout>
</FrameLayout>
This question already has answers here:
What is a NullPointerException, and how do I fix it?
(12 answers)
Closed 6 years ago.
I'm developing a demo app when i login it will navigate to another page.
Here using button i'm trying to navigate to other page
Main activity
public class WelcomeActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_welcome);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
Button ibsignin = (Button) findViewById(R.id.ibsignin);
ibsignin.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent (v.getContext(), Register.class);
startActivity(intent);
}
});
}
}
I have defined button code in xml file still i'm getting null pointer exception.
XML file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_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"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.example.nandan.uschedule.WelcomeActivity"
android:background="#drawable/edit1">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="75dp"
android:id="#+id/welcome"
android:background="#drawable/minnesota"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/linearLayout"
android:clickable="false"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true">
<EditText
android:layout_width="350dp"
android:layout_height="wrap_content"
android:id="#+id/ibusername"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_gravity="center"
android:layout_marginBottom="200dp"
android:layout_marginTop="225dp"
android:inputType="textEmailAddress|text"
android:hint="User name/ Email Address"
android:textColor="#000000"
android:textStyle="normal" />
<EditText
android:layout_width="350dp"
android:layout_height="wrap_content"
android:inputType="textPassword|text"
android:ems="10"
android:id="#+id/ibpassword"
android:hint="Password"
android:layout_gravity="center"
android:layout_marginTop="-200dp"
android:textColor="#000000" />
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Remember me"
android:id="#+id/cbRememberme"
android:hint="Remember me"
android:layout_gravity="center" />
<Button
android:layout_width="250dp"
android:layout_height="38dp"
android:text="Sign in"
android:id="#+id/ibsingin"
android:layout_gravity="center"
android:background="#4D306A" />
<TextView
android:layout_width="wrap_content"
android:layout_height="40dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Do not have an account yet?"
android:id="#+id/havenoaccount"
android:layout_gravity="center"
android:textColor="#000000"
android:paddingTop="12dp"
android:textSize="20dp" />
<Button
android:layout_width="250dp"
android:layout_height="38dp"
android:text="Sign up"
android:id="#+id/ibsignup"
android:layout_gravity="center"
android:background="#4D306A" />
<TextView
android:layout_width="wrap_content"
android:layout_height="35dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Forgot Password?"
android:id="#+id/ibforgotpwd"
android:layout_gravity="center"
android:textColor="#000000"
android:textSize="20dp"
android:clickable="true" />
</LinearLayout>
</RelativeLayout>
my logcat
Process: com.example.nandan.uschedule, PID: 2487
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.nandan.uschedule/com.example.nandan.uschedule.WelcomeActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
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:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.example.nandan.uschedule.WelcomeActivity.onCreate(WelcomeActivity.java:27)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
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:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
I don't know which line is 27, but it's most likely the NPE comes from here:
Button ibsignin = (Button) findViewById(R.id.ibsignin);
Make sure your button is in your XML layout and that it is called ibsignin.
I am new to android. Here am trying to pass the radiobutton and Checkbox values from one activity to another activity. Its not showing any error but when I run it simply gets closed. Any help would be appreciated.Here I have posted the complete code..
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.RadioButton;
public class MainActivity extends Activity {
Intent obj = new Intent(this, SecondActivity.class);
Bundle extras = new Bundle();
RadioButton male, female, single, married;
CheckBox twelveth, bE, mE;
String s1="+2";
String s2="B.E.";
String s3="M.E.";
StringBuilder s;
String str;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
male = (RadioButton) findViewById(R.id.male);
female = (RadioButton) findViewById(R.id.female);
single = (RadioButton) findViewById(R.id.single);
married = (RadioButton) findViewById(R.id.married);
twelveth = (CheckBox) findViewById(R.id.twelveth);
bE = (CheckBox) findViewById(R.id.BE);
mE = (CheckBox) findViewById(R.id.ME);
str=s.toString();
extras.putString("Education",str);
}
public void onGenderClicked(View v) {
boolean checked = ((RadioButton) v).isChecked();
switch (v.getId()) {
case R.id.male:
if (checked)
extras.putString("Gender", "Male");
break;
case R.id.female:
if (checked)
extras.putString("Gender", "Female");
break;
}
}
public void onStatusClicked(View v) {
boolean checked = ((RadioButton) v).isChecked();
switch (v.getId()) {
case R.id.single:
if (checked)
extras.putString("Status", "Single");
break;
case R.id.married:
if (checked)
extras.putString("Status", "Married");
break;
}
}
public void ButtonClick(View v) {
obj.putExtras(extras);
startActivity(obj);
}
public void onCheckBoxClicked(View v)
{
boolean checked=((CheckBox)v).isChecked();
switch(v.getId())
{
case R.id.twelveth:
if(checked)
{
s.append("\n"+s1);
}
break;
case R.id.BE:
if(checked)
{
s.append("\n"+s2);
}
break;
case R.id.ME:
if(checked)
{
s.append("\n"+s3);
}
break;
}
str=s.toString();
extras.putString("Education",str);
}
}
SecondActivity
package com.example.aravindpraveen.buttonsandboxes;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
public class SecondActivity extends Activity {
TextView tvGender,tvStatus,tvEducation;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.second);
tvGender=(TextView)findViewById(R.id.tvGender);
tvStatus=(TextView)findViewById(R.id.tvStatus);
tvEducation=(TextView)findViewById(R.id.tvEducation);
Intent obj1=getIntent();
Bundle extras=obj1.getExtras();
String gender=extras.getString("Gender");
String status=extras.getString("Starus");
String education=extras.getString("Education");
tvGender.setText(gender);
tvStatus.setText(status);
tvEducation.setText(education);
}
}
Android Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.aravindpraveen.buttonsandboxes" >
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".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>
<activity
android:name=".SecondActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
activity_main.xml
<LinearLayout 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"
android:background="#6457d962"
android:orientation="vertical">
<TextView android:text="#string/b_b"
android:layout_width="match_parent"
android:layout_height="50dp"
android:textSize="40sp"
android:background="#f62dd93c"
android:textColor="#c34c27e6"
android:gravity="center"/>
<Space
android:layout_width="match_parent"
android:layout_height="15dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/gender"
android:textSize="40sp"
android:gravity="center"
android:textColor="#000000"/>
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/rg_gender">
<RadioButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/male"
android:text="#string/male"
android:textSize="30sp"
android:checked="true"
android:onClick="onGenderClicked"/>
<RadioButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/female"
android:text="#string/female"
android:textSize="30sp"
android:onClick="onGenderClicked"/>
</RadioGroup>
<Space
android:layout_width="match_parent"
android:layout_height="15dp"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="40sp"
android:text="#string/M_status"
android:textColor="#000000"
android:gravity="center"/>
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/rg_status">
<RadioButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/single"
android:text="#string/single"
android:textSize="30sp"
android:checked="true"
android:onClick="onStatusClicked"/>
<RadioButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/married"
android:text="#string/married"
android:textSize="30sp"
android:onClick="onStatusClicked"/>
</RadioGroup>
<Space
android:layout_width="match_parent"
android:layout_height="15dp"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="40sp"
android:text="#string/education"
android:textColor="#000000"
android:gravity="center"
/>
<CheckBox
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/twelveth"
android:textSize="30sp"
android:id="#+id/twelveth"
android:onClick="onCheckBoxClicked"/>
<CheckBox
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/bE"
android:textSize="30sp"
android:id="#+id/BE"
android:onClick="onCheckBoxClicked"/>
<CheckBox
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/mE"
android:textSize="30sp"
android:id="#+id/ME"
android:onClick="onCheckBoxClicked"/>
<Button
android:layout_width="wrap_content"
android:layout_height="50dp"
android:id="#+id/submit"
android:text="#string/submit"
android:layout_gravity="center"
android:onClick="ButtonClick"/>
</LinearLayout>
second.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#f4dbde"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="40sp"
android:background="#fba1a1"
android:text="#string/heading"
android:gravity="center"
android:textColor="#ffffff"/>
<Space
android:layout_width="match_parent"
android:layout_height="20dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/gender"
android:textSize="40sp"
android:gravity="center"
android:textColor="#ffffff"
android:background="#f7beae"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="30sp"
android:paddingTop="20dp"
android:gravity="center"
android:id="#+id/tvGender"/>
<Space
android:layout_width="match_parent"
android:layout_height="20dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/M_status"
android:textSize="40sp"
android:gravity="center"
android:textColor="#ffffff"
android:background="#f7beae"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="30sp"
android:paddingTop="20dp"
android:gravity="center"
android:id="#+id/tvStatus"/>
<Space
android:layout_width="match_parent"
android:layout_height="20dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/education"
android:textSize="40sp"
android:gravity="center"
android:textColor="#ffffff"
android:background="#f7beae"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="30sp"
android:paddingTop="20dp"
android:gravity="center"
android:id="#+id/tvEducation"/>
</LinearLayout>
LogCat
02-03 11:39:42.859 1135-1135/com.example.aravindpraveen.buttonsandboxes D/AndroidRuntime﹕ Shutting down VM
02-03 11:39:42.863 1135-1135/com.example.aravindpraveen.buttonsandboxes W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0xa4c2c648)
02-03 11:39:42.899 1135-1135/com.example.aravindpraveen.buttonsandboxes E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.aravindpraveen.buttonsandboxes/com.example.aravindpraveen.buttonsandboxes.MainActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2137)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at android.content.ContextWrapper.getPackageName(ContextWrapper.java:135)
at android.content.ComponentName.<init>(ComponentName.java:75)
at android.content.Intent.<init>(Intent.java:3662)
at com.example.aravindpraveen.buttonsandboxes.MainActivity.<init>(MainActivity.java:15)
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1130)
at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2128)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
from the second activity declare in Manifest, remove tags
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
i think starting activity as MAIN while it's not MAIN may cause this problem
also in documentaion
Activity Action: Start as a main entry point, does not expect to receive data.
EDIT:
also move
str=s.toString();
extras.putString("Education",str);
inside onClick that starts the 2nd activity
LOGCAT
04-03 20:59:46.189: E/AndroidRuntime(362): android.content.res.Resources$NotFoundException: String resource ID #0x0
04-03 20:59:46.189: E/AndroidRuntime(362): at android.content.res.Resources.getText(Resources.java:201)
04-03 20:59:46.189: E/AndroidRuntime(362): at android.widget.TextView.setText(TextView.java:2857)
04-03 20:59:46.189: E/AndroidRuntime(362): at coin.calc.wilson.CoinCalculatorActivity$1.onClick(CoinCalculatorActivity.java:65)
04-03 20:59:46.189: E/AndroidRuntime(362): at android.view.View.performClick(View.java:2485)
04-03 20:59:46.189: E/AndroidRuntime(362): at android.view.View$PerformClick.run(View.java:9080)
04-03 20:59:46.189: E/AndroidRuntime(362): at android.os.Handler.handleCallback(Handler.java:587)
04-03 20:59:46.189: E/AndroidRuntime(362): at android.os.Handler.dispatchMessage(Handler.java:92)
04-03 20:59:46.189: E/AndroidRuntime(362): at android.os.Looper.loop(Looper.java:123)
04-03 20:59:46.189: E/AndroidRuntime(362): at android.app.ActivityThread.main(ActivityThread.java:3683)
04-03 20:59:46.189: E/AndroidRuntime(362): at java.lang.reflect.Method.invokeNative(Native Method)
04-03 20:59:46.189: E/AndroidRuntime(362): at java.lang.reflect.Method.invoke(Method.java:507)
04-03 20:59:46.189: E/AndroidRuntime(362): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-03 20:59:46.189: E/AndroidRuntime(362): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-03 20:59:46.189: E/AndroidRuntime(362): at dalvik.system.NativeStart.main(Native Method)
04-03 20:59:49.720: I/Process(362): Sending signal. PID: 362 SIG: 9
Here is my java code:
package coin.calc.wilson;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class CoinCalculatorActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button solve = (Button)findViewById(R.id.bsolve);
solve.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
int td, tc, twenty, ten, five, one, quarter, dime, nickel, penny;
EditText tdet = (EditText)findViewById(R.id.etdollars);
EditText tcet = (EditText)findViewById(R.id.etcents);
try{
td = Integer.parseInt(tdet.getText().toString());
tc = Integer.parseInt(tdet.getText().toString());
}
catch (NumberFormatException e) {
td = tc = 0;
}
if (td < 0 || tc < 0){
/* ERROR */
}
else{
if( td == 0 ){
twenty = ten = five = one = 0;
}
else{
one = td%5;
if(td >= 20){
twenty = (td/20)-((td%20)/20);
}
else{
twenty = 0;
}
int tda20 = td-(20*twenty);
if (tda20 >= 10){
ten = (tda20/10)-((tda20%10)/10);
}
else{
ten = 0;
}
int tda10 = tda20-(10*ten);
if(tda10>=5){
five = (tda10/5)-((tda10%5)/5);
}
else{
five = 0;
}
TextView tv20 = (TextView)findViewById(R.id.tvtwenty);
tv20.setText(twenty);
TextView tv10 = (TextView)findViewById(R.id.tvten);
tv10.setText(ten);
TextView tv5 = (TextView)findViewById(R.id.tvfive);
tv5.setText(five);
TextView tv1 = (TextView)findViewById(R.id.tvone);
tv1.setText(one);
}
if( tc == 0 ){
quarter = dime = nickel = penny = 0;
}
else{
penny = tc%5;
if(tc >= 25){
quarter = (tc/25)-((td%25)/25);
}
else{
quarter = 0;
}
int tcaq = tc-(25*quarter);
if (tcaq >= 10){
dime = (tcaq/10)-((tcaq%10)/10);
}
else{
dime = 0;
}
int tcad = tcaq-(10*ten);
if(tcad>=5){
nickel = (tcad/5)-((tcad%5)/5);
}
else{
nickel = 0;
}
TextView tvq = (TextView)findViewById(R.id.tvquarter);
tvq.setText(quarter);
TextView tvd = (TextView)findViewById(R.id.tvdime);
tvd.setText(dime);
TextView tvn = (TextView)findViewById(R.id.tvnickel);
tvn.setText(nickel);
TextView tvp = (TextView)findViewById(R.id.tvpenny);
tvp.setText(penny);
}
}
}});}
}
and here is the xml:
<TableRow
android:id="#+id/tableRow1"
android:layout_height="wrap_content"
android:gravity="center" >
<EditText
android:id="#+id/etdollars"
android:layout_width="156dp"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="number" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="dollars"
android:textAppearance="?android:attr/textAppearanceLarge" />
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center" >
<EditText
android:id="#+id/etcents"
android:layout_width="156dp"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="number" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="cents"
android:textAppearance="?android:attr/textAppearanceLarge" />
</TableRow>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="60dp"
android:gravity="center" >
<Button
android:id="#+id/bsolve"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Solve!" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="80dp" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="100dp"
android:layout_height="80dp"
android:layout_weight="0.00"
android:layout_marginLeft="8.75dp"
android:layout_marginRight="8.75dp"
android:src="#drawable/twenty" />
<TextView
android:id="#+id/tvtwenty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.00"
android:layout_gravity="center_vertical"
android:text="0"
android:textAppearance="?android:attr/textAppearanceLarge" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="61dp"
android:layout_height="80dp"
android:layout_marginLeft="43dp"
android:layout_marginRight="13.5dp"
android:src="#drawable/cquarter" />
<TextView
android:id="#+id/tvquarter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.00"
android:layout_gravity="center_vertical"
android:text="0"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="80dp" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="100dp"
android:layout_height="80dp"
android:layout_weight="0.00"
android:layout_marginLeft="8.75dp"
android:layout_marginRight="8.75dp"
android:src="#drawable/ten" />
<TextView
android:id="#+id/tvten"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.00"
android:layout_gravity="center_vertical"
android:text="0"
android:textAppearance="?android:attr/textAppearanceLarge" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="61dp"
android:layout_height="80dp"
android:layout_marginLeft="43dp"
android:layout_marginRight="13.5dp"
android:src="#drawable/cdime" />
<TextView
android:id="#+id/tvdime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.00"
android:layout_gravity="center_vertical"
android:text="0"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="80dp" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="100dp"
android:layout_height="80dp"
android:layout_weight="0.00"
android:layout_marginLeft="8.75dp"
android:layout_marginRight="8.75dp"
android:src="#drawable/five" />
<TextView
android:id="#+id/tvfive"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.00"
android:layout_gravity="center_vertical"
android:text="0"
android:textAppearance="?android:attr/textAppearanceLarge" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="61dp"
android:layout_height="80dp"
android:layout_marginLeft="43dp"
android:layout_marginRight="13.5dp"
android:src="#drawable/cnickel" />
<TextView
android:id="#+id/tvnickel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.00"
android:layout_gravity="center_vertical"
android:text="0"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="80dp" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="100dp"
android:layout_height="80dp"
android:layout_weight="0.00"
android:layout_marginLeft="8.75dp"
android:layout_marginRight="8.75dp"
android:src="#drawable/one" />
<TextView
android:id="#+id/tvone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.00"
android:layout_gravity="center_vertical"
android:text="0"
android:textAppearance="?android:attr/textAppearanceLarge" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="61dp"
android:layout_height="80dp"
android:layout_marginLeft="43dp"
android:layout_marginRight="13.5dp"
android:src="#drawable/cpenny" />
<TextView
android:id="#+id/tvpenny"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.00"
android:layout_gravity="center_vertical"
android:text="0"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
</TableLayout>
If it helps, i think the error MAY have something to do with resources i am using (eight jpgs), but i'm not sure. The program runs cleanly up until the OnClickListener is activated. Thanks for any and all help!
Is here (and in another lines like that):
tv20.setText(twenty);
twenty is int and should be String (I suppose that you want to show the number in the textview):
tv20.setText(String.valueOf(twenty));
EDIT:
All this variables have the same error
int td, tc, twenty, ten, five, one, quarter, dime, nickel, penny;
You have a small but heavy mistake:
If you try to put a number/integer into a TextView, you need to cast it to a String first. If you don't do that, Android things you reference to an internal id like R.string.mynumber and that is not what you want.
try moving the two following lines right underneath Button solve = (Button)findViewById(R.id.bsolve); and before solve.setOnClickListener(new OnClickListener()
EditText tdet = (EditText)findViewById(R.id.etdollars);
EditText tcet = (EditText)findViewById(R.id.etcents);