views:

64

answers:

1

Hi all

I need help with server and I'm new with it. Got a help from my friend but still can't work. I can't login. There is no error so called 'detected' when running the application. I can't login. Somehow the connection wasn't properly established.

This is my java file open in eclipse;

package log1.log2;



import java.io.ObjectOutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Vector;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import java.io.ObjectInputStream;





public class Login extends Activity {


 DBAdapter db = new DBAdapter(this);
/** Called when the activity is first created. */

 private EditText etUsername;
 private EditText etPassword;
 private Button btnLogin;
 private Button btnRegister;
 private TextView lblResult;
 private String username;
 private String password;
 private String user;
 private String value;
 Vector SendVEctor = new Vector();
 Vector receiveVEctor = new Vector(); 

    @Override

    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);

        // Get the EditText and Button References
        etUsername = (EditText)findViewById(R.id.usernametxt);
        etPassword = (EditText)findViewById(R.id.passwordtxt);
        btnLogin = (Button)findViewById(R.id.btnLogin);
        btnRegister = (Button)findViewById(R.id.btnRegister);
        lblResult = (TextView)findViewById(R.id.msglbl);

        //Cursor c = (Cursor) db.getAllTitles();

        //Button btnArrival = (Button) findViewById(R.id.btnRegister);
     //btnArrival.setOnClickListener(this);


    // Set Click Listener

        btnRegister.setOnClickListener(new OnClickListener() {
         @Override
         public void onClick(View v) {
          Intent intent=new Intent(Login.this,Register.class);
            startActivity(intent);

         }
        });

    btnLogin.setOnClickListener(new OnClickListener() {
 @Override
 public void onClick(View v) 
 {


  String a = "http://172.27.32.251:9090/jsp-examples/ferryhub";
   URL url = null;
      HttpURLConnection httpurlconnection = null;
      try {
       url = new URL(a);
       httpurlconnection = (HttpURLConnection) url
         .openConnection();
       httpurlconnection.setDoOutput(true);
       httpurlconnection.setRequestMethod("POST");



      Toast.makeText(Login.this, a, Toast.LENGTH_SHORT).show();
       Toast.makeText(Login.this, "Toast1", Toast.LENGTH_SHORT).show();
       ObjectOutputStream dos = new ObjectOutputStream(httpurlconnection.getOutputStream());
       SendVEctor.add(etUsername.getText().toString());//foodname
       SendVEctor.add(etPassword.getText().toString());//foodname

       dos.writeObject(SendVEctor);

                 dos.close();


                 ObjectInputStream ois = new ObjectInputStream(httpurlconnection.getInputStream());

                 receiveVEctor = (Vector)ois.readObject();

       Toast.makeText(Login.this, receiveVEctor.get(0).toString(), Toast.LENGTH_SHORT).show();

       if(receiveVEctor.equals("Login Success"))
       { etUsername.setText("");
        etPassword.setText("");
         Toast.makeText(Login.this, receiveVEctor.get(0).toString(), Toast.LENGTH_SHORT).show();
        Intent myIntent = new Intent(((View) v).getContext(),Register.class);
     startActivityForResult(myIntent, 1);

       }//end inner if
       else if(receiveVEctor.equals("Login Fail"))
       { etUsername.setText("");
        etPassword.setText("");
         Toast.makeText(Login.this, receiveVEctor.get(0).toString(), Toast.LENGTH_SHORT).show();


       }//end inner if



       else
       {
        Toast.makeText(Login.this, "error", Toast.LENGTH_SHORT).show(); 
       }


      }//end try
      catch (Exception e) {
       e.printStackTrace();
       Toast.makeText(Login.this, "error2", Toast.LENGTH_SHORT).show();

      }//end catch 
      finally {
       if (httpurlconnection != null)
        httpurlconnection.disconnect();
      }//end finally
  }//end else






   });
 }

}

Everytime when I run my application, the toast will appear with the message error2 after showing http://172.27.32.251:9090/jsp-examples/ferryhub and toast1.

If I'm not wrong the problem is that there is no successful connection to the servlet. I hope to hear from good tips soon. Thank you for reading my question.

-Dayne


Hello again

I've run the program again without editing and check the logcat. I can't find any errors..

here's how it looks like:

08-24 07:52:37.875: INFO/NotificationService(54): enqueueToast pkg=log1.log2 callback=android.app.ITransientNotification$Stub$Proxy@43904308 duration=0
08-24 07:52:37.895: INFO/NotificationService(54): enqueueToast pkg=log1.log2 callback=android.app.ITransientNotification$Stub$Proxy@43925200 duration=0
08-24 07:52:37.945: WARN/System.err(216): java.net.SocketException: Permission denied (maybe missing INTERNET permission)
08-24 07:52:37.975: WARN/System.err(216):     at org.apache.harmony.luni.platform.OSNetworkSystem.createSocketImpl(Native Method)
08-24 07:52:37.975: WARN/System.err(216):     at org.apache.harmony.luni.platform.OSNetworkSystem.createSocket(OSNetworkSystem.java:85)
08-24 07:52:37.975: WARN/System.err(216):     at org.apache.harmony.luni.net.PlainSocketImpl2.create(PlainSocketImpl2.java:59)
08-24 07:52:37.975: WARN/System.err(216):     at java.net.Socket.checkClosedAndCreate(Socket.java:829)
08-24 07:52:37.975: WARN/System.err(216):     at java.net.Socket.connect(Socket.java:984)
08-24 07:52:37.975: WARN/System.err(216):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:67)
08-24 07:52:37.975: WARN/System.err(216):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionManager$ConnectionPool.getHttpConnection(HttpConnectionManager.java:151)
08-24 07:52:37.975: WARN/System.err(216):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionManager.getConnection(HttpConnectionManager.java:73)
08-24 07:52:37.975: WARN/System.err(216):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.getHTTPConnection(HttpURLConnection.java:826)
08-24 07:52:37.975: WARN/System.err(216):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:812)
08-24 07:52:37.975: WARN/System.err(216):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1153)
08-24 07:52:37.984: WARN/System.err(216):     at log1.log2.Login$2.onClick(Login.java:95)
08-24 07:52:37.984: WARN/System.err(216):     at android.view.View.performClick(View.java:2344)
08-24 07:52:37.984: WARN/System.err(216):     at android.view.View.onKeyUp(View.java:3939)
08-24 07:52:37.984: WARN/System.err(216):     at android.widget.TextView.onKeyUp(TextView.java:4413)
08-24 07:52:37.984: WARN/System.err(216):     at android.view.KeyEvent.dispatch(KeyEvent.java:895)
08-24 07:52:37.984: WARN/System.err(216):     at android.view.View.dispatchKeyEvent(View.java:3647)
08-24 07:52:37.984: WARN/System.err(216):     at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:746)
08-24 07:52:37.984: WARN/System.err(216):     at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:746)
08-24 07:52:37.984: WARN/System.err(216):     at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:746)
08-24 07:52:37.984: WARN/System.err(216):     at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:746)
08-24 07:52:37.984: WARN/System.err(216):     at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchKeyEvent(PhoneWindow.java:1708)
08-24 07:52:37.984: WARN/System.err(216):     at com.android.internal.policy.impl.PhoneWindow.superDispatchKeyEvent(PhoneWindow.java:1197)
08-24 07:52:37.994: WARN/System.err(216):     at android.app.Activity.dispatchKeyEvent(Activity.java:1967)
08-24 07:52:37.994: WARN/System.err(216):     at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1684)
08-24 07:52:37.994: WARN/System.err(216):     at android.view.ViewRoot.deliverKeyEventToViewHierarchy(ViewRoot.java:2329)
08-24 07:52:37.994: WARN/System.err(216):     at android.view.ViewRoot.handleFinishedEvent(ViewRoot.java:2299)
08-24 07:52:37.994: WARN/System.err(216):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1621)
08-24 07:52:37.994: WARN/System.err(216):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-24 07:52:37.994: WARN/System.err(216):     at android.os.Looper.loop(Looper.java:123)
08-24 07:52:37.994: WARN/System.err(216):     at android.app.ActivityThread.main(ActivityThread.java:4203)
08-24 07:52:37.994: WARN/System.err(216):     at java.lang.reflect.Method.invokeNative(Native Method)
08-24 07:52:37.994: WARN/System.err(216):     at java.lang.reflect.Method.invoke(Method.java:521)
08-24 07:52:37.994: WARN/System.err(216):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
08-24 07:52:37.994: WARN/System.err(216):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
08-24 07:52:37.994: WARN/System.err(216):     at dalvik.system.NativeStart.main(Native Method)
08-24 07:52:38.004: INFO/NotificationService(54): enqueueToast pkg=log1.log2 callback=android.app.ITransientNotification$Stub$Proxy@438ad2c8 duration=0
08-24 07:52:38.206: INFO/ARMAssembler(54): generated scanline__00000077:03515104_00001A01_00000000 [ 46 ipp] (68 ins) at [0x2ac120:0x2ac230] in 1976229 ns

I hope you can point out the actual error and tell me what I should do.

Thank you for reading my post.

-Dayne


Hi again

As for the internet permission statement, I did at that line in my manifest xml file. I insert it under login activity as shown below:

<activity android:name="Login">
            <intent-filter>
                <action android:name="android.intent.action.EDIT" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <uses-permission android:name="android.permission.INTERNET"/>
         <activity android:name="AdminMain">
            <intent-filter>
                <action android:name="android.intent.action.EDIT" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>

Is there any other possible things that I might missed? I hope you have a thing or two to tell me. Thank you.

-Dayne

A: 

It's all there:

java.net.SocketException: Permission denied (maybe missing INTERNET permission)

Check this page: http://developer.android.com/reference/android/Manifest.permission.html

You need to add "android.permission.INTERNET" to your manifest.xml-file, the whole line should look this this <uses-permission android:name="android.permission.INTERNET" />.

Select0r
Hi I've already insert the internet permission statement in the manifest. Any other ideas why still can't work?
Dayne
Not right now, but I wonder why you keep getting a "permission" error - are you sure that the service you're sending the POST to isn't returning that?
Select0r
are you saying that it's because of the internet service provider? At first thats what it seems to be because I was using the campus's internet. But thats not the case since even at home using my own internet, im still having that problem.
Dayne
Have you tried monitoring your traffic with something like Wireshark to really find out what's going in/out and what not? Also, your permission should be inside your <manifest>-node, check this page: http://developer.android.com/guide/topics/manifest/manifest-intro.html
Select0r
i've already added <uses-permission android:name ="android.permission.INTERNET"/> under my activity.
Dayne
"Under activity" is inside the node "application" not inside "manifest", I don't know if that's the cause, but I'd try (see the link I posted above about how to structure the manifest). If that doesn't help, monitor the network ...
Select0r
yes, it helps. thank you!
Dayne