2013-08-07 57 views
1

嗨,我是新的Android我刚刚创建了我的第一个Android应用程序,并且遇到了很多问题。在错误Logcat中获取错误消息,应用程序没有响应

我在我的Logcat中收到了一些错误消息,我的应用没有回应。以下是我的ManifestMainActivityLogcat的详细信息。

请帮我一把。

清单文件:

<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> 
+0

您在模拟器或真实设备测试。告诉我的Android AVD或设备的版本 –

+0

我在模拟器和API级别测试他们是18 – Harshit

+0

使用10.0.2.2而不是127.0.0.1 –

回答

2

你不能让你需要登录方法,通过或者使用移动到一个新的线程的UI线程网呼叫Async Class或刚刚开始一个新的线程,做在那里登录。

0

u需要IP地址是。你不写本地主机

ü下面的代码:

String url="http://192.168.0.0/"; //use ur computer or server ip address write 
    httppost=new HttpPost("bijaru/check.php"); 



ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); 

       nameValuePairs.add(new BasicNameValuePair("image",image_str)); 
       nameValuePairs.add(new BasicNameValuePair("mobile_id",username)); 
       nameValuePairs.add(new BasicNameValuePair("name",name1)); 
       nameValuePairs.add(new BasicNameValuePair("city",city1)); 
       nameValuePairs.add(new BasicNameValuePair("emailid",emailid)); 
       nameValuePairs.add(new BasicNameValuePair("username",username)); 
       nameValuePairs.add(new BasicNameValuePair("password",password)); 
       nameValuePairs.add(new BasicNameValuePair("birthdate",bd)); 
       nameValuePairs.add(new BasicNameValuePair("country",country)); 
       nameValuePairs.add(new BasicNameValuePair("state",state)); 
       nameValuePairs.add(new BasicNameValuePair("gender",gender)); 
       try{ 
        HttpClient httpclient = new DefaultHttpClient(); 
        HttpPost httppost = new HttpPost(mainurl+"upload_image.php"); 
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); 
        HttpResponse response = httpclient.execute(httppost); 
       // String the_string_response = convertResponseToString(response); 
       // Toast.makeText(getApplicationContext(), "Response " + the_string_response, Toast.LENGTH_LONG).show(); 
       }catch(Exception e){ 
         Toast.makeText(getApplicationContext(), "ERROR " + e.getMessage(), Toast.LENGTH_LONG).show(); 
        // System.out.println("Error in http connection "+e.toString()); 
       } 
+0

即使我这样做...但仍然不工作 – Harshit

+0

然后发布你的错误catlog –

+0

互联网许可写入清单文件 –

相关问题