Android应用程序开发 - 应用程序在启动第二个活动后崩溃

时间:2014-03-09 03:31:25

标签: java android android-intent android-webview

我是Android开发的新手,现在已经停留了几天。虽然很多人都得到了相同的错误答案提交似乎并没有帮助我。我有一个启动画面5秒钟,然后启动我的第二个活动,这只是一个webview。 (旁注:如果我不使用互联网权限,第二个活动启动没有问题,但我确实得到一个网页不可用的屏幕,当我包含权限时,应用程序崩溃后闪屏)这是我的代码;

MainActivity:

public class MainActivity extends Activity {

Thread newTimer;


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

    newTimer = new Thread() {
        public void run(){
            try{
                sleep(3000);
                }

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

            finally
            {
                Intent nw = new Intent(MainActivity.this, SecondActivity.class);
                startActivity(nw);
                }
            }
        };  
    newTimer.start();
   }
}

SecondActivity:

public class SecondActivity extends Activity {

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.secondlayout);

    String url = "http://ythaber.com/";
    WebView myWebWiew = (WebView) this.findViewById(R.id.webView1);

    myWebWiew.setWebViewClient(new WebViewClient());

    myWebWiew.getSettings().setJavaScriptEnabled(true);
    myWebWiew.loadUrl(url);

}

AndroidManifest:

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

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

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" >
    <activity
        android:name="com.idpturkey.ythaber2.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="SecondActivity" >
    </activity>
</application>
</manifest>

logcat的:

E/AndroidRuntime(17034): FATAL EXCEPTION: main
Process: com.idpturkey.ythaber2, PID: 18216
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.idpturkey.ythaber2/com.idpturkey.ythaber2.SecondActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class uses-permission
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2596)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2653)
at android.app.ActivityThread.access$800(ActivityThread.java:156)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1355)

secondlayout.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"
android:orientation="vertical" >

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

<WebView
    android:id="@+id/webView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

</RelativeLayout>

提前致谢, Devrim

1 个答案:

答案 0 :(得分:1)

secondlayout.xml

中删除此行
<uses-permission
    android:name="android.permission.INTERNET" >
</uses-permission>

将其放入项目中的ManifestFile.xml

您的所有权限应写在Manifest.xml而不是your_layout.xml

希望它会对你有所帮助。