1

こんにちは、初めてのアプリをAndroid作成したばかりで、多くの問題が発生しています。Android

エラー メッセージが表示されLogcat、アプリが応答しません。以下に、私のManifestMainActivityおよびLogcat詳細を示します。

私を助けてください。

マニフェスト ファイル:

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="18" />

<uses-permission  android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission  android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET"/>

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.bijaru.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="com.example.bijaru.SettingsActivity"
        android:label="@string/title_activity_settings" >
    </activity>
    <activity
        android:name="com.example.bijaru.LoggedinActivity"
        android:label="@string/title_activity_loggedin" >
    </activity>
</application>

メイン アクティビティ ファイル:-

package com.example.bijaru;


    //importing of files
    public class MainActivity extends Activity {

    Button login;
    EditText username,password;
    TextView status;
    HttpPost httppost;
    StringBuffer stringbuffer;
    HttpResponse response;
    HttpClient client;
    List<NameValuePair> namevaluepair;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        addListenerOnButton();
    }


    private void addListenerOnButton() {
        // TODO Auto-generated method stub

        username=(EditText)findViewById(R.id.username);
        password=(EditText)findViewById(R.id.password);
        status=(TextView)findViewById(R.id.status);



        //final Context context = this;

        login = (Button) findViewById(R.id.login);

        login.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {

                switch (arg0.getId()){
                case R.id.login:
                login();
                break;
                }

              //  Intent intent = new Intent(context, LoggedinActivity.class);
                       //     startActivity(intent);   
            }

            private void login() {
                // TODO Auto-generated method stub
                try{

                    client = new DefaultHttpClient();
                    httppost=new HttpPost("http://127.0.0.1/bijaru/check.php");
                    namevaluepair = new ArrayList<NameValuePair>(1);
                    namevaluepair.add(new BasicNameValuePair("username", username.getText().toString().trim()));
                    namevaluepair.add(new BasicNameValuePair("password", password.getText().toString().trim()));
                    httppost.setEntity(new UrlEncodedFormEntity(namevaluepair));

                    response=client.execute(httppost);

                    ResponseHandler<String> responsehandler =new BasicResponseHandler();
                    final String response=client.execute(httppost,responsehandler);

                    status.setText(""+response);

                    if(response.equalsIgnoreCase("sucess"))
                    {

                        startActivity(new Intent(MainActivity.this,LoggedinActivity.class));
                    }

                }
                catch(Exception e)
                {
                    e.printStackTrace();

                }

            }

        });


    }


    @Override
      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;
     }

     }

エラー ログ カテゴリ:-

    08-07 07:09:36.341: E/cutils-trace(887): Error opening trace file: No such file or directory (2)
08-07 07:09:44.411: E/SoundPool(287): error loading /system/media/audio/ui/Effect_Tick.ogg
08-07 07:09:44.411: W/AudioService(287): Soundpool could not load file: /system/media/audio/ui/Effect_Tick.ogg
08-07 07:09:44.421: E/SoundPool(287): error loading /system/media/audio/ui/Effect_Tick.ogg
08-07 07:09:44.421: W/AudioService(287): Soundpool could not load file: /system/media/audio/ui/Effect_Tick.ogg
08-07 07:09:44.431: E/SoundPool(287): error loading /system/media/audio/ui/Effect_Tick.ogg
08-07 07:09:44.431: W/AudioService(287): Soundpool could not load file: /system/media/audio/ui/Effect_Tick.ogg
08-07 07:09:44.431: E/SoundPool(287): error loading /system/media/audio/ui/Effect_Tick.ogg
08-07 07:09:44.441: W/AudioService(287): Soundpool could not load file: /system/media/audio/ui/Effect_Tick.ogg
08-07 07:09:44.451: E/SoundPool(287): error loading /system/media/audio/ui/Effect_Tick.ogg
08-07 07:09:44.451: W/AudioService(287): Soundpool could not load file: /system/media/audio/ui/Effect_Tick.ogg
08-07 07:09:44.461: W/System.err(853): android.os.NetworkOnMainThreadException
08-07 07:09:44.471: E/SoundPool(287): error loading /system/media/audio/ui/KeypressStandard.ogg
08-07 07:09:44.471: W/AudioService(287): Soundpool could not load file: /system/media/audio/ui/KeypressStandard.ogg
08-07 07:09:44.471: E/SoundPool(287): error loading /system/media/audio/ui/KeypressSpacebar.ogg
08-07 07:09:44.481: W/AudioService(287): Soundpool could not load file: /system/media/audio/ui/KeypressSpacebar.ogg
08-07 07:09:44.491: E/SoundPool(287): error loading /system/media/audio/ui/KeypressDelete.ogg
08-07 07:09:44.491: W/AudioService(287): Soundpool could not load file: /system/media/audio/ui/KeypressDelete.ogg
08-07 07:09:44.501: W/System.err(853):  at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1133)
08-07 07:09:44.501: W/System.err(853):  at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:84)
08-07 07:09:44.501: W/System.err(853):  at libcore.io.IoBridge.connectErrno(IoBridge.java:127)
08-07 07:09:44.501: W/System.err(853):  at libcore.io.IoBridge.connect(IoBridge.java:112)
08-07 07:09:44.501: W/System.err(853):  at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
08-07 07:09:44.511: E/SoundPool(287): error loading /system/media/audio/ui/KeypressReturn.ogg
08-07 07:09:44.511: W/AudioService(287): Soundpool could not load file: /system/media/audio/ui/KeypressReturn.ogg
08-07 07:09:44.521: W/AudioService(287): onLoadSoundEffects(), Error -1 while loading samples
08-07 07:09:44.521: W/System.err(853):  at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:459)
08-07 07:09:44.521: W/System.err(853):  at java.net.Socket.connect(Socket.java:842)
08-07 07:09:44.521: W/System.err(853):  at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:119)
08-07 07:09:44.531: W/System.err(853):  at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:144)
08-07 07:09:44.531: W/System.err(853):  at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
08-07 07:09:44.541: W/System.err(853):  at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
08-07 07:09:44.541: W/System.err(853):  at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
08-07 07:09:44.541: W/System.err(853):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
08-07 07:09:44.541: W/System.err(853):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
08-07 07:09:44.551: W/System.err(853):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
08-07 07:09:44.551: W/System.err(853):  at com.example.bijaru.MainActivity$1.login(MainActivity.java:87)
08-07 07:09:44.551: W/System.err(853):  at com.example.bijaru.MainActivity$1.onClick(MainActivity.java:68)
08-07 07:09:44.551: W/System.err(853):  at android.view.View.performClick(View.java:4240)
08-07 07:09:44.561: W/System.err(853):  at android.view.View$PerformClick.run(View.java:17721)
08-07 07:09:44.561: W/System.err(853):  at android.os.Handler.handleCallback(Handler.java:730)
08-07 07:09:44.561: W/System.err(853):  at android.os.Handler.dispatchMessage(Handler.java:92)
08-07 07:09:44.571: W/System.err(853):  at android.os.Looper.loop(Looper.java:137)
08-07 07:09:44.571: W/System.err(853):  at android.app.ActivityThread.main(ActivityThread.java:5103)
08-07 07:09:44.581: W/System.err(853):  at java.lang.reflect.Method.invokeNative(Native Method)
08-07 07:09:44.581: W/System.err(853):  at java.lang.reflect.Method.invoke(Method.java:525)
08-07 07:09:44.581: W/System.err(853):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
08-07 07:09:44.581: W/System.err(853):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-07 07:09:44.581: W/System.err(853):  at dalvik.system.NativeStart.main(Native Method)

PHP コード:-

 <?php
  define("HOST", "localhost");
   // The host you want to connect to.
     define("USER", "admin");
  // The database username.
  define("PASSWORD", "admin");
  // The database password.
  define("DATABASE", "bijaru");
  // The database name.

  // Create connection
   $con = mysqli_connect(HOST, USER, PASSWORD, DATABASE);

  // Check connection
  if (mysqli_connect_errno($con)) {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
   }

  if (isset($_POST['login'])) {
  $username = $_POST['username'];
  $password = $_POST['password'];

    $str="SELECT * FROM users WHERE username='{$username}' and password='{$password}'";
  if ($result = mysqli_query($con, $str)) {
    // Return the number of rows in result set
    $rowcount = mysqli_num_rows($result);
if($rowcount !=0)
{
 echo "sucess";
}
else
{
echo "login failed";
}
}

else
{
echo "query fail";
}
 }
   ?>
  <!DOCTYPE html>
<html>
<body>
    <form method="post">
        Name:
        <input type="text" name="username">
        Password:
        <input type="password" name="password">
        <input type="submit" name="login">
    </form>

 </body>
</html>
4

2 に答える 2

2

UIスレッドでネットワーク呼び出しを行うことができない場合は、非同期クラスを使用するか、新しいスレッドを開始してそこでログインを行うことにより、ログインメソッドを新しいスレッドに移動する必要があります。

于 2013-08-07T08:56:05.563 に答える