资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

奇葩的java代码 经典java代码

java中DOM解析XML文件奇葩的错误 java.lang.NullPointerException

代码如下:

原阳网站制作公司哪家好,找成都创新互联!从网页设计、网站建设、微信开发、APP开发、响应式网站建设等网站项目制作,到程序开发,运营维护。成都创新互联于2013年创立到现在10年的时间,我们拥有了丰富的建站经验和运维经验,来保证我们的工作的顺利进行。专注于网站建设就选成都创新互联

public class LoadXml extends Activity {

private final static String TAG="LoadXml";

public static Context context = null;

Document document = null;

NodeList childsNodes = null;

DocumentBuilderFactory factory = null;

DocumentBuilder builder = null;

InputStream inputStreams = null;

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

Button button1=(Button)findViewById(R.id.button1);

button1.setOnClickListener(button1OnClickListener);

}

OnClickListener button1OnClickListener=new OnClickListener(){

@Override

public void onClick(View v) {

Log.d(TAG, "onClick");

getComplateXml();

}

};

public void getComplateXml(){

Log.d(TAG, "123");

try {

Log.d(TAG, "getComplateXml");

readUserConfig();

// int j = 0;

// for (int i = 0; i childsNodes.getLength(); i++) {

// Log.d(TAG, "1");

// Node node = (Node) childsNodes.item(i);

// Log.d(TAG, "2");

// ContentResolver contentResolver = this.context

// .getContentResolver();

// Log.d(TAG, "3");

// Uri insertUri = Uri.parse("content://com.huawei.biz.LoadContentProvider/STUDENT");

// Log.d(TAG, "4");

// ContentValues values = new ContentValues();

// values.put("name", node.getNodeName());

// Log.d(TAG, node.getNodeName());

//

// values.put("id", node.getFirstChild().getNodeValue());

// Log.d(TAG, node.getFirstChild().getNodeValue());

//

// values.put("Photo",DataManager.getDrawableList().get(j));

// Log.d(TAG, DataManager.getDrawableList().get(j).toString());

// contentResolver.insert(insertUri, values);

// j++;

// }

} catch (Exception e) {

e.printStackTrace();

}

}

private void readUserConfig() throws Exception{

Log.d(TAG, "readUserConfig");

Log.d(TAG, "1");

factory = DocumentBuilderFactory.newInstance();

Log.d(TAG, "2");

builder = factory.newDocumentBuilder();

Log.d(TAG, "3");

inputStreams = LoadXml.context.getResources().getAssets().open("student.xml");

Log.d(TAG, "4");

document = builder.parse(inputStreams);

Log.d(TAG, "5");

childsNodes = document.getDocumentElement().getChildNodes();

Log.d(TAG, "6");

}

}

java面试题:一个人早上八点上山,晚上八点到达山顶。第二天早上八点下山,晚上八点到达山底。

java面试题的解析方式(思路如下):

public static void main(String[] args) {

// TODO Auto-generated method stub

int up = 8;

int down = 8;

while(up=20){

if((up == 20-6) (up == 20-6)){

System.out.println("在"+up+"时到达同一地点");

break;

}

up += 1;

down += 1;

}

}

微软面试题的背后

微软的奇葩面试题答案并不重要,重要的是思考过程,而思考过程体现了你是否拥有公司所看重的能力,不仅是微软,其他公司的面试也是为了测试你的某种能力,如果你提前培养了这种能力,相当于知道了面试的“考纲”,在面试中自然就从容不迫,游刃有余了。

平时要知道转化能力是看透问题,然后找到解决方案的能力。所以转化能力最重要的是如何看透问题,也就是你思考问题的方式。

教我写下小代码吧 java

interface Instrument{

void play();

}

class Piano implements Instrument{

public void play() {

System.out.println("play Piano");

}

}

class Violin implements Instrument{

public void play() {

System.out.println("play Violin");

}

}

public class InstrumentTest{

public static void main(String[] args) {

Instrument i1 = new Piano();

Instrument i2 = new Violin();

i1.play();

i2.play();

}

}

java线程的经典代码

package threadgroup;

class ThreadDemo3 extends Thread {

private String name;

private int delay;

public ThreadDemo3(String sname, int i_delay) {

name = sname;

delay = i_delay;

}

public void run() {

try {

sleep(delay);

} catch (InterruptedException e) {

}

System.out.println("多线程测试!\n" + name + "\n" + delay);

}

}

public class testMyThread {

public static void main(String[] args) {

ThreadDemo3 th1,th2,th3;

th1 = new ThreadDemo3("线程1", (int) (Math.random() * 900));

th2 = new ThreadDemo3("线程2", (int) (Math.random() * 900));

th3 = new ThreadDemo3("线程3", (int) (Math.random() * 900));

th1.start();

th2.start();

th3.start();

}

}

package threadgroup;

public class threadDemo {

public static void main(String[] args) {

Thread t = Thread.currentThread();

t.setName("你好吗?");

System.out.println("正在进行的Thread是:" + t);

try {

for (int i = 0; i 5; i++) {

System.out.println("我不叫穆继超" + i);

Thread.sleep(3000);

}

} catch (Exception e) {

// TODO: handle exception

System.out.println("Thread has wrong" + e.getMessage());

}

}

}

package threadgroup;

public class threadDemo2 implements Runnable {

public threadDemo2() {

Thread t1 = Thread.currentThread();

t1.setName("第一个主进程");

System.out.println("正在运行" + t1);

Thread t2 = new Thread(this, "");

System.out.println("在创建一个进程");

t2.start();

try {

System.out.println("使他进入第一个睡眠状态");

Thread.sleep(2000);

} catch (InterruptedException e) {

System.out.println("Thread has wrong" + e.getMessage());

}

System.out.println("退出第一个进程");

}

public void run() {

try {

for (int i = 0; i 5; i++) {

System.out.println("进程" + i);

Thread.sleep(3000);

}

} catch (InterruptedException e) {

// TODO: handle exception

System.out.println("Thread has wrong" + e.getMessage());

}

System.out.println("退出第二个进程");

}

public static void main(String[] args) {

new threadDemo2();

}

}


当前文章:奇葩的java代码 经典java代码
本文URL:http://cdkjz.cn/article/dohpccs.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220