CODE FOR TRYING TO GET ACHST/TOTS
package com.karanvir.ccc;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity {
EditText number1;
EditText number2;
EditText number3;
EditText number4;
EditText number5;
EditText number6;
EditText number7;
EditText number8;
EditText number9;
EditText number10;
double ach1;
double ach2;
double ach3;
double ach4;
double ach5;
double ach6;
double ach7;
double ach8;
double ach9;
double ach10;
EditText answer;
// setting up our % of grades part
EditText total0;
EditText total1;
EditText total2;
EditText total3;
EditText total4;
EditText total5;
EditText total6;
EditText total7;
EditText total8;
EditText total9;
double tot1;
double tot2;
double tot3;
double tot4;
double tot5;
double tot6;
double tot7;
double tot8;
double tot9;
double tot10;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initializeUi();
}
private void initializeUi() {
number1 = (EditText) findViewById(R.id.achieved1);
number2 = (EditText) findViewById(R.id.achieved2);
number3 = (EditText) findViewById(R.id.achieved3);
number4 = (EditText) findViewById(R.id.achieved4);
number5 = (EditText) findViewById(R.id.achieved5);
number6 = (EditText) findViewById(R.id.achieved6);
number7 = (EditText) findViewById(R.id.achieved7);
number8 = (EditText) findViewById(R.id.achieved8);
number9 = (EditText) findViewById(R.id.achieved9);
number10 = (EditText) findViewById(R.id.achieved10);
ach1 = Integer.parseInt(number1.getText().toString());
ach2 = Integer.parseInt(number2.getText().toString());
ach3 = Integer.parseInt(number3.getText().toString());
ach4 = Integer.parseInt(number4.getText().toString());
ach5 = Integer.parseInt(number5.getText().toString());
ach6 = Integer.parseInt(number6.getText().toString());
ach7 = Integer.parseInt(number7.getText().toString());
ach8 = Integer.parseInt(number8.getText().toString());
ach9 = Integer.parseInt(number9.getText().toString());
ach10 = Integer.parseInt(number10.getText().toString());
//Casting our button and the answer field
answer = (EditText) findViewById(R.id.editText7);
// setting up our % of grades part
total0 = (EditText) findViewById(R.id.total0);
total1 = (EditText) findViewById(R.id.total1);
total2 = (EditText) findViewById(R.id.total2);
total3 = (EditText) findViewById(R.id.total3);
total4 = (EditText) findViewById(R.id.total4);
total5 = (EditText) findViewById(R.id.total5);
total6 = (EditText) findViewById(R.id.total6);
total7 = (EditText) findViewById(R.id.total7);
total8 = (EditText) findViewById(R.id.total8);
total9 = (EditText) findViewById(R.id.total9);
tot1 = Integer.parseInt(total0.getText().toString());
tot2 = Integer.parseInt(total1.getText().toString());
tot3 = Integer.parseInt(total2.getText().toString());
tot4 = Integer.parseInt(total3.getText().toString());
tot5 = Integer.parseInt(total4.getText().toString());
tot6 = Integer.parseInt(total5.getText().toString());
tot7 = Integer.parseInt(total6.getText().toString());
tot8 = Integer.parseInt(total7.getText().toString());
tot9 = Integer.parseInt(total8.getText().toString());
tot10 = Integer.parseInt(total9.getText().toString());
}
public void ons(View view) {
double tots = (tot1 + tot2 + tot3 + tot4 + tot5 + tot6 + tot7 + tot8 + tot9 + tot10);
double achst= ach1+ach2+ach3+ach4+ach5+ach6+ach7+ach8+ach9+ach10;
double multi = achst / tots;
String total2 = String.valueOf(multi);
answer.setText(total2);
}
}

newest error after recommended
05-14 22:43:08.155 762-871/? E/ViewRootImpl: sendUserActionEvent() mView == null
05-14 22:43:09.185 32300-32300/? E/Zygote: v2
05-14 22:43:09.195 32300-32300/? E/Zygote: accessInfo : 0
05-14 22:43:09.315 32314-32314/? E/dex2oat: Failed to create oat file: /data/dalvik-cache/arm/data@app@com.karanvir.ccc-1@split_lib_dependencies_apk.apk@classes.dex: Permission denied
05-14 22:43:09.525 32330-32330/? E/dex2oat: Failed to create oat file: /data/dalvik-cache/arm/data@app@com.karanvir.ccc-1@split_lib_slice_0_apk.apk@classes.dex: Permission denied
05-14 22:43:09.585 32332-32332/? E/dex2oat: Failed to create oat file: /data/dalvik-cache/arm/data@app@com.karanvir.ccc-1@split_lib_slice_1_apk.apk@classes.dex: Permission denied
05-14 22:43:09.635 32334-32334/? E/dex2oat: Failed to create oat file: /data/dalvik-cache/arm/data@app@com.karanvir.ccc-1@split_lib_slice_2_apk.apk@classes.dex: Permission denied
05-14 22:43:09.695 32337-32337/? E/dex2oat: Failed to create oat file: /data/dalvik-cache/arm/data@app@com.karanvir.ccc-1@split_lib_slice_3_apk.apk@classes.dex: Permission denied
05-14 22:43:09.745 32340-32340/? E/dex2oat: Failed to create oat file: /data/dalvik-cache/arm/data@app@com.karanvir.ccc-1@split_lib_slice_4_apk.apk@classes.dex: Permission denied
05-14 22:43:09.805 32342-32342/? E/dex2oat: Failed to create oat file: /data/dalvik-cache/arm/data@app@com.karanvir.ccc-1@split_lib_slice_5_apk.apk@classes.dex: Permission denied
05-14 22:43:09.855 32352-32352/? E/dex2oat: Failed to create oat file: /data/dalvik-cache/arm/data@app@com.karanvir.ccc-1@split_lib_slice_6_apk.apk@classes.dex: Permission denied
05-14 22:43:09.905 32356-32356/? E/dex2oat: Failed to create oat file: /data/dalvik-cache/arm/data@app@com.karanvir.ccc-1@split_lib_slice_7_apk.apk@classes.dex: Permission denied
05-14 22:43:09.965 32358-32358/? E/dex2oat: Failed to create oat file: /data/dalvik-cache/arm/data@app@com.karanvir.ccc-1@split_lib_slice_8_apk.apk@classes.dex: Permission denied
05-14 22:43:10.025 32360-32360/? E/dex2oat: Failed to create oat file: /data/dalvik-cache/arm/data@app@com.karanvir.ccc-1@split_lib_slice_9_apk.apk@classes.dex: Permission denied
05-14 22:43:10.365 32300-32300/com.karanvir.ccc E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.karanvir.ccc, PID: 32300
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.karanvir.ccc/com.karanvir.ccc.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.text.Editable android.widget.EditText.getText()' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3253)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349)
at android.app.ActivityThread.access$1100(ActivityThread.java:221)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7224)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.text.Editable android.widget.EditText.getText()' on a null object reference
at com.karanvir.ccc.MainActivity.initializeUi(MainActivity.java:114)
at com.karanvir.ccc.MainActivity.onCreate(MainActivity.java:64)
at android.app.Activity.performCreate(Activity.java:6876)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3206)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349)
at android.app.ActivityThread.access$1100(ActivityThread.java:221)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7224)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
05-14 22:43:10.435 762-1543/? E/Watchdog: !@Sync 2175 [05-14 22:43:10.440]
05-14 22:43:10.685 762-32374/? E/android.os.Debug: ro.product_ship = true
05-14 22:43:10.685 762-32374/? E/android.os.Debug: ro.debug_level = 0x4f4c
05-14 22:43:10.685 762-32374/? E/android.os.Debug: sys.mobilecare.preload = false
05-14 22:43:17.775 14835-14887/? E/ContactsProvider_EventLog: Flush buffer to file cnt : 7 size : 5Kb duration : 108ms lastUpdatedAfter : 27748 ms mFlush_time_threasold : 2000 mCurrentSize : 2562
05-14 22:43:31.025 2549-2549/? E/MtpServerJNI: server is null in send_object_removed
05-14 22:43:40.435 762-1543/? E/Watchdog: !@Sync 2176 [05-14 22:43:40.442]

[在此输入图片说明] [1]
New error after trying recommended answer
05-14 22:22:23.795 23560-23560/? E/Zygote: v2
05-14 22:22:23.795 23560-23560/? E/Zygote: accessInfo : 0
05-14 22:22:23.945 23573-23573/? E/dex2oat: Failed to create oat file: /data/dalvik-cache/arm/data@app@com.karanvir.ccc-1@split_lib_dependencies_apk.apk@classes.dex: Permission denied
05-14 22:22:24.165 23590-23590/? E/dex2oat: Failed to create oat file: /data/dalvik-cache/arm/data@app@com.karanvir.ccc-1@split_lib_slice_0_apk.apk@classes.dex: Permission denied
05-14 22:22:24.225 23593-23593/? E/dex2oat: Failed to create oat file: /data/dalvik-cache/arm/data@app@com.karanvir.ccc-1@split_lib_slice_1_apk.apk@classes.dex: Permission denied
05-14 22:22:24.275 23596-23596/? E/dex2oat: Failed to create oat file: /data/dalvik-cache/arm/data@app@com.karanvir.ccc-1@split_lib_slice_2_apk.apk@classes.dex: Permission denied
05-14 22:22:24.335 23598-23598/? E/dex2oat: Failed to create oat file: /data/dalvik-cache/arm/data@app@com.karanvir.ccc-1@split_lib_slice_3_apk.apk@classes.dex: Permission denied
05-14 22:22:24.395 23600-23600/? E/dex2oat: Failed to create oat file: /data/dalvik-cache/arm/data@app@com.karanvir.ccc-1@split_lib_slice_4_apk.apk@classes.dex: Permission denied
05-14 22:22:24.445 23604-23604/? E/dex2oat: Failed to create oat file: /data/dalvik-cache/arm/data@app@com.karanvir.ccc-1@split_lib_slice_5_apk.apk@classes.dex: Permission denied
05-14 22:22:24.505 23612-23612/? E/dex2oat: Failed to create oat file: /data/dalvik-cache/arm/data@app@com.karanvir.ccc-1@split_lib_slice_6_apk.apk@classes.dex: Permission denied
05-14 22:22:24.555 23614-23614/? E/dex2oat: Failed to create oat file: /data/dalvik-cache/arm/data@app@com.karanvir.ccc-1@split_lib_slice_7_apk.apk@classes.dex: Permission denied
05-14 22:22:24.615 23616-23616/? E/dex2oat: Failed to create oat file: /data/dalvik-cache/arm/data@app@com.karanvir.ccc-1@split_lib_slice_8_apk.apk@classes.dex: Permission denied
05-14 22:22:24.675 23618-23618/? E/dex2oat: Failed to create oat file: /data/dalvik-cache/arm/data@app@com.karanvir.ccc-1@split_lib_slice_9_apk.apk@classes.dex: Permission denied
05-14 22:22:25.015 23560-23560/com.karanvir.ccc E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.karanvir.ccc, PID: 23560
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.karanvir.ccc/com.karanvir.ccc.MainActivity}: java.lang.NumberFormatException: Invalid int: ""
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3253)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349)
at android.app.ActivityThread.access$1100(ActivityThread.java:221)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7224)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: java.lang.NumberFormatException: Invalid int: ""
at java.lang.Integer.invalidInt(Integer.java:138)
at java.lang.Integer.parseInt(Integer.java:358)
at java.lang.Integer.parseInt(Integer.java:334)
at com.karanvir.ccc.MainActivity.initializeUi(MainActivity.java:83)
at com.karanvir.ccc.MainActivity.onCreate(MainActivity.java:64)
at android.app.Activity.performCreate(Activity.java:6876)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3206)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349)
at android.app.ActivityThread.access$1100(ActivityThread.java:221)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7224)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
05-14 22:22:25.335 762-23632/? E/android.os.Debug: ro.product_ship = true
05-14 22:22:25.335 762-23632/? E/android.os.Debug: ro.debug_level = 0x4f4c
05-14 22:22:25.335 762-23632/? E/android.os.Debug: sys.mobilecare.preload = false
05-14 22:22:31.155 23729-23729/? E/Zygote: v2
05-14 22:22:31.165 23729-23729/? E/Zygote: accessInfo : 0
05-14 22:22:32.785 23729-23763/? E/ExtMediaPlayer-JNI: env->IsInstanceOf fails
05-14 22:22:32.785 23729-23763/? E/MediaPlayer-JNI: JNIMediaPlayerFactory: bIsQCMediaPlayerPresent 0
05-14 22:22:32.785 23729-23763/? E/ExtMediaPlayer-JNI: env->IsInstanceOf fails
05-14 22:22:32.785 23729-23763/? E/MediaPlayer-JNI: JNIMediaPlayerFactory: bIsQCMediaPlayerPresent 0

这是我项目的主要活动代码..我是一名新开发者,所以可能会有一些非常糟糕的简单错误。我是一名新开发者,我也应该补充一下。我的错误也包括在我的目录中。
package com.karanvir.ccc;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity {
EditText number1 = (EditText) findViewById(R.id.achieved1);
EditText number2 = (EditText) findViewById(R.id.achieved2);
EditText number3 = (EditText) findViewById(R.id.achieved3);
EditText number4 = (EditText) findViewById(R.id.achieved4);
EditText number5 = (EditText) findViewById(R.id.achieved5);
EditText number6 = (EditText) findViewById(R.id.achieved6);
EditText number7 = (EditText) findViewById(R.id.achieved7);
EditText number8 = (EditText) findViewById(R.id.achieved8);
EditText number9 = (EditText) findViewById(R.id.achieved9);
EditText number10 = (EditText) findViewById(R.id.achieved10);
double ach1 = Integer.parseInt(number1.getText().toString());
double ach2 = Integer.parseInt(number2.getText().toString());
double ach3 = Integer.parseInt(number3.getText().toString());
double ach4 = Integer.parseInt(number4.getText().toString());
double ach5 = Integer.parseInt(number5.getText().toString());
double ach6 = Integer.parseInt(number6.getText().toString());
double ach7 = Integer.parseInt(number7.getText().toString());
double ach8 = Integer.parseInt(number8.getText().toString());
double ach9 = Integer.parseInt(number9.getText().toString());
double ach10 = Integer.parseInt(number10.getText().toString());
//Casting our button and the answer field
EditText answer = (EditText) findViewById(R.id.editText7);
// setting up our % of grades part
EditText total0 = (EditText) findViewById(R.id.total0);
EditText total1 = (EditText) findViewById(R.id.total1);
EditText total2 = (EditText) findViewById(R.id.total2);
EditText total3 = (EditText) findViewById(R.id.total3);
EditText total4 = (EditText) findViewById(R.id.total4);
EditText total5 = (EditText) findViewById(R.id.total5);
EditText total6 = (EditText) findViewById(R.id.total6);
EditText total7 = (EditText) findViewById(R.id.total7);
EditText total8 = (EditText) findViewById(R.id.total8);
EditText total9 = (EditText) findViewById(R.id.total9);
double tot1 = Integer.parseInt(total0.getText().toString());
double tot2 = Integer.parseInt(total1.getText().toString());
double tot3 = Integer.parseInt(total2.getText().toString());
double tot4 = Integer.parseInt(total3.getText().toString());
double tot5 = Integer.parseInt(total4.getText().toString());
double tot6 = Integer.parseInt(total5.getText().toString());
double tot7 = Integer.parseInt(total6.getText().toString());
double tot8 = Integer.parseInt(total7.getText().toString());
double tot9 = Integer.parseInt(total8.getText().toString());
double tot10 = Integer.parseInt(total9.getText().toString());
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).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();
答案 0 :(得分:1)
应该是这样的
public class MainActivity extends AppCompatActivity {
EditText number1, number2.....
double ach1, ach2....
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initializeUi();
.................
....................
.................
}
private void initializeUi() {
number1 = (EditText) findViewById(R.id.achieved1);
number2 = (EditText) findViewById(R.id.achieved2);
number3 = (EditText) findViewById(R.id.achieved3);
number4 = (EditText) findViewById(R.id.achieved4);
number5 = (EditText) findViewById(R.id.achieved5);
number6 = (EditText) findViewById(R.id.achieved6);
number7 = (EditText) findViewById(R.id.achieved7);
number8 = (EditText) findViewById(R.id.achieved8);
number9 = (EditText) findViewById(R.id.achieved9);
number10 = (EditText) findViewById(R.id.achieved10);
//Casting our button and the answer field
answer = (EditText) findViewById(R.id.editText7);
// setting up our % of grades part
total0 = (EditText) findViewById(R.id.total0);
total1 = (EditText) findViewById(R.id.total1);
total2 = (EditText) findViewById(R.id.total2);
total3 = (EditText) findViewById(R.id.total3);
total4 = (EditText) findViewById(R.id.total4);
total5 = (EditText) findViewById(R.id.total5);
total6 = (EditText) findViewById(R.id.total6);
total8 = (EditText) findViewById(R.id.total8);
total9 = (EditText) findViewById(R.id.total9);
}
public void ons(View view) {
ach1 = Integer.parseInt(number1.getText().toString());
ach2 = Integer.parseInt(number2.getText().toString());
ach3 = Integer.parseInt(number3.getText().toString());
ach4 = Integer.parseInt(number4.getText().toString());
ach5 = Integer.parseInt(number5.getText().toString());
ach6 = Integer.parseInt(number6.getText().toString());
ach7 = Integer.parseInt(number7.getText().toString());
ach8 = Integer.parseInt(number8.getText().toString());
ach9 = Integer.parseInt(number9.getText().toString());
ach10 = Integer.parseInt(number10.getText().toString());
tot1 = Integer.parseInt(total0.getText().toString());
tot2 = Integer.parseInt(total1.getText().toString());
tot3 = Integer.parseInt(total2.getText().toString());
tot4 = Integer.parseInt(total3.getText().toString());
tot5 = Integer.parseInt(total4.getText().toString());
tot6 = Integer.parseInt(total5.getText().toString());
tot7 = Integer.parseInt(total6.getText().toString());
tot8 = Integer.parseInt(total7.getText().toString());
tot9 = Integer.parseInt(total8.getText().toString());
tot10 = Integer.parseInt(total9.getText().toString());
double tots = (tot1 + tot2 + tot3 + tot4 + tot5 + tot6 + tot7 + tot8 + tot9 + tot10);
double achst= ach1+ach2+ach3+ach4+ach5+ach6+ach7+ach8+ach9+ach10;
double multi = achst / tots;
String total2 = String.valueOf(multi);
answer.setText(total2);
}