新しいAndroid Devがここにあります。さて私は、私を別の活動に連れて行くという簡単な意思を示しました。問題は、その特定のアクティビティに私を連れて行くことができないことです(ただし、他のアクティビティはうまく開きます)。私の意図が私の活動を認識できないのはなぜですか
FATAL EXCEPTION: main
Process: com.shahrukhraza.app, PID: 5628
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.shahrukhraza.app/com.shahrukhraza.app.otherAppActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.Window$Callback android.view.Window.getCallback()' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2327)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.Window$Callback android.view.Window.getCallback()' on a null object reference
at android.support.v7.app.AppCompatDelegateImplBase.<init>(AppCompatDelegateImplBase.java:68)
at android.support.v7.app.AppCompatDelegateImplV7.<init>(AppCompatDelegateImplV7.java:146)
at android.support.v7.app.AppCompatDelegateImplV11.<init>(AppCompatDelegateImplV11.java:28)
at android.support.v7.app.AppCompatDelegateImplV14.<init>(AppCompatDelegateImplV14.java:41)
at android.support.v7.app.AppCompatDelegateImplV23.<init>(AppCompatDelegateImplV23.java:29)
at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:188)
at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:172)
at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:512)
at android.support.v7.app.AppCompatActivity.findViewById(AppCompatActivity.java:184)
at com.shahrukhraza.app.otherAppActivity.<init>(otherAppActivity.java:14)
at java.lang.Class.newInstance(Native Method)
at android.app.Instrumentation.newActivity(Instrumentation.java:1067)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2317)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
そして、これは私のMainActivity.javaです::ここでは、それは私を与えているエラーがある
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_other_app);
Button b1 = (Button) findViewById(R.id.btn1);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, otherAppActivity.class);
startActivity(intent);
}
});
}
}
そして、これが問題を引き起こしているJavaクラスです:
public class otherAppActivity extends AppCompatActivity {
EditText eText1 = (EditText) findViewById(R.id.eText1);
EditText eText2 = (EditText) findViewById(R.id.eText2);
Button btn = (Button) findViewById(R.id.button);
TextView result = (TextView)findViewById(R.id.textView);
double n1,n2,sum;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.other_activity_app);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
n1 = Double.parseDouble(eText1.getText().toString());
n2 = Double.parseDouble(eText2.getText().toString());
sum = n1 +n2;
result.setText(Double.toString(sum));
}
});
}
}
@MikeMうん、私はそれをやろうとした。まだそれは私にエラーを与えている。 –
実際にそれを修正したのであれば、スタックトレースは今とは異なります。 –
これでうまくいくのを待ってください! 申し訳ありませんが、スタックトレースとは何ですか? –