奇怪的错误java.lang.reflect.Method.Invokenactive(本机方法)Android Studio请回答
我正在为我的学校开发一个带有时间表和一个小计算器的应用程序 下面是manifest.xml文件:奇怪的错误java.lang.reflect.Method.Invokenactive(本机方法)Android Studio请回答,java,android,android-studio,android-activity,native-methods,Java,Android,Android Studio,Android Activity,Native Methods,我正在为我的学校开发一个带有时间表和一个小计算器的应用程序 下面是manifest.xml文件: <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.markwitt.schul_app"> <uses-permission android:name="andr
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.markwitt.schul_app">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:launchMode="singleTop"
android:minSdkVersion="20"
android:supportsRtl="true"
android:targetSdkVersion="25"
android:theme="@style/AppTheme">
<activity android:name=".Stundenplan">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Vertretungsplan" />
<activity android:name=".Rechner" />
<activity android:name=".Overlay"></activity>
</application>
问题是,每次我在Xperia Z3上调试启动应用程序并按下按钮打开“Rechner”活动时,应用程序都会关闭,并显示以下错误:(sry用于错误格式)
I/OpenGLRenderer:初始化EGL,版本1.4
I/Timeline:Timeline:Activity\u idle id:android.os。BinderProxy@f97be6e时间:6061206
I/Timeline:Timeline:Activity\u idle id:android.os。BinderProxy@f97be6e时间:6065998
I/Timeline:Timeline:Activity\u launch\u request id:com.example.markwitt.schul\u应用程序时间:6074313
D/AndroidRuntime:关闭虚拟机
---------坠机开始
E/AndroidRuntime:致命异常:主
进程:com.example.markwitt.schul_应用程序,PID:22562
java.lang.RuntimeException:无法实例化activity ComponentInfo{com.example.markwitt.schul_app/com.example.markwitt.schul_app.Rechner}:java.lang.NullPointerException:尝试在空对象引用上调用虚拟方法“android.view.Window$Callback android.view.Window.getCallback()”
在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2375)上
位于android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2524)
在android.app.ActivityThread.access$900(ActivityThread.java:154)
在android.app.ActivityThread$H.handleMessage(ActivityThread.java:1391)
位于android.os.Handler.dispatchMessage(Handler.java:102)
位于android.os.Looper.loop(Looper.java:224)
位于android.app.ActivityThread.main(ActivityThread.java:5526)
位于java.lang.reflect.Method.invoke(本机方法)
在com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run上(ZygoteInit.java:726)
位于com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
原因:java.lang.NullPointerException:尝试对空对象引用调用虚拟方法“android.view.Window$Callback android.view.Window.getCallback()”
位于android.support.v7.app.AppCompateDelegateImplbase。(appCompateDelegateImplbase.java:116)
在android.support.v7.app.AppCompateDelegateImplv9。(AppCompateDelegateImplv9.java:147)
在android.support.v7.app.AppCompateDelegateImplv11。(AppCompateDelegateImplv11.java:27)
在android.support.v7.app.AppCompateDelegateImplv14。(AppCompateDelegateImplv14.java:53)
位于android.support.v7.app.AppCompateDelegateImplv23。(AppCompateDelegateImplv23.java:29)
在android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:203)中
在android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:185)上
位于android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:525)
位于android.support.v7.app.AppCompatActivity.findViewById(AppCompatActivity.java:193)
在com.example.markwitt.schul_app.Rechner上(Rechner.java:16)
位于java.lang.Class.newInstance(本机方法)
位于android.app.Instrumentation.newActivity(Instrumentation.java:1068)
在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2365)上
位于android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2524)
在android.app.ActivityThread.access$900(ActivityThread.java:154)
在android.app.ActivityThread$H.handleMessage(ActivityThread.java:1391)
位于android.os.Handler.dispatchMessage(Handler.java:102)
位于android.os.Looper.loop(Looper.java:224)
位于android.app.ActivityThread.main(ActivityThread.java:5526)
位于java.lang.reflect.Method.invoke(本机方法)
在com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run上(ZygoteInit.java:726)
位于com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
I/进程:发送信号。PID:22562信号:9
已断开与目标VM的连接,地址:'localhost:8600',传输:'socket'
我的Rechner.java和我的activity\u Rechner如下所示:
package com.example.markwitt.schul_app;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
public class Rechner extends AppCompatActivity {
private RadioGroup radioGroup;
private RadioButton checked;
private Button los;
public String mode;
EditText number1 = (EditText) findViewById(R.id.nummer1);
EditText number2 = (EditText) findViewById(R.id.nummer2);
EditText ergebnis = (EditText) findViewById(R.id.ergebnis);
public int text1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_rechner);
addListenerOnButton();
}
public void addListenerOnButton() {
radioGroup = (RadioGroup) findViewById(R.id.radioGroup);
los = (Button) findViewById(R.id.button5);
los.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int selectedId = radioGroup.getCheckedRadioButtonId();
checked = (RadioButton) findViewById(selectedId);
switch (checked.getId()){
case R.id.plus: mode = "+";
case R.id.minus: mode = "-";
case R.id.mal: mode = "*";
case R.id.geteilt: mode = ":";
case R.id.fakultaet: mode = "fak";
}
text1 = Integer.parseInt(number1.getText().toString());
int text2 = Integer.parseInt(number2.getText().toString());
switch (mode){
case "+": ergebnis.setText(text1 + text2);
case "-": ergebnis.setText(text1 - text2);
case "*": ergebnis.setText(text1 * text2);
case ":": ergebnis.setText(text1 / text2);
case "fak": ergebnis.setText(Long.toString(fakultaet(text1)));
}
}
});
}
static long fakultaet(int n) {
int ergebnis = 1;
for (int i = 1; i <= n; i++) {
ergebnis = ergebnis * i;
}
return ergebnis;
}
package com.example.markwitt.schul_应用程序;
导入android.os.Bundle;
导入android.support.v7.app.AppActivity;
导入android.view.view;
导入android.widget.Button;
导入android.widget.EditText;
导入android.widget.RadioButton;
导入android.widget.RadioGroup;
公共类Rechner扩展了AppCompatActivity{
私人放射组放射组;
检查私人无线按钮;
私人按钮服务水平;
公共字符串模式;
EditText number1=(EditText)findViewById(R.id.numer1);
EditText number2=(EditText)findViewById(R.id.numer2);
EditText ergebnis=(EditText)findviewbyd(R.id.ergebnis);
公共int text1;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity\u rechner);
addListenerOnButton();
}
public void addListenerOnButton(){
放射组=(放射组)findViewById(R.id.radioGroup);
los=(按钮)findViewById(R.id.button5);
los.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
int selectedId=radioGroup.getCheckedRadioButtonId();
选中=(单选按钮)findViewById(selectedId);
开关(选中。getId()){
案例R.id.plus:mode=“+”;
案例R.id.减号:模式=“-”;
案例R.id.mal:mode=“*”;
案例R.id.geteilt:mode=“:”;
rechner.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivity(new Intent(Stundenplan.this, Rechner.class));
}
});
I/OpenGLRenderer: Initialized EGL, version 1.4
I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@f97be6e time:6061206
I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@f97be6e time:6065998
I/Timeline: Timeline: Activity_launch_request id:com.example.markwitt.schul_app time:6074313
D/AndroidRuntime: Shutting down VM
--------- beginning of crash
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.markwitt.schul_app, PID: 22562
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.markwitt.schul_app/com.example.markwitt.schul_app.Rechner}: 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:2375)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2524)
at android.app.ActivityThread.access$900(ActivityThread.java:154)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1391)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:224)
at android.app.ActivityThread.main(ActivityThread.java:5526)
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:116)
at android.support.v7.app.AppCompatDelegateImplV9.<init>(AppCompatDelegateImplV9.java:147)
at android.support.v7.app.AppCompatDelegateImplV11.<init>(AppCompatDelegateImplV11.java:27)
at android.support.v7.app.AppCompatDelegateImplV14.<init>(AppCompatDelegateImplV14.java:53)
at android.support.v7.app.AppCompatDelegateImplV23.<init>(AppCompatDelegateImplV23.java:29)
at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:203)
at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:185)
at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:525)
at android.support.v7.app.AppCompatActivity.findViewById(AppCompatActivity.java:193)
at com.example.markwitt.schul_app.Rechner.<init>(Rechner.java:16)
at java.lang.Class.newInstance(Native Method)
at android.app.Instrumentation.newActivity(Instrumentation.java:1068)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2365)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2524)
at android.app.ActivityThread.access$900(ActivityThread.java:154)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1391)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:224)
at android.app.ActivityThread.main(ActivityThread.java:5526)
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)
I/Process: Sending signal. PID: 22562 SIG: 9
Disconnected from the target VM, address: 'localhost:8600', transport: 'socket'
package com.example.markwitt.schul_app;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
public class Rechner extends AppCompatActivity {
private RadioGroup radioGroup;
private RadioButton checked;
private Button los;
public String mode;
EditText number1 = (EditText) findViewById(R.id.nummer1);
EditText number2 = (EditText) findViewById(R.id.nummer2);
EditText ergebnis = (EditText) findViewById(R.id.ergebnis);
public int text1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_rechner);
addListenerOnButton();
}
public void addListenerOnButton() {
radioGroup = (RadioGroup) findViewById(R.id.radioGroup);
los = (Button) findViewById(R.id.button5);
los.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int selectedId = radioGroup.getCheckedRadioButtonId();
checked = (RadioButton) findViewById(selectedId);
switch (checked.getId()){
case R.id.plus: mode = "+";
case R.id.minus: mode = "-";
case R.id.mal: mode = "*";
case R.id.geteilt: mode = ":";
case R.id.fakultaet: mode = "fak";
}
text1 = Integer.parseInt(number1.getText().toString());
int text2 = Integer.parseInt(number2.getText().toString());
switch (mode){
case "+": ergebnis.setText(text1 + text2);
case "-": ergebnis.setText(text1 - text2);
case "*": ergebnis.setText(text1 * text2);
case ":": ergebnis.setText(text1 / text2);
case "fak": ergebnis.setText(Long.toString(fakultaet(text1)));
}
}
});
}
static long fakultaet(int n) {
int ergebnis = 1;
for (int i = 1; i <= n; i++) {
ergebnis = ergebnis * i;
}
return ergebnis;
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_durchschnitt"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.markwitt.schul_app.Rechner">
<EditText
android:id="@+id/nummer1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="12dp"
android:layout_weight="1"
android:ems="10"
android:hint="Nummer 1"
android:inputType="number"
android:maxLines="1"
android:textAlignment="center" />
<Button
android:id="@+id/button5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/ergebnis"
android:layout_centerHorizontal="true"
android:layout_marginBottom="22dp"
android:text="=" />
<RadioGroup
android:id="@+id/radioGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/nummer1"
android:layout_marginEnd="42dp"
android:layout_marginRight="42dp"
android:layout_marginTop="69dp"
android:orientation="horizontal">
<RadioButton
android:id="@+id/mal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/geteilt"
android:layout_alignBottom="@+id/geteilt"
android:layout_toLeftOf="@+id/geteilt"
android:layout_toStartOf="@+id/geteilt"
android:layout_weight="1"
android:text="* "
android:textAllCaps="true"
android:textStyle="bold" />
<RadioButton
android:id="@+id/fakultaet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/mal"
android:layout_alignBottom="@+id/mal"
android:layout_toLeftOf="@+id/mal"
android:layout_toStartOf="@+id/mal"
android:layout_weight="1"
android:text="Fakultät "
android:textAllCaps="true"
android:textStyle="bold" />
<RadioButton
android:id="@+id/plus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/minus"
android:layout_alignBottom="@+id/minus"
android:layout_toEndOf="@+id/nummer1"
android:layout_toRightOf="@+id/nummer1"
android:layout_weight="1"
android:text="+ "
android:textAllCaps="true"
android:textStyle="bold" />
<RadioButton
android:id="@+id/geteilt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/radioGroup"
android:layout_toEndOf="@+id/radioGroup"
android:layout_toRightOf="@+id/radioGroup"
android:layout_weight="1"
android:text=": "
android:textAllCaps="true"
android:textStyle="bold" />
<RadioButton
android:id="@+id/minus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/geteilt"
android:layout_alignBottom="@+id/geteilt"
android:layout_toLeftOf="@+id/plus"
android:layout_toStartOf="@+id/plus"
android:layout_weight="1"
android:text="- "
android:textAllCaps="true"
android:textStyle="bold" />
</RadioGroup>
<EditText
android:id="@+id/ergebnis"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/nummer2"
android:layout_alignParentBottom="true"
android:layout_alignStart="@+id/nummer2"
android:layout_marginBottom="61dp"
android:ems="10"
android:hint="Ergebnis"
android:inputType="number"
android:textAlignment="center" />
<EditText
android:id="@+id/nummer2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/nummer1"
android:layout_alignStart="@+id/nummer1"
android:layout_centerVertical="true"
android:ems="10"
android:hint="Nummer 2"
android:inputType="number"
android:textAlignment="center" />
</RelativeLayout>
EditText number1;
EditText number2;
EditText ergebnis;
public int text1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_rechner);
number1 = (EditText) findViewById(R.id.nummer1);
number2 = (EditText) findViewById(R.id.nummer2);
ergebnis = (EditText) findViewById(R.id.ergebnis);
addListenerOnButton();
}