[gelöst] Problem mit JSON - (java.lang.NullPointerException: lock == null) Was mache ich falsch?

  • Antworten:14
  • Bentwortet
Peter Staudigel
  • Forum-Beiträge: 20

28.04.2015, 00:24:31 via Website

Hallo, ich brauche unbedingt Hilfe....
komme einfach nicht weiter, ich mach zur zeit meine 1. Erfahrungen mit der Appenticklung also erwartet a besten nichts ^^

Eigentlich bin ich schon ziehmlich weit gewesen mit meiner App bis dann nach einer Änderung immer ein Problemm mit dem JSONParser aufgetreten ist.

erstmal der Logcat:

04-27 21:52:03.215 1863-1948/com.example.mysqltest E/Buffer Error﹕ Error converting result java.lang.NullPointerException: lock == null
04-27 21:52:03.215 1863-1948/com.example.mysqltest E/JSON Parser﹕ Error parsing data org.json.JSONException: End of input at character 0 of
--------- beginning of crash
04-27 21:52:03.216 1863-1948/com.example.mysqltest E/AndroidRuntime﹕ FATAL EXCEPTION: AsyncTask #2
Process: com.example.mysqltest, PID: 1863
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:300)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String org.json.JSONObject.toString()' on a null object reference
at com.example.mysqltest.Login$AttemptLogin.doInBackground(Login.java:125)
at com.example.mysqltest.Login$AttemptLogin.doInBackground(Login.java:94)
at android.os.AsyncTask$2.call(AsyncTask.java:288)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
            at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
            at java.lang.Thread.run(Thread.java:818)
04-27 21:52:04.984 1863-1863/com.example.mysqltest E/WindowManager﹕ android.view.WindowLeaked: Activity com.example.mysqltest.Login has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{e95d269 V.E..... R......D 0,0-1026,288} that was originally added here
at android.view.ViewRootImpl.(ViewRootImpl.java:363)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:261)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
at android.app.Dialog.show(Dialog.java:298)
at com.example.mysqltest.Login$AttemptLogin.onPreExecute(Login.java:103)
at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:587)
at android.os.AsyncTask.execute(AsyncTask.java:535)
at com.example.mysqltest.Login.onClick(Login.java:82)
at android.view.View.performClick(View.java:4756)
at android.view.View$PerformClick.run(View.java:19749)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

JSONParser.java:

public class JSONParser {

static InputStream is = null;
static JSONObject jObj = null;
static String json = "";

// constructor
public JSONParser() {

}


public JSONObject getJSONFromUrl(final String url) {

    // Making HTTP request
    try {
        // Construct the client and the HTTP request.
        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpPost httpPost = new HttpPost(url);

        // Execute the POST request and store the response locally.
        HttpResponse httpResponse = httpClient.execute(httpPost);
        // Extract data from the response.
        HttpEntity httpEntity = httpResponse.getEntity();
        // Open an inputStream with the data content.
        is = httpEntity.getContent();

    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    try {
        // Create a BufferedReader to parse through the inputStream.
        BufferedReader reader = new BufferedReader(new InputStreamReader(
                is, "iso-8859-1"), 8);
        // Declare a string builder to help with the parsing.
        StringBuilder sb = new StringBuilder();
        // Declare a string to store the JSON object data in string form.
        String line = null;

        // Build the string until null.
        while ((line = reader.readLine()) != null) {
            sb.append(line + "\n");
        }

        // Close the input stream.
        is.close();
        // Convert the string builder data to an actual string.
        json = sb.toString();
    } catch (Exception e) {
        Log.e("Buffer Error", "Error converting result " + e.toString());
    }

    // Try to parse the string to a JSON object
    try {
        jObj = new JSONObject(json);
    } catch (JSONException e) {
        Log.e("JSON Parser", "Error parsing data " + e.toString());
    }

    // Return the JSON Object.
    return jObj;

}


// function get json from url
// by making HTTP POST or GET mehtod
public JSONObject makeHttpRequest(String url, String method,
        List<NameValuePair> params) {
    // Making HTTP request
    try {

        // check for request method
        if(method == "POST"){
            // request method is POST
            // defaultHttpClient
            DefaultHttpClient httpClient = new DefaultHttpClient();
            HttpPost httpPost = new HttpPost(url);
            httpPost.setEntity(new UrlEncodedFormEntity(params));
            HttpResponse httpResponse = httpClient.execute(httpPost);
            HttpEntity httpEntity = httpResponse.getEntity();
            is = httpEntity.getContent();
        }else if(method == "GET"){
            // request method is GET
            DefaultHttpClient httpClient = new DefaultHttpClient();
            String paramString = URLEncodedUtils.format(params, "utf-8");
            url += "?" + paramString;
            HttpGet httpGet = new HttpGet(url);

            HttpResponse httpResponse = httpClient.execute(httpGet);
            HttpEntity httpEntity = httpResponse.getEntity();
            is = httpEntity.getContent();
        }           

    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    try {
        BufferedReader reader = new BufferedReader(new InputStreamReader(
                is, "iso-8859-1"), 8);
        StringBuilder sb = new StringBuilder();
        String line = null;
        while ((line = reader.readLine()) != null) {
            sb.append(line + "\n");
        }
        is.close();
        json = sb.toString();
    } catch (Exception e) {
        Log.e("Buffer Error", "Error converting result " + e.toString());
    }

    // try parse the string to a JSON object
    try {
        jObj = new JSONObject(json);
    } catch (JSONException e) {
        Log.e("JSON Parser", "Error parsing data " + e.toString());
    }
    // return JSON String
    return jObj;

}

}

Login.Java:

public class Login extends Activity implements OnClickListener {

private EditText user, pass;
private Button mSubmit, mRegister;


// testing on Emulator:
private static final String LOGIN_URL = "kann ich als neues itglied leider nicht stehen lassen";


// JSON element ids from repsonse of php script:
private static final String TAG_SUCCESS = "success";
private static final String TAG_MESSAGE = "message";

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.login);

    // setup input fields
    user = (EditText) findViewById(R.id.username);
    pass = (EditText) findViewById(R.id.password);

    // setup buttons
    mSubmit = (Button) findViewById(R.id.login);
    mRegister = (Button) findViewById(R.id.register);

    // register listeners
    mSubmit.setOnClickListener(this);
    mRegister.setOnClickListener(this);

}

@Override
public void onClick(View v) {
    // TODO Auto-generated method stub
    switch (v.getId()) {
    case R.id.login:
        new AttemptLogin().execute();
        break;
    case R.id.register:
        Intent i = new Intent(this, Register.class);
        startActivity(i);
        break;

    default:
        break;
    }
}

class AttemptLogin extends AsyncTask<String, String, String> {

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        pDialog = new ProgressDialog(Login.this);
        pDialog.setMessage("Attempting login...");
        pDialog.setIndeterminate(false);
        pDialog.setCancelable(true);
        pDialog.show();
    }

    @Override
    protected String doInBackground(String... args) {
        // TODO Auto-generated method stub
        // Check for success tag
        int success;
        String username = user.getText().toString();
        String password = pass.getText().toString();
        try {
            // Building Parameters
            List<NameValuePair> params = new ArrayList<NameValuePair>();
            params.add(new BasicNameValuePair("username", username));
            params.add(new BasicNameValuePair("password", password));

            Log.d("request!", "starting");
            // getting product details by making HTTP request
            JSONObject json = jsonParser.makeHttpRequest(LOGIN_URL, "POST",
                    params);

            // check your log for json response
            Log.d("Login attempt", json.toString());

            // json success tag
            success = json.getInt(TAG_SUCCESS);
            if (success == 1) {
                Log.d("Login Successful!", json.toString());
                // save user data
                SharedPreferences sp = PreferenceManager
                        .getDefaultSharedPreferences(Login.this);
                Editor edit = sp.edit();
                edit.putString("username", username);
                edit.commit();

                Intent i = new Intent(Login.this, ReadComments.class);
                finish();
                startActivity(i);
                return json.getString(TAG_MESSAGE);
            } else {
                Log.d("Login Failure!", json.getString(TAG_MESSAGE));
                return json.getString(TAG_MESSAGE);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }

        return null;

    }

    protected void onPostExecute(String file_url) {
        // dismiss the dialog once product deleted
        pDialog.dismiss();
        if (file_url != null) {
            Toast.makeText(Login.this, file_url, Toast.LENGTH_LONG).show();
        }

    }

}

}

Login.php

<?php

//load and connect to MySQL database stuff
require("config.inc.php");
$login_ok = FALSE;
if (!empty($_POST)) {
//gets user's info based off of a username.
$query = "
SELECT
id,
username,
password
FROM users
WHERE
username = :username
";

$query_params = array(
    ':username' => $_POST['username']
);

try {
    $stmt   = $db->prepare($query);
    $result = $stmt->execute($query_params);
}
catch (PDOException $ex) {
    // For testing, you could use a die and message. 
    //die("Failed to run query: " . $ex->getMessage());

    //or just use this use this one to product JSON data:
    $response["success"] = 0;
    $response["message"] = "Database Error1. Please Try Again!";
    die(json_encode($response));

}

//This will be the variable to determine whether or not the user's information is correct.
//we initialize it as false.
$validated_info = false;

//fetching all the rows from the query
$row = $stmt->fetch();
if ($row) {
    //if we encrypted the password, we would unencrypt it here, but in our case we just
    //compare the two passwords
    if ($_POST['password'] === $row['password']) {
        $login_ok = true;
    }
}

// If the user logged in successfully, then we send them to the private members-only page 
// Otherwise, we display a login failed message and show the login form again 
if ($login_ok) {
    $response["success"] = 1;
    $response["message"] = "Login successful!";
    die(json_encode($response));
} else {
    $response["success"] = 0;
    $response["message"] = "Invalid Credentials!";
    die(json_encode($response));
}

} else {
?>

Login



Username:





Password:







Register
}

?>

wenn ihr noch was brauch meldet euch. hoffe ihr könnt mir irgendwie helfen und vielleich nen weng was bei bringen.
Bei dem JSON-Zeug blick ich erlich gesagt auch nicht wirklich durch und habe das nur aus einem Tuturial übernommen...

und hat auch sehr gut Funktioniert.
Habe sogar aus Verzwweiflung das Tuturial-Projekt nochmal komplett gemacht und da hab ich genau den selben Fehler.

— geändert am 28.04.2015, 18:56:57

Antworten
Ludy
  • Admin
  • Forum-Beiträge: 7.960

28.04.2015, 05:32:41 via Website

Hallo Peter,

Herzlich willkommen bei uns im Entwickler Forum (*)

Bitte beachte, dass Threads mit nicht aussagekräftigem Titel bei uns üblicherweise den Regeln entsprechend entfernt werden. Ich bitte dich daher, deinen Threadtitel innerhalb der nächsten 24 Stunden, spätestens jedoch bei deinem nächsten Besuch noch etwas aussagekräftiger zu gestalten (Hierfür einfach unter deinem ersten Beitrag auf 'bearbeiten' klicken, dann kannst du oben noch mal den Titel anpassen)

Danke :-)

Gruß Ludy (App Entwickler)

Mein Beitrag hat dir geholfen? Lass doch ein "Danke" da.☺

☕ Buy Me A Coffee ☕

Lebensmittelwarnung-App

✨Meine Wunschliste✨

📲Telegram NextPit News📲

Antworten
Peter Staudigel
  • Forum-Beiträge: 20

28.04.2015, 06:42:59 via Website

Hoffe das es so besser ist, leider habe ich keine Idee wie ich das benennen soll.
Weil ich halt nicht ei was das Problem sein soll da alles mal ging und ich daran nichts geändert hatte...

aber danke für den Hinweis

Antworten
Sven R.
  • Forum-Beiträge: 1.904

28.04.2015, 07:07:56 via App

Also ich habe im LogCat geschätzt drei Fehlermeldungen gefunden. Eine davon ist die hier:

Peter Staudigel

[...] Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String org.json.JSONObject.toString()' on a null object reference
        at com.example.mysqltest.Login$AttemptLogin.doInBackground(Login.java:125) [...]

Was steht denn in Zeile 125 in der Login.java?

Außerdem sagt er, dass der Input zum Parsen 0 Zeichen lang ist. Ist das so? Gib den String zum Parsen mal im LogCat aus.

— geändert am 28.04.2015, 07:10:02

Wenn dir mein Beitrag gefällt, kannst dich einfach mit dem 👍 "Danke"-Button auf der Website dieses Forums bedanken. 😀

Why Java? - Because I can't C#

Antworten
Ludy
  • Admin
  • Forum-Beiträge: 7.960

28.04.2015, 08:05:41 via App

Peter Staudigel

Hoffe das es so besser ist, leider habe ich keine Idee wie ich das benennen soll.

So ist schon okay, so finden User die das gleich Probleme haben mit json object eine schnellere Hilfe.

Gruß Ludy (App Entwickler)

Mein Beitrag hat dir geholfen? Lass doch ein "Danke" da.☺

☕ Buy Me A Coffee ☕

Lebensmittelwarnung-App

✨Meine Wunschliste✨

📲Telegram NextPit News📲

Antworten
Peter Staudigel
  • Forum-Beiträge: 20

28.04.2015, 17:50:34 via Website

also: in Zeile 125 steht "Log.d("Login attempt", json.toString());"
der string sollte eigentlich nicht 0 Zeichen lang sein....

also habe raus gefunden wo das Problem in etwa liegt:

 Log.e("JSON Parser1", "step1");
            DefaultHttpClient httpClient = new DefaultHttpClient();

            Log.e("JSON Parser1", "step2"+ httpClient);
            HttpPost httpPost = new HttpPost(url);

            Log.e("JSON Parser1", "step3" + httpPost);
            httpPost.setEntity(new UrlEncodedFormEntity(params));

            Log.e("JSON Parser1", "step4" +  httpPost);
            HttpResponse httpResponse = httpClient.execute(httpPost);

            Log.e("JSON Parser1", "httpResponse " + httpResponse);
            HttpEntity httpEntity = httpResponse.getEntity();

            Log.e("JSON Parser1", "httpEntity " + httpEntity);
            is = httpEntity.getContent();

            Log.e("JSON Parser1", "is " + is);

nach step4 springt er in catch... (JSON Parser﹕ is3)

04-28 15:37:24.373    3026-3047/com.example.mysqltest E/JSON Parser1﹕ step1

04-28 15:37:24.373 3026-3047/com.example.mysqltest E/JSON Parser1﹕ step2org.apache.http.impl.client.DefaultHttpClient@25b49afa
04-28 15:37:24.373 3026-3047/com.example.mysqltest E/JSON Parser1﹕ step3org.apache.http.client.methods.HttpPost@2c7a58ab
04-28 15:37:24.378 3026-3047/com.example.mysqltest E/JSON Parser1﹕ step4org.apache.http.client.methods.HttpPost@2c7a58ab
04-28 15:37:24.456 3026-3045/com.example.mysqltest W/EGL_emulation﹕ eglSurfaceAttrib not implemented
04-28 15:37:24.456 3026-3045/com.example.mysqltest W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xa6840b00, error=EGL_SUCCESS
04-28 15:37:24.609 3026-3047/com.example.mysqltest E/JSON Parser﹕ is3

Hilft das so weiter?

Antworten
Sven R.
  • Forum-Beiträge: 1.904

28.04.2015, 17:58:36 via Website

Der Input-String fürs JsonObject wird 0 Zeichen lang sein, weil der Post(und damit auch die Response) nicht funktioniert. Ich habe mich noch nicht so mit Post und Get beschäftigt, darum erkenne ich jetzt nicht viel am Code. Ist in dem Catch-Block eine e.printStackTrace() drin? Wenn nicht, mach das mal rein und dann schick nochmal den LogCat, aber den Teil mit ".. Caused by ..." und alle Zeilenangaben und die erste Zeilenangabe mit Code(und dem Code drumrum).

Wenn dir mein Beitrag gefällt, kannst dich einfach mit dem 👍 "Danke"-Button auf der Website dieses Forums bedanken. 😀

Why Java? - Because I can't C#

Antworten
Peter Staudigel
  • Forum-Beiträge: 20

28.04.2015, 18:13:45 via Website

jup ist drinne:

LogCat:
04-28 15:37:24.609 3026-3047/com.example.mysqltest W/System.err﹕ org.apache.http.conn.HttpHostConnectException: Connection to http___localhost refused
04-28 15:37:24.610 3026-3047/com.example.mysqltest W/System.err﹕ at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:183)
04-28 15:37:24.610 3026-3047/com.example.mysqltest W/System.err﹕ at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
04-28 15:37:24.610 3026-3047/com.example.mysqltest W/System.err﹕ at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
04-28 15:37:24.610 3026-3047/com.example.mysqltest W/System.err﹕ at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
04-28 15:37:24.610 3026-3047/com.example.mysqltest W/System.err﹕ at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
04-28 15:37:24.610 3026-3047/com.example.mysqltest W/System.err﹕ at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
04-28 15:37:24.610 3026-3047/com.example.mysqltest W/System.err﹕ at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
04-28 15:37:24.610 3026-3047/com.example.mysqltest W/System.err﹕ at com.example.mysqltest.JSONParser.makeHttpRequest(JSONParser.java:120)
04-28 15:37:24.610 3026-3047/com.example.mysqltest W/System.err﹕ at com.example.mysqltest.Login$AttemptLogin.doInBackground(Login.java:121)
04-28 15:37:24.610 3026-3047/com.example.mysqltest W/System.err﹕ at com.example.mysqltest.Login$AttemptLogin.doInBackground(Login.java:94)
04-28 15:37:24.610 3026-3047/com.example.mysqltest W/System.err﹕ at android.os.AsyncTask$2.call(AsyncTask.java:288)
04-28 15:37:24.610 3026-3047/com.example.mysqltest W/System.err﹕ at java.util.concurrent.FutureTask.run(FutureTask.java:237)
04-28 15:37:24.610 3026-3047/com.example.mysqltest W/System.err﹕ at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
04-28 15:37:24.611 3026-3047/com.example.mysqltest W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
04-28 15:37:24.611 3026-3047/com.example.mysqltest W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
04-28 15:37:24.611 3026-3047/com.example.mysqltest W/System.err﹕ at java.lang.Thread.run(Thread.java:818)
04-28 15:37:24.611 3026-3047/com.example.mysqltest W/System.err﹕ Caused by: java.net.ConnectException: failed to connect to /127.0.0.1 (port 80): connect failed: ECONNREFUSED (Connection refused)
04-28 15:37:24.611 3026-3047/com.example.mysqltest W/System.err﹕ at libcore.io.IoBridge.connect(IoBridge.java:124)
04-28 15:37:24.611 3026-3047/com.example.mysqltest W/System.err﹕ at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:183)
04-28 15:37:24.611 3026-3047/com.example.mysqltest W/System.err﹕ at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:456)
04-28 15:37:24.611 3026-3047/com.example.mysqltest W/System.err﹕ at java.net.Socket.connect(Socket.java:882)
04-28 15:37:24.611 3026-3047/com.example.mysqltest W/System.err﹕ at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:119)
04-28 15:37:24.611 3026-3047/com.example.mysqltest W/System.err﹕ at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:144)
04-28 15:37:24.611 3026-3047/com.example.mysqltest W/System.err﹕ ... 15 more
04-28 15:37:24.611 3026-3047/com.example.mysqltest W/System.err﹕ Caused by: android.system.ErrnoException: connect failed: ECONNREFUSED (Connection refused)
04-28 15:37:24.611 3026-3047/com.example.mysqltest W/System.err﹕ at libcore.io.Posix.connect(Native Method)
04-28 15:37:24.611 3026-3047/com.example.mysqltest W/System.err﹕ at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:111)
04-28 15:37:24.612 3026-3047/com.example.mysqltest W/System.err﹕ at libcore.io.IoBridge.connectErrno(IoBridge.java:137)
04-28 15:37:24.612 3026-3047/com.example.mysqltest W/System.err﹕ at libcore.io.IoBridge.connect(IoBridge.java:122)
04-28 15:37:24.612 3026-3047/com.example.mysqltest W/System.err﹕ ... 20 more

Dazugehöriger Javateil:

// Making HTTP request
    try {

        // check for request method
        if(method == "POST"){
            // request method is POST
            // defaultHttpClient

            Log.e("JSON Parser1", "step1");
            DefaultHttpClient httpClient = new DefaultHttpClient();

            Log.e("JSON Parser1", "step2"+ httpClient);
            HttpPost httpPost = new HttpPost(url);

            Log.e("JSON Parser1", "step3" + httpPost);
            httpPost.setEntity(new UrlEncodedFormEntity(params));

            Log.e("JSON Parser1", "step4" +  httpPost);
            HttpResponse httpResponse = httpClient.execute(httpPost);

            Log.e("JSON Parser1", "httpResponse " + httpResponse);
            HttpEntity httpEntity = httpResponse.getEntity();

            Log.e("JSON Parser1", "httpEntity " + httpEntity);
            is = httpEntity.getContent();

            Log.e("JSON Parser1", "is " + is);

        }else if(method == "GET"){
            // request method is GET
            DefaultHttpClient httpClient = new DefaultHttpClient();
            String paramString = URLEncodedUtils.format(params, "utf-8");
            url += "?" + paramString;
            HttpGet httpGet = new HttpGet(url);

            HttpResponse httpResponse = httpClient.execute(httpGet);

            Log.e("JSON Parser", "httpResponse " + httpResponse);
            Log.e("JSON Parser", "httpResponse.tostr " + httpResponse.toString());
            HttpEntity httpEntity = httpResponse.getEntity();

            Log.e("JSON Parser", "httpEntity " + httpEntity);
            Log.e("JSON Parser", "httpEntity.tostr " + httpEntity.toString());
            is = httpEntity.getContent();

            Log.e("JSON Parser", "is " + is);
            Log.e("JSON Parser", "is.tostr " + is.toString());
        }

    } catch (UnsupportedEncodingException e) {
        Log.e("JSON Parser", "is1");
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        Log.e("JSON Parser", "is2");
        e.printStackTrace();
    } catch (IOException e) {
        Log.e("JSON Parser", "is3");
        e.printStackTrace();
    }

Antworten
Peter Staudigel
  • Forum-Beiträge: 20

28.04.2015, 18:51:46 via Website

ich hab das proble gefunden.....
endlich ey

also:
1. hat irgendwie auf einmal der emulator das problem das er über die url localhost nicht mehr verbinden kann
(obohl ich es die ganze zeit so gemacht habe!)

  1. wichtig ist auch wenn man mit xamp arbeiter nicht die ip von xamp zu nehmen sondern die vom pc!
    Beispielteil1 "http:"
    Beispielteil2 "//146.0.0.2/Website/login.php"
    (leider darf ich keine Links posten)
    Welche ip man hat findet man: CMD öffnen und "ipconfig" eingeben, dort nach "ipv4-Adresse" suchen

  2. auch wichtig soll sein in Manifest.xml den code einzufügen:

    uses-permission android:name="android.permission.INTERNET"

(war bei mir schon drinne, größer und kleinerals noch davor und dahinter mit backslash)

danke für eure hilfe! :D:D

— geändert am 28.04.2015, 18:54:56

Antworten
Sven R.
  • Forum-Beiträge: 1.904

29.04.2015, 07:17:47 via App

Immerhin lag ich richtig, dass der Input 0 Zeichen lang ist. Das hätte eigentlich die Fehlersuche schon erleichert.

Wenn dir mein Beitrag gefällt, kannst dich einfach mit dem 👍 "Danke"-Button auf der Website dieses Forums bedanken. 😀

Why Java? - Because I can't C#

Antworten
Peter Staudigel
  • Forum-Beiträge: 20

29.04.2015, 17:23:45 via Website

ja hat es auch, dadurch bin ich mit zur lösung gekommen.

danke nochmals

Antworten
Sven R.
  • Forum-Beiträge: 1.904

29.04.2015, 18:06:58 via Website

Achso, bitte :)

Wenn dir mein Beitrag gefällt, kannst dich einfach mit dem 👍 "Danke"-Button auf der Website dieses Forums bedanken. 😀

Why Java? - Because I can't C#

Antworten
Jasko Del
  • Forum-Beiträge: 11

24.08.2015, 15:14:38 via Website

Hallo Peter,

du hast wahrscheinlich das Turtorial von Mybringback nachgeschrieben ?

Ich bin gerade bei dem selben Problem wie du nur ist mir jetzt nicht ganz ersichtlich was du zur Lösung beigetragen hast ?

Musstes du etwas am Code ändern oder hat es nur an deiner IP gelegen ?

Außerdem wird bei mir hier:
try {
List parameter = new ArrayList();
parameter.add(new BasicNameValuePair("username", username));
parameter.add(new BasicNameValuePair("password", passwort));

NameValuePair und BasicNameValuePair durchgestrichen angezeigt und ich weiß nicht woher das kommt. ?

Freue mich über deine Antwort.

Gru´ß
Jasko

— geändert am 24.08.2015, 16:03:46

Antworten
Peter Staudigel
  • Forum-Beiträge: 20

30.08.2015, 18:58:35 via Website

also ja bei mir lag es nur an der ip bzw das ich davor nur über localhost gegangen bin...

dann ging das plötzlich nicht mehr. und mit ip gings dann ohne probleme :)

das it deinem "NameValuePair und BasicNameValuePair" kann ich so nichs zu sagen...
mach am besten ein thread auf enn du irklich nicht eiter kommst.

ich nehme mal an eingebunden hast du es?

import org.apache.http.NameValuePair;

Antworten
Jasko Del
  • Forum-Beiträge: 11

31.08.2015, 11:58:29 via Website

Danke für das Antworten hat sich aber bei mir auch schon geklärt. Es lag an der IP
und wegen dem NameValuePair liegt es an der target API.

Danke

Peter Staudigel

Antworten