Android不幸的是项目已停止错误

时间:2016-06-14 19:23:13

标签: android eclipse-adt

我正在Eclipse ADT Bundle中创建Android应用程序。当点击按钮应用程序连接Web服务并获取app.I中的位置值时我在模拟器中启动应用程序,而我收到“不幸的是项目名称已停止”警告。我正在检查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>

网络服务:

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

1 个答案:

答案 0 :(得分:0)

您正在使用MappingActivity扩展FragmentActivity而不是ActivityAppCompatActivity替换它,并且可以正常工作。

相关问题