我有这个logcat错误,它无法启动活动..
04-25 17:51:54.889: E/AndroidRuntime(1238): Process: com.mobilebasedtexttosignlanguageconverter, PID: 1238
04-25 17:51:54.889: E/AndroidRuntime(1238): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mobilebasedtexttosignlanguageconverter/com.mobilebasedtexttosignlanguageconverter.MainActivity}: java.lang.NullPointerException
04-25 17:51:54.889: E/AndroidRuntime(1238): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
04-25 17:51:54.889: E/AndroidRuntime(1238): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
04-25 17:51:54.889: E/AndroidRuntime(1238): at android.app.ActivityThread.access$800(ActivityThread.java:135)
04-25 17:51:54.889: E/AndroidRuntime(1238): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
04-25 17:51:54.889: E/AndroidRuntime(1238): at android.os.Handler.dispatchMessage(Handler.java:102)
04-25 17:51:54.889: E/AndroidRuntime(1238): at android.os.Looper.loop(Looper.java:136)
04-25 17:51:54.889: E/AndroidRuntime(1238): at android.app.ActivityThread.main(ActivityThread.java:5017)
04-25 17:51:54.889: E/AndroidRuntime(1238): at java.lang.reflect.Method.invokeNative(Native Method)
04-25 17:51:54.889: E/AndroidRuntime(1238): at java.lang.reflect.Method.invoke(Method.java:515)
04-25 17:51:54.889: E/AndroidRuntime(1238): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
04-25 17:51:54.889: E/AndroidRuntime(1238): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
04-25 17:51:54.889: E/AndroidRuntime(1238): at dalvik.system.NativeStart.main(Native Method)
04-25 17:51:54.889: E/AndroidRuntime(1238): Caused by: java.lang.NullPointerException
04-25 17:51:54.889: E/AndroidRuntime(1238): at com.mobilebasedtexttosignlanguageconverter.MainActivity.onCreate(MainActivity.java:34)
04-25 17:51:54.889: E/AndroidRuntime(1238): at android.app.Activity.performCreate(Activity.java:5231)
04-25 17:51:54.889: E/AndroidRuntime(1238): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
04-25 17:51:54.889: E/AndroidRuntime(1238): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
这是我的主要活动..
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
getFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
}
Button conv = (Button)findViewById(R.id.btn_conv);
//Button inst = (Button)findViewById(R.id.btn_ins);
//Button view = (Button)findViewById(R.id.btn_view);
//Button ext = (Button)findViewById(R.id.btn_ex);
conv.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent conv = new Intent(MainActivity.this, ConvertSubMenu.class);
startActivity(conv);
}
});
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.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();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container,
false);
return rootView;
}
}
请帮助我,我刚刚安装了最新的eclipse,我对android的更新的sdk管理器有问题,因为它对我来说很新..
答案 0 :(得分:0)
我的猜测是findViewById正在返回null
。确保您的布局中有一个ID为btn_conv
的按钮。