I am not sure where exactly this error is occurring.
I have used intent with no problems for my main menu linking to other activities
I am trying to take in two values for the connection settings of my app and then pass it on to another activity so that it can connect to the server.Again I am not entirely sure what is going wrong.
03-12 15:31:59.588 5671-5671/killianmills.pycast W/ApplicationPackageManager﹕ getCSCPackageItemText()
03-12 15:31:59.718 5671-5671/killianmills.pycast I/Adreno-EGL﹕ <qeglDrvAPI_eglInitialize:381>: EGL 1.4 QUALCOMM build: (CL3869936)
OpenGL ES Shader Compiler Version: 17.01.11.SPL
Build Date: 01/17/14 Fri
Local Branch:
Remote Branch:
Local Patches:
Reconstruct Branch:
03-12 15:31:59.758 5671-5671/killianmills.pycast D/OpenGLRenderer﹕ Enabling debug mode 0
03-12 15:31:59.858 5671-5671/killianmills.pycast V/RenderScript﹕ 0x79275f50 Launching thread(s), CPUs 4
03-12 15:32:31.018 5671-5671/killianmills.pycast W/ApplicationPackageManager﹕ getCSCPackageItemText()
03-12 15:32:33.921 5671-5671/killianmills.pycast D/dalvikvm﹕ newInstance failed: Lkillianmills/pycast/GeneralMode; not accessible to Landroid/app/Instrumentation;
03-12 15:32:33.921 5671-5671/killianmills.pycast D/AndroidRuntime﹕ Shutting down VM
03-12 15:32:33.921 5671-5671/killianmills.pycast W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x4189dda0)
03-12 15:32:33.931 5671-5671/killianmills.pycast E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: killianmills.pycast, PID: 5671
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{killianmills.pycast/killianmills.pycast.GeneralMode}: java.lang.IllegalAccessException: access to class not allowed
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2231)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363)
at android.app.ActivityThread.access$900(ActivityThread.java:161)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1265)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5356)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalAccessException: access to class not allowed
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1208)
at android.app.Instrumentation.newActivity(Instrumentation.java:1079)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2222)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363)
at android.app.ActivityThread.access$900(ActivityThread.java:161)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1265)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5356)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)
03-12 15:32:35.833 5671-5671/killianmills.pycast I/Process﹕ Sending signal. PID: 5671 SIG: 9
device not found
General Mode- Where I want to pick up the values established in the connectionSettings activity
package killianmills.pycast;
import android.app.Activity;
import android.graphics.Point;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.Display;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.VelocityTracker;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;
public class GeneralMode extends Activity {
private Socket client;
private PrintWriter printwriter;
private EditText textField;
private Button button;
private Button buttonLeft;
private Button buttonRight;
private Button buttonEnter;
private Button keyRight;
private Button keyLeft;
private Button keyUp;
private Button keyDown;
private String message;
private static final String DEBUG_TAG = "Velocity";
private VelocityTracker mVelocityTracker = null;
public boolean onTouchEvent(MotionEvent event) {
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int trackPadWidth = size.x;
int trackPadHeight = (size.y / 2)+((int)(size.y*.05));
int touchedX = (int) event.getX();
int touchedY = (int) event.getY();
int index = event.getActionIndex();
int action = event.getActionMasked();
int pointerId = event.getPointerId(index);
if(touchedY<trackPadHeight && touchedX < trackPadWidth ){
switch (action) {
case MotionEvent.ACTION_DOWN:
if (mVelocityTracker == null) {
mVelocityTracker = VelocityTracker.obtain();
} else {
mVelocityTracker.clear();
}
mVelocityTracker.addMovement(event);
break;
case MotionEvent.ACTION_MOVE:
mVelocityTracker.addMovement(event);
mVelocityTracker.computeCurrentVelocity(1000);
message = ("0" + (int) (mVelocityTracker.getXVelocity() * .0125) + " " + (int) (mVelocityTracker.getYVelocity() * .0125)).toString();
SendMessage sendMessageTask = new SendMessage();
sendMessageTask.execute();
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
mVelocityTracker.recycle();
mVelocityTracker = null;
break;
}
return true;
}
return false;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_general_mode);
textField = (EditText) findViewById(R.id.editText1);
button = (Button) findViewById(R.id.button1);
buttonLeft= (Button) findViewById(R.id.buttonLeftClick);
buttonRight= (Button) findViewById(R.id.buttonRightClick);
buttonEnter= (Button) findViewById(R.id.buttonEnterClick);
keyRight= (Button) findViewById(R.id.buttonRightk);
keyLeft= (Button) findViewById(R.id.buttonLeftk);
keyUp= (Button) findViewById(R.id.buttonUpk);
keyDown= (Button) findViewById(R.id.buttonDownk);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
message = "2"+textField.getText().toString();
textField.setText("");
SendMessage sendMessageTask = new SendMessage();
sendMessageTask.execute();
}
});
buttonLeft.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
message="11";
SendMessage sendMessageTask = new SendMessage();
sendMessageTask.execute();
}
});
buttonRight.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
message="12";
SendMessage sendMessageTask = new SendMessage();
sendMessageTask.execute();
}
});
buttonEnter.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
message="3";
SendMessage sendMessageTask = new SendMessage();
sendMessageTask.execute();
}
});
keyRight.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
message="6";
SendMessage sendMessageTask = new SendMessage();
sendMessageTask.execute();
}
});
keyLeft.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
message="7";
SendMessage sendMessageTask = new SendMessage();
sendMessageTask.execute();
}
});
keyUp.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
message="4";
SendMessage sendMessageTask = new SendMessage();
sendMessageTask.execute();
}
});
keyDown.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
message="5";
SendMessage sendMessageTask = new SendMessage();
sendMessageTask.execute();
}
});
}
private class SendMessage extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... params) {
try {
//client = new Socket("136.206.213.38", 4444);
client = new Socket("192.168.1.39", 4444);
printwriter = new PrintWriter(client.getOutputStream(), true);
printwriter.write(message);
printwriter.flush();
printwriter.close();
client.close(); // closing the connection
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_general_mode, menu);
return true;
}
}
Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="killianmills.pycast" >
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.INTERNET" >
</uses-permission>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".GeneralMode"
android:label="@string/title_activity_general_mode" >
</activity>
<activity
android:name=".ConnectionSettings"
android:label="@string/title_activity_connection_settings" >
</activity>
<activity
android:name=".About"
android:label="@string/title_activity_about" >
</activity>
<activity
android:name=".PresentationMode"
android:label="@string/title_activity_presentation_mode" >
</activity>
</application>
</manifest>
and the connectionSettings
package killianmills.pycast;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class ConnectionSettings extends Activity {
private Button connectButton;
private EditText ip, port;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_connection_settings);
ip = (EditText)findViewById(R.id.ipAddress);
port = (EditText)findViewById(R.id.portNumber);
addListenerOnSave();
}
public void addListenerOnSave() {
connectButton = (Button) findViewById(R.id.connectButton);
connectButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// takes values from user input
String holder1 = ip.getText().toString();
String holder2 = port.getText().toString();
Intent i = new Intent(getApplicationContext(), GeneralMode.class);
i.putExtra("first",holder1);
i.putExtra("second",holder2);
}
});
}
}
I have found the answer I was looking for a while ago.
I really wanted to be able to share variables across different activities instead of passing them to one another in a linear way, the solution to this is to use shared preferences.
Link: http://developer.android.com/reference/android/content/SharedPreferences.html
Shared Preferences allows you to save a value into an xml file, you can set your own permissions on which apps can access them e.g: private means that only the app that calls it may access the variables stored within. This allowed me to save the IP address, Port Number and mouse sensitivity settings on my app and allow them to be used in multiple activities e.g: sending URLs and sending mouse movements via the velocity tracker.
If you did want to send them linearly you can use the putExtra method or use Bundle: http://developer.android.com/reference/android/os/Bundle.html in order to send multiple values onto the next activity without saving it, in case you don't want to be saving every single semi important value.
My apologies for asking the question a little bit awkwardly, I was new to android at the time.