日期:2014-05-20  浏览次数:20737 次

用Eclipse中文引号或注释当中GBK和UTF-8切换多次之后成乱码
用Eclipse中文引号或注释当中GBK和UTF-8切换多次之后成乱码
再切换之后,就改不过来了,而且乱码修改都不能保存,提示乱码错误什么的。很麻烦,

Java code

/**
 * prj5_1.java
 * 锟斤拷示锟斤拷锟斤拷诒?锟斤拷使锟斤拷ChoiceGroup
 * @ 锟斤拷锟斤拷
 * @ version 1.0
 * create on 2008-10-27
 */
package src;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.Display;
//import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
//import javax.microedition.lcdui.Item;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;


public class prj5_1 extends MIDlet {
    
    private Form mainForm=new Form("锟斤拷锟角匡拷锟斤拷锟斤拷锟斤拷锟揭伙拷锟斤拷锟紺hoiceGroup锟斤拷Form");
    private Display dis;
    
    private ChoiceGroup cg1=new ChoiceGroup("选锟斤拷锟皆别(碉拷选 锟斤拷",ChoiceGroup.EXCLUSIVE);//Choice.MULTIPLE;Fields inherited from interface javax.microedition.lcdui.Choice 
    private ChoiceGroup cg2=new ChoiceGroup("选锟斤拷锟皆别(菜碉拷 锟斤拷",ChoiceGroup.POPUP);
    private ChoiceGroup cg3=new ChoiceGroup("选锟今爱好o拷锟斤拷选 锟斤拷",ChoiceGroup.MULTIPLE);

//    public prj5_1() {
//        // TODO 锟皆讹拷锟斤拷晒锟斤拷旌拷锟斤拷锟?
//    }

    protected void startApp() throws MIDletStateChangeException {
        dis=Display.getDisplay(this);//应锟斤拷锟皆撅拷态锟斤拷式锟斤拷锟斤拷锟斤拷锟斤拷 Display 锟叫的撅拷态锟斤拷锟斤拷 getDisplay锟斤拷MIDlet锟斤拷
        dis.setCurrent(mainForm);
        
        mainForm.append(cg1);
        cg1.append("锟斤拷", null);
        cg1.append("女", null);
        
        mainForm.append(cg2);
        cg2.append("锟斤拷", null);
        cg2.append("女", null);
        
        mainForm.append(cg3);
        cg3.append("锟斤拷锟斤拷", null);
        cg3.append("锟杰诧拷", null);
        cg3.append("锟斤拷锟斤拷", null);
        
        dis.setCurrentItem(cg3);//锟斤拷为默锟斤拷选锟斤拷锟节达拷之前一锟斤拷要锟接碉拷FORM锟斤拷
        // TODO 锟皆讹拷锟斤拷煞锟斤拷锟斤拷锟斤拷

    }
    
    protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
        // TODO 锟皆讹拷锟斤拷煞锟斤拷锟斤拷锟斤拷

    }

    protected void pauseApp() {
        // TODO 锟皆讹拷锟斤拷煞锟斤拷锟斤拷锟斤拷

    }



}






------解决方案--------------------
换成这种方式吧

String str = "中文字";
for (int i=0;i<str.length();i++)
{
char c=str.charAt(i);
String so = Integer.toHexString(c);
//System.out.println(c + "'s unicode: "+so); 
System.out.print("\\u"+so);
}

画字的地方就用\uXXXXXX的编码。
------解决方案--------------------
在Eclipse或MyEclipse中,选中出乱码的那个文件,右键,选择properties,再other中选择相应的encoding,试一下
------解决方案--------------------
去属性里面找找java >>>> text里的java project 把编码格式转换为UTF-8试试!