C
ChrisHell
Neues Mitglied
- 0
hey Leute,
ich habe heute angefangen Apps für Android zu programmieren bzw erst einmal ein wenig rumprobiert.
Mein eigentliches Problem ist nun das ich gerne eine app schreiben würde die mir eine Website anzeigt, also eigentlich nichts kompliziertes.
Nun stürzt jedoch die App sofort ab wenn ich sie starte und ich kann mir nicht erklären warum
Ich hab das WebView-Element hinzufügt und auch die ID entsprechend abgeändert.
Design XML-Code:
Mein Hauptcode sieht folgendermaßen aus:
Zum schluss meine Manifest Datei:
Der Debugger gibt folgendes in Rot aus:
Als IDE benutze ich Android Studio, die App stürzt sowohl bei einem Nexus S Emulator als auch auf meinem Galaxy S1 mit Cyanogenmod (Android 4.2.2) ab :/
Schonmal Danke im Voraus
Der ursprüngliche Beitrag von 19:32 Uhr wurde um 19:59 Uhr ergänzt:
Hat sich erledigt, ich musste
setContentView(R.layout.fragment_main);
anstatt
setContentView(R.layout.activity_main);
schreiben
ich habe heute angefangen Apps für Android zu programmieren bzw erst einmal ein wenig rumprobiert.
Mein eigentliches Problem ist nun das ich gerne eine app schreiben würde die mir eine Website anzeigt, also eigentlich nichts kompliziertes.
Nun stürzt jedoch die App sofort ab wenn ich sie starte und ich kann mir nicht erklären warum

Ich hab das WebView-Element hinzufügt und auch die ID entsprechend abgeändert.
Design XML-Code:
Code:
<?xml version="1.0" encoding="utf-8"?>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/wv1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
Mein Hauptcode sieht folgendermaßen aus:
Code:
package com.chpdsbpro.app;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.os.Build;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends ActionBarActivity {
WebView mWebView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mWebView = (WebView) findViewById(R.id.wv1);
mWebView.setWebViewClient(new WebViewClient());
mWebView.loadUrl("http://google.de/");
}
@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);
}
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
return rootView;
}
}
}
Zum schluss meine Manifest Datei:
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.chpdsbpro.app" >
<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.chpdsbpro.app.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>
</application>
</manifest>
Der Debugger gibt folgendes in Rot aus:
Code:
03-25 14:24:03.000 1310-1310/com.chpdsbpro.app E/AndroidRuntime FATAL EXCEPTION: main
Process: com.chpdsbpro.app, PID: 1310
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.chpdsbpro.app/com.chpdsbpro.app.MainActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.chpdsbpro.app.MainActivity.onCreate(MainActivity.java:27)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
************at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
************at android.app.ActivityThread.access$800(ActivityThread.java:135)
************at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
************at android.os.Handler.dispatchMessage(Handler.java:102)
************at android.os.Looper.loop(Looper.java:136)
************at android.app.ActivityThread.main(ActivityThread.java:5017)
************at java.lang.reflect.Method.invokeNative(Native Method)
************at java.lang.reflect.Method.invoke(Method.java:515)
************at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
************at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
************at dalvik.system.NativeStart.main(Native Method)
Als IDE benutze ich Android Studio, die App stürzt sowohl bei einem Nexus S Emulator als auch auf meinem Galaxy S1 mit Cyanogenmod (Android 4.2.2) ab :/
Schonmal Danke im Voraus
Der ursprüngliche Beitrag von 19:32 Uhr wurde um 19:59 Uhr ergänzt:
Hat sich erledigt, ich musste
setContentView(R.layout.fragment_main);
anstatt
setContentView(R.layout.activity_main);
schreiben