unfortunately ,....has stopped问题求解决
我按照网上给的教学视频编写一个多选框的案例,程序编译是对的,但是当apk程序在虚拟机上运行的时候就出现unfortunately ,....has stopped这样的错误
错误一
具体代码如下:
//main_activity.java
package com.dylan.s01_e09_checkbox;
import android.app.Activity;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.CheckBox;
public class MainActivity extends Activity {
@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();
}
}
@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);
CheckBox eatBox = (CheckBox)rootView.findViewById(R.id.eatId);
CheckBox sleepBox = (CheckBox)rootView.findViewById(R.id.sleepId);
CheckBox dotaBox = (CheckBox)rootView.findViewById(R.id.dotaId);
OnBoxClickListener listener = new OnBoxClickListener();
eatBox.setOnClickListener(listener);
sleepBox.setOnClickListener(listener);
dotaBox.setOnClickListener(listener);
return rootView;
}
}
public static class OnBoxClickListener implements OnClickListener{
@Override
public void onClick(View arg0) {
System.out.println("Checkbox is clicked");
}
}
}
红色字体部分是我添加的代码。。。
fragment_main.xml文件如下:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.dylan.s01_e09_checkbox.MainActivity$PlaceholderFragment" >
<CheckBok
android:id="@+id/eatId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="吃饭" />
<CheckBok
android:id="@+id/sleepId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="睡觉" />
<CheckBok
android:id="@+id/dotaId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="dota" />
</LinearLayout>
出现错误的logcat代码如下:
04-20 06:26:29.158: E/AndroidRuntime(1107): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dylan.s01_e09_checkbox/com.dylan.s01_e09_checkbox.MainActivity}: android.view.InflateException: Binary XML file line #8: Error inflating class CheckBok
错误二
还有就是在我每次保存main_activity文件的时候总会跳出
'Running Android Lint' has encountered a problem
An internal error occurred during :"Running Android Lint"
虽然这个错误提示不影响整体的运行结果,但总是看到心里还是不舒服的。。。
请问这些问题怎么解决啊,大神求帮忙了。。。