Note that there are some explanatory texts on larger screens.

plurals
  1. POMy Android app won't start
    primarykey
    data
    text
    <p>I tried to make an Android app that would send a text to the server using asynctask. I successfully ran and tested one button, and now I'm having trouble with five buttons and five textviews.</p> <p>My activity_main layout:</p> <pre><code>&lt;RelativeLayout 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:background="@drawable/bckgrnd_2" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MainActivity" &gt; &lt;Button android:id="@+id/button1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center" android:text="@string/btn1" android:onClick="buttonClicked1" /&gt; &lt;Button android:id="@+id/button2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignRight="@+id/button1" android:layout_below="@+id/button1" android:onClick="buttonClicked2" android:text="@string/btn2" /&gt; &lt;Button android:id="@+id/button3" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignRight="@+id/button2" android:layout_below="@+id/button2" android:text="@string/btn3" android:onClick="buttonClicked3" /&gt; &lt;Button android:id="@+id/button4" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignLeft="@+id/button3" android:layout_below="@+id/button3" android:text="@string/btn4" android:onClick="buttonClicked4" /&gt; &lt;Button android:id="@+id/button5" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignRight="@+id/button4" android:layout_below="@+id/button4" android:onClick="buttonClicked5" android:text="@string/btn5" /&gt; &lt;EditText android:id="@+id/editText1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/button5" android:text="play1" /&gt; &lt;TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignRight="@+id/editText1" android:layout_below="@+id/editText2" android:text="play2" /&gt; &lt;TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignRight="@+id/textView1" android:layout_below="@+id/editText3" android:text="play3" /&gt; &lt;TextView android:id="@+id/textView3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/textView2" android:layout_below="@+id/editText4" android:text="play4" /&gt; &lt;TextView android:id="@+id/textView4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/textView3" android:layout_below="@+id/editText5" android:text="play5" /&gt; &lt;/RelativeLayout&gt; </code></pre> <p>My main activity code:</p> <pre><code>public class MainActivity extends Activity { private EditText textField; private EditText textField1; private EditText textField2; private EditText textField3; private EditText textField4; private Button button1; private Button button2; private Button button3; private Button button4; private Button button5; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); textField = (EditText) findViewById(R.id.editText1); textField1 = (EditText) findViewById(R.id.editText2); textField2 = (EditText) findViewById(R.id.editText3); textField3 = (EditText) findViewById(R.id.editText4); textField4 = (EditText) findViewById(R.id.editText5); button1 = (Button) findViewById(R.id.button1); button2 = (Button) findViewById(R.id.button2); button3 = (Button) findViewById(R.id.button3); button4 = (Button) findViewById(R.id.button4); button5 = (Button) findViewById(R.id.button5); textField.setVisibility(View.GONE); textField1.setVisibility(View.GONE); textField2.setVisibility(View.GONE); textField3.setVisibility(View.GONE); textField4.setVisibility(View.GONE); } public void buttonClicked1(View v){ Toast.makeText(this, "Song Has Been Successfully Added!", Toast.LENGTH_SHORT).show(); new asynctask().execute(textField); } public void buttonClicked2(View v) { Toast.makeText(this, "Song Has Been Successfully Added!", Toast.LENGTH_SHORT).show(); new asynctask().execute(textField1); } public void buttonClicked3(View v) { Toast.makeText(this, "Song Has Been Successfully Added!", Toast.LENGTH_SHORT).show(); new asynctask().execute(textField2); } public void buttonClicked4(View v) { Toast.makeText(this, "Song Has Been Successfully Added!", Toast.LENGTH_SHORT).show(); new asynctask().execute(textField3); } public void buttonClicked5(View v) { Toast.makeText(this, "Song Has Been Successfully Added!", Toast.LENGTH_SHORT).show(); new asynctask().execute(textField4); } } </code></pre> <p>Asynctask code:</p> <pre><code>public class asynctask extends AsyncTask&lt;View, Integer, Socket&gt; { private static final String IP_ADDRESS = "192.168.1.106"; private static final int DEST_PORT = 7777; private EditText mTextField; protected Socket doInBackground(View... params) { if (params.length != 1) throw new IllegalArgumentException(); mTextField = (EditText) params[0]; Socket client = null; try { client = new Socket(IP_ADDRESS, DEST_PORT); } catch (UnknownHostException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return client; } protected void onPostExecute(Socket client) { try { PrintWriter printwriter; String messsage; messsage = mTextField.getText().toString(); mTextField.setText(""); printwriter = new PrintWriter(client.getOutputStream(), true); printwriter.write(messsage); printwriter.flush(); printwriter.close(); client.close(); } catch (IOException e) { e.printStackTrace(); } } } </code></pre> <p>This is what my logcat says:</p> <pre><code>09-12 01:28:30.914: E/AndroidRuntime(560): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) 09-12 01:28:30.914: E/AndroidRuntime(560): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 09-12 01:28:30.914: E/AndroidRuntime(560): at dalvik.system.NativeStart.main(Native Method) 09-12 01:28:30.914: E/AndroidRuntime(560): Caused by: java.lang.NullPointerException 09-12 01:28:30.914: E/AndroidRuntime(560): at com.timskie.dancingfountainv1.MainActivity.onCreate(MainActivity.java:46) 09-12 01:28:30.914: E/AndroidRuntime(560): at android.app.Activity.performCreate(Activity.java:4465) 09-12 01:28:30.914: E/AndroidRuntime(560): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049) 09-12 01:28:30.914: E/AndroidRuntime(560): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919) 09-12 01:28:30.914: E/AndroidRuntime(560): ... 11 more </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload