package com.example.mypptcontrol;import java.io.IOException;import java.io.OutputStream;import java.io.PrintWriter;import java.net.Socket;import java.net.UnknownHostException;import android.app.Activity;import android.os.Bundle;import android.view.Menu;import android.view.MenuItem;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.EditText;import android.widget.Toast;public class MainActivity extends Activity { private Button loginButton1; private Button loginButton2; private Button loginButton3; private Button loginButton4; private Button loginButton5; public String ppt; PrintWriter pw = null; Socket socket=null; OutputStream os=null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //初始化连接按钮 loginButton1 =(Button) findViewById(R.id.button2); loginButton2 =(Button) findViewById(R.id.button5); loginButton3 =(Button) findViewById(R.id.button6); loginButton4 =(Button) findViewById(R.id.button4); loginButton4 =(Button) findViewById(R.id.button1); EditText et = (EditText)findViewById(R.id.editText1); //获取edittext文本内容 String value1 = et.getText().toString(); EditText et2 = (EditText)findViewById(R.id.editText2); loginButton1.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { // TODO 自动生成的方法存根 try { socket=new Socket("123.150.226.119",7777); os=socket.getOutputStream(); pw= new PrintWriter(os); } catch (UnknownHostException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } catch (IOException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } } }); loginButton2.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { // TODO 自动生成的方法存根 ppt="F6"; } }); loginButton3.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { // TODO 自动生成的方法存根 ppt="last"; } }); loginButton4.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { // TODO 自动生成的方法存根 ppt="next"; } }); loginButton5.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { // TODO 自动生成的方法存根 ppt="stop"; } }); if(ppt!="stop"){ pw.write(ppt); pw.flush(); }else{ pw.write(ppt); pw.flush(); pw.flush(); try { os.close(); } catch (IOException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } try { socket.close(); } catch (IOException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } } } 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); } }上面是MainActivity的代码 10-27 08:01:43.183: D/AndroidRuntime(1151): Shutting down VM10-27 08:01:43.183: W/dalvikvm(1151): threadid=1: thread exiting with uncaught exception (group=0xb3adaba8)10-27 08:01:43.203: E/AndroidRuntime(1151): FATAL EXCEPTION: main10-27 08:01:43.203: E/AndroidRuntime(1151): Process: com.example.mypptcontrol, PID: 115110-27 08:01:43.203: E/AndroidRuntime(1151): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mypptcontrol/com.example.mypptcontrol.MainActivity}: java.lang.NullPointerException10-27 08:01:43.203: E/AndroidRuntime(1151): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)10-27 08:01:43.203: E/AndroidRuntime(1151): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)10-27 08:01:43.203: E/AndroidRuntime(1151): at android.app.ActivityThread.access$800(ActivityThread.java:135)10-27 08:01:43.203: E/AndroidRuntime(1151): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)10-27 08:01:43.203: E/AndroidRuntime(1151): at android.os.Handler.dispatchMessage(Handler.java:102)10-27 08:01:43.203: E/AndroidRuntime(1151): at android.os.Looper.loop(Looper.java:136)10-27 08:01:43.203: E/AndroidRuntime(1151): at android.app.ActivityThread.main(ActivityThread.java:5001)10-27 08:01:43.203: E/AndroidRuntime(1151): at java.lang.reflect.Method.invokeNative(Native Method)10-27 08:01:43.203: E/AndroidRuntime(1151): at java.lang.reflect.Method.invoke(Method.java:515)10-27 08:01:43.203: E/AndroidRuntime(1151): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)10-27 08:01:43.203: E/AndroidRuntime(1151): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)10-27 08:01:43.203: E/AndroidRuntime(1151): at dalvik.system.NativeStart.main(Native Method)10-27 08:01:43.203: E/AndroidRuntime(1151): Caused by: java.lang.NullPointerException10-27 08:01:43.203: E/AndroidRuntime(1151): at com.example.mypptcontrol.MainActivity.onCreate(MainActivity.java:90)10-27 08:01:43.203: E/AndroidRuntime(1151): at android.app.Activity.performCreate(Activity.java:5231)10-27 08:01:43.203: E/AndroidRuntime(1151): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)10-27 08:01:43.203: E/AndroidRuntime(1151): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)10-27 08:01:43.203: E/AndroidRuntime(1151): ... 11 more10-27 08:01:48.223: I/Process(1151): Sending signal. PID: 1151 SIG: 9这是eclipse报错 求大神看看我就是想做一个手机控制电脑ppt播放 这是客户端
添加回答
举报
0/150
提交
取消