当应用程序异常退出时,我遇到了一个失败的活页夹事务错误,但没有任何意图。 每个xml的图像低于40K,所以我认为它不是图像的问题。 这是我的代码。
... ...
public class MainActivity extends Activity implements OnClickListener{
private SlideMenu slideMenu;
static Socket socket;
private TextView titleName;
private RelativeLayout container;
private Map<String, String> mainleft;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mainleft = new LinkedHashMap<String, String>();
titleName = (TextView)findViewById(R.id.title_bar_name);
container = (RelativeLayout)findViewById(R.id.container);
slideMenu = (SlideMenu) findViewById(R.id.slide_menu);
ImageView menuImg = (ImageView) findViewById(R.id.title_bar_menu_btn);
menuImg.setOnClickListener(this);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
TelephonyManager telephonyManager = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
String IMEI = telephonyManager.getDeviceId();
System.out.println("IMEI:" + IMEI);
try {
FragmentViewall fragment1 = new FragmentViewall(getBaseContext(),"zhuxitong.xml");
getFragmentManager().beginTransaction().replace(R.id.container, fragment1).commit();
slideMenu.closeMenu();
titleName.setText((CharSequence) "zhuxitong");
container.setBackgroundColor(Color.WHITE);
InputStream input = getResources().getAssets().open("mainleftcfg.xml");
XmlPullParser pullParser = Xml.newPullParser();
pullParser.setInput(input, "UTF-8");
int event = pullParser.getEventType();
String[] temp = null;
while (event != XmlPullParser.END_DOCUMENT)
{
switch (event)
{
case XmlPullParser.START_DOCUMENT:
break;
case XmlPullParser.START_TAG:
if("item".equals(pullParser.getName()))
{
temp = new String[2];
}
if ("name".equals(pullParser.getName()))
temp[0] = new String(pullParser.nextText());
if ("xmlname".equals(pullParser.getName()))
temp[1] = new String(pullParser.nextText());
break;
case XmlPullParser.END_TAG:
if("item".equals(pullParser.getName()))
{
mainleft.put(temp[0], temp[1]);
temp = null;
}
break;
}
event = pullParser.next();
}
} catch (XmlPullParserException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
initView();
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.title_bar_menu_btn:
if (slideMenu.isMainScreenShowing()) {
slideMenu.openMenu();
} else {
slideMenu.closeMenu();
}
break;
}
}
private int initView()
{
new Thread() {
public void run() {
String serverIP = LoginActivity.socketipValue;
String serverDK = LoginActivity.socketdkValue;
try {
socket = new Socket(serverIP, Integer.parseInt(serverDK));
} catch (NumberFormatException e) {
e.printStackTrace();
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}.start();
View line = new View(this);
line.setBackgroundResource(R.drawable.ic_shelf_category_divider);
Drawable drawable= getResources().getDrawable(R.drawable.ic_category_mark2);
drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
LinearLayout linearLayout = (LinearLayout) findViewById(R.id.leftq);
Iterator iter = mainleft.entrySet().iterator();
while (iter.hasNext())
{
Map.Entry entry = (Map.Entry) iter.next();
final String temp = (String)entry.getValue();
final String temp2 = (String)entry.getKey();
TextView textt = new TextView(this);
textt.setText((CharSequence) entry.getKey());
textt.setTextColor(Color.WHITE);
textt.setTextSize(18);
textt.setGravity(Gravity.CENTER);
textt.setBackgroundResource(R.drawable.selector_category_item);
textt.setCompoundDrawables(drawable,null,null,null);
textt.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
FragmentViewall fragment1 = new FragmentViewall(getBaseContext(), temp);
getFragmentManager().beginTransaction().replace(R.id.container, fragment1).commit();
slideMenu.closeMenu();
titleName.setText((CharSequence) temp2);
container.setBackgroundColor(Color.WHITE);
}
});
linearLayout.addView(textt);
}
TextView texttv = new TextView(this);
texttv.setText(getResources().getString(R.string.g6c1_video));
texttv.setTextColor(Color.WHITE);
texttv.setTextSize(18);
texttv.setGravity(Gravity.CENTER);
texttv.setBackgroundResource(R.drawable.ic_item_selected_bg);
texttv.setCompoundDrawables(drawable,null,null,null);
texttv.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
videoontimeFragment fragment1 = new videoontimeFragment();
getFragmentManager().beginTransaction().replace(R.id.container, fragment1).commit();
slideMenu.closeMenu();
titleName.setText(getResources().getString(R.string.g6c1_video));
container.setBackgroundColor(Color.WHITE);
}
});
linearLayout.addView(texttv);
TextView texttb = new TextView(this);
texttb.setText(getResources().getString(R.string.g6c2_video));
texttb.setTextColor(Color.WHITE);
texttb.setTextSize(18);
texttb.setGravity(Gravity.CENTER);
texttb.setBackgroundResource(R.drawable.ic_item_selected_bg);
texttb.setCompoundDrawables(drawable,null,null,null);
texttb.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
videobackFragment fragment1 = new videobackFragment();
getFragmentManager().beginTransaction().replace(R.id.container, fragment1).commit();
slideMenu.closeMenu();
titleName.setText(getResources().getString(R.string.g6c2_video));
container.setBackgroundColor(Color.WHITE);
}
});
linearLayout.addView(texttb);
TextView textt = new TextView(this);
textt.setText(getResources().getString(R.string.action_loginout));
textt.setTextColor(Color.WHITE);
textt.setTextSize(18);
textt.setGravity(Gravity.CENTER);
textt.setBackgroundResource(R.drawable.selector_category_item);
textt.setCompoundDrawables(drawable,null,null,null);
textt.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
LoginActivity.sp.edit().putBoolean("AUTO_ISCHECK", false).commit();
LoginActivity.sp.edit().clear().commit();
Intent intent = new Intent(MainActivity.this,LoginActivity.class);
MainActivity.this.startActivity(intent);
MainActivity.this.finish();
slideMenu.closeMenu();
}
});
linearLayout.addView(textt);
TextView textt2 = new TextView(this);
textt2.setText(getResources().getString(R.string.action_settings));
textt2.setTextColor(Color.WHITE);
textt2.setTextSize(18);
textt2.setGravity(Gravity.CENTER);
textt2.setBackgroundResource(R.drawable.selector_category_item);
textt2.setCompoundDrawables(drawable,null,null,null);
textt2.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
AlertDialog.Builder builder = new Builder(MainActivity.this);
builder.setMessage("1.0");
builder.setPositiveButton("Confirm",
new android.content.DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
builder.create().show();
slideMenu.closeMenu();
}
});
linearLayout.addView(textt2);
return 0;
}
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
dialog();
return true;
}
return true;
}
protected void dialog() {
AlertDialog.Builder builder = new Builder(MainActivity.this);
builder.setMessage("Quit?");
builder.setTitle("tips");
builder.setPositiveButton("Confirm",
new android.content.DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
android.os.Process.killProcess(android.os.Process.myPid());
}
});
builder.setNegativeButton("Cancel",
new android.content.DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
builder.create().show();
}
}