2016-06-14 31 views
1

我正在Eclipse ADT Bundle中创建Android应用程序。当单击按钮应用程序连接Web服务并获取位置值在app.I中启动应用程序在模拟器中,而我收到“unfourunately项目名称已停止“警告。我正在检查logcat.But我没有解决问题。我正在分享logcat错误。请问你能帮帮我吗。安卓尚未幸运项目已停止错误

主要活动:

public class MainActivity extends Activity { 
    public final static String URL = "http://10.0.2.2:8081/WebService/services/SqlService.SqlServiceHttpSoap11Endpoint/"; 
    public static final String NAMESPACE = "http://services.com"; 
    public static final String SOAP_ACTION= "http://services.com/locationData"; 
    private static final String METHOD_NAME = "locationData"; 

    String str = null; 
    TextView t; 
    String longitude; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     if (android.os.Build.VERSION.SDK_INT > 9) { 
      StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); 
      StrictMode.setThreadPolicy(policy); 
      } 
     t = (TextView) findViewById(R.id.textView1); 



     SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 
     request.addProperty("message","Hello"); 

     SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
     envelope.dotNet=true; 
     envelope.setOutputSoapObject(request); 

     HttpTransportSE androidHttpTransport = new HttpTransportSE(URL); 
     try { 
      androidHttpTransport.call(SOAP_ACTION, envelope); 
     } catch (HttpResponseException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } catch (IOException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } catch (XmlPullParserException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 

     SoapPrimitive result; 
     try { 
      result = (SoapPrimitive)envelope.getResponse(); 
      String strRes = result.toString(); 
      String resultArr[] = strRes.split("&"); 
      longitude = resultArr[0]; 
      t.setText(resultArr[0]); 
     } catch (SoapFault e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 


    } 
    public void sendLocation(View v){ 
     Intent intent = new Intent(MainActivity.this,MappingActivity.class); 
     intent.putExtra("longitude",longitude); 
     startActivity(intent); 
    } 
} 

main.xml中:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context="com.example.abc.MainActivity" 
    android:background="@drawable/background1"> 

    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="62dp" 
     android:text="TextView" /> 

    <Button 
     android:id="@+id/button1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignLeft="@+id/textView1" 
     android:layout_below="@+id/textView1" 
     android:layout_marginTop="69dp" 
     android:background="#000000" 
     android:onClick="sendLocation" 
     android:text="Refresh Location" 
     android:textColor="#ffffff" /> 

</RelativeLayout> 

清单:

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.example.abc" 
    android:versionCode="1" 
    android:versionName="1.0" > 

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


    <uses-feature 
     android:glEsVersion="0x00020000" 
     android:required="true" /> 

    <uses-permission android:name="com.example.abc.permission.MAPS_RECEIVE" /> 
    <uses-permission android:name="android.permission.INTERNET" /> 
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> 
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 
    <uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" /> 
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" /> 

    <permission 
     android:name="com.example.abc.permission.MAPS_RECEIVE" 
     android:protectionLevel="signature" /> 

    <application 
     android:allowBackup="true" 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme" > 


      <meta-data 
       android:name="com.google.android.maps.v2.API_KEY" 
       android:value="map_api_key" /> 
      <meta-data 
       android:name="com.google.android.gms.version" 
       android:value="@integer/google_play_services_version" /> 

     <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=".MapActivity" 
      android:label="@string/title_activity_map" > 
     </activity> 
     <activity 
      android:name=".MappingActivity" 
      android:label="@string/title_activity_mapping" > 
     </activity> 
    </application> 

</manifest> 

MappingActivity:

public class MappingActivity extends FragmentActivity { 
    private GoogleMap googleHarita; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.map); 
     //String longitude = getIntent().getExtras().getString("longitude"); 
     //Float f = Float.parseFloat(longitude); 

     if (googleHarita == null) { 
      googleHarita = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.haritafragment)) 
        .getMap(); 
      if (googleHarita != null) { 

       LatLng istanbulKoordinat = new LatLng(0,29.004065); 
       googleHarita.addMarker(new MarkerOptions().position(istanbulKoordinat).title("Kız Kulesi")); 
       googleHarita.moveCamera(CameraUpdateFactory.newLatLngZoom(istanbulKoordinat, 13));  


     } 
    } 
} 

}

map.xml:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <fragment 
     android:id="@+id/haritafragment" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     class="com.google.android.gms.maps.SupportMapFragment" /> 

</RelativeLayout> 

Web服务:

public String insertData(String longitude,String latitude,String time){ 

      try{ 

       Class.forName("com.mysql.jdbc.Driver"); 
       Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost/places","root",""); 
       PreparedStatement statement = (PreparedStatement) con.prepareStatement("insert into location (COLUMN_LONGITUDE,COLUMN_LATITUDE,COLUMN_TIME) values ('"+longitude+"','"+latitude+"','"+time+"')"); 


       int result=statement.executeUpdate(); 
       con.close(); 
      }catch(Exception exc){ 

       System.out.println(exc); 

      } 


      return time; 

     } 


    public String locationData(){ 

     String locationInfo=""; 

      try{ 

       Class.forName("com.mysql.jdbc.Driver"); 
       Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost/places","root",""); 
       PreparedStatement statement = (PreparedStatement) con.prepareStatement("select * from location"); 

       ResultSet result=statement.executeQuery(); 

       while(result.next()){ 

        locationInfo=locationInfo+result.getString("COLUMN_LONGITUDE")+"&" +result.getString("COLUMN_LATITUDE")+ "&" +result.getString("COLUMN_TIME"); 

       } 


      }catch(Exception exc){ 

       System.out.println(exc); 

      } 
      return locationInfo; 

     } 

的logcat:

errors in logcat

+0

你必须在你的'Manifest文件'中声明'MappingActivity.class' – diogojme

+0

是的,我宣布了。我正在共享清单文件。 – Busra

+0

分享您的MappingActivity.class – diogojme

回答

0

你在你的MappingActivity扩展FragmentActivity而不是ActivityAppCompatActivity取代它,将工作。

+0

我声明了MappingActivity。但问题没有解决。 – Busra

+0

@Busra我编辑我的回复,请检查它 – diogojme

+0

我试过了,但问题没有解决。 – Busra