我来自德国,是java和Android编程的新手。在我的第一个应用程序中,我有2页。此时第一页(aktivity_main.xml)为空。在那里,我想构建一个listView。当我进入菜单并单击 “Hinzufügen” ( - >在英语中表示“添加”)时,第二页(mypage)将打开。
在此,我可以输入我的输入。这里开始我的问题。 (我搜索了几天,但是我做了,它不起作用!)当我改变放射组中的状态时,Text (TextDefinitionWert:“Bitte geben SieIhrengewünschtenMaximalwertein:”) 应该在anohter Text中更改,保存在String.xml中。但它不起作用。只有 NullPointerException
这是 MainActivity.Java :
的代码package ilyas.ausgabenkontrolle;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.*;
import android.widget.RadioGroup.*;
public class MainActivity extends Activity implements RadioGroup.OnCheckedChangeListener {
TextView TextHeaderNeuBearbeiten;
TextView TextDefinitionWert;
RadioButton RadioUp;
RadioButton RadioDown;
EditText EditName;
EditText EditWert;
Button ButtonOKnb;
RadioGroup RadioGroup;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextHeaderNeuBearbeiten = (TextView) findViewById(R.id.TextHeaderNeuBearbeiten) ;
TextDefinitionWert = (TextView ) findViewById(R.id.TextDefinitionWert);
RadioUp = (RadioButton) findViewById(R.id.RadioUp);
RadioDown = (RadioButton) findViewById(R.id.RadioDown);
EditName = (EditText) findViewById(R.id.EditName);
EditWert = (EditText) findViewById(R.id.EditWert);
ButtonOKnb = (Button) findViewById(R.id.ButtonOKnb);
RadioGroup = (RadioGroup) findViewById(R.id.radioGroup1);
//the next line causes the Exception. When I delete this line, the Emulator starts, but when I change the stats, nothing happens:
RadioGroup.setOnCheckedChangeListener(this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.activity_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.toString().equals("Hinzufügen")) {
setContentView(R.layout.neuesbearbeiten);
}
return true;
}
public void onCheckedChanged(RadioGroup RadioGroup, int checkedId) {
// TODO Auto-generated method stub
switch (checkedId) {
case R.id.RadioUp:
TextDefinitionWert.setText(R.string.definitionup);
break;
case R.id.RadioDown:
TextDefinitionWert.setText(R.string.definitiondown);
break;
}
}
}
(由于我是新来的,我无法发布图片。)
LogCat是这样的:
ilyas.ausgabenkontrolle/ilyas.ausgabenkontrolle.MainActivity}: java.lang.NullPointerException
at android.app.activityThread.performLaunchActivity(ActivityThread.java:1956)
at android.app.activityThread.handleLaunchActivity(ActivityThread.java:1981)
at android.app.activityThread.access$600(ActivityThread.java:123)
at android.app.activityThread$H.handleMessage(ActivityThread.java:1147)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at ilyas.ausgabenkontrolle.MainActivity.onCreate(MainActivity.java:37)
at android.app.Activity.performCreate(Activity.java:4465)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
at android.app.activityThread.performLaunchActivity(ActivityThread.java:1920)
... 11 more
我希望你能帮助我。我不知道为什么会这样。