简体   繁体   中英

How to fix android-eclipse HelloWorld application?

I have a problem I am not sure how to ask about. So please give me guidance, as I am a beginner with developing android apps (which is by far the most complicated, cumbersome and confusing thing to do!).

I have created a new "Hello World" project, had to do some other setup stuff (or whatever, not exactly sure what I did), and 'run' my first android application with an enumator. The emulator start, and the app "Hello World" stops immedeately with the message:

The application HelloWorld (process ...) has stopped unexpectedly. Please try again. 

In my eclipse window I see the following three warnings, but I am not sure if it is related to the actual problem above:

Could not locate '/home/alexander/opt/src/android-sdk-linux/extras/android/support/v7/appcompat/bin/android-support-v7-appcompat.jar'. This will not be added to the package.
The type ActionBarActivity is deprecated    MainActivity.java   /HelloWorld/src/com/example/helloworld  line 3  Java Problem
The type ActionBarActivity is deprecated    MainActivity.java   /HelloWorld/src/com/example/helloworld  line 10 Java Problem

Here is the content of MainActivity.java:

package com.example.helloworld;

import android.support.v7.app.ActionBarActivity;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;


@SuppressLint("NewApi") public class MainActivity extends ActionBarActivity {

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

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

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}

How can I fix this problem? How can I even start figuring out what is wrong? Is there any other way to simpler create android applications? Or must it be really complicated, cumbersome and confusing...?

It seems that you don't have the right SDK version. So it can't load ActionBarActivity .

Also ActionBarActivity is depricated so you might want to use AppCompatActivity .

Reference: https://developer.android.com/reference/android/support/v7/app/ActionBarActivity.html

I also recommend to switch to Android Studio because it's easier to manage the SDK.

try this

    Add android-support-v7-appcompat.jar to your Buildpath
    Right click on your Project --> Properties --> Java Build Path --> Libraries tab --> Add External JAR --> Browse --> add android-support-v7-appcompat.jar --> ok --> Apply --> ok

    Clean and build your project and run.

Hopefully this will work...

Replace your MainActivity.java with the below code

package com.example.helloworld;

    import android.app.Activity;
    import android.os.Bundle;
    import android.view.Menu;
    import android.view.MenuItem;

public class MainActivity extends Activity {

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

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM