F
Fred12
Gast
hi,
hab ein Problem und zwar steht da wenn ich meine App aufm Handy starten will: "Leider wurde (App..) beendet"
obwohl debugging usw. in Android Studio problemlos verlief..woran liegt das? hier ein kleiner Log:
hier meine MainActivity.xml:
und meine activitymain.xml:
bin etwas ratlos...
ist das vllt relevant:
10-27 13:38:32.394 215-574/? I/ActivityManager No longer want com.android.packageinstaller (pid 20219): hidden #16
10-27 13:38:32.418 20376-20376/com.example.test D/AndroidRuntime Shutting down VM
10-27 13:38:32.418 20376-20376/com.example.test W/dalvikvm threadid=1: thread exiting with uncaught exception (group=0x40a5c1f8)
10-27 13:38:32.425 19694-19696/? E/dalvikvm GC_CONCURRENT freed 1446K, 19% free 9377K/11491K, paused 6ms+2ms
10-27 13:38:32.425 20376-20376/com.example.test E/AndroidRuntime FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.test/com.example.test.MainActivity}: java.lang.NullPointerException
215-237/? W/ActivityManager Activity destroy timeout for ActivityRecord{41405800 com.example.test/.MainActivity}
hab ein Problem und zwar steht da wenn ich meine App aufm Handy starten will: "Leider wurde (App..) beendet"
obwohl debugging usw. in Android Studio problemlos verlief..woran liegt das? hier ein kleiner Log:
Code:
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at android.app.Activity.findViewById(Activity.java:1794)
at com.example.test.MainActivity.<init>(MainActivity.java:19)
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1319)
at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1871)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
at android.app.ActivityThread.access$600(ActivityThread.java:123)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
at dalvik.system.NativeStart.main(Native Method)
10-27 13:24:21.183 215-23066/? W/ActivityManager Force finishing activity com.example.test/.MainActivity
10-27 13:24:21.214 215-23066/? E/ActivityManager exception bw.write()java.io.IOException: Transport endpoint is not connected
10-27 13:24:21.621 907-927/? I/System.out pauseFxCore end
10-27 13:24:21.629 907-907/? D/OpenGLRenderer Flushing caches (mode 0)
10-27 13:24:21.722 215-22972/? D/Sensors sensors_poll_context_t->activate(handle: 0, enabled: 0)
10-27 13:24:21.722 215-22972/? D/Sensors virtual int AccelerometerSensor::enable(int32_t, int): fd (341 ),en (0),flags(0), mEnabled(1),input_sys_path (/sys/class/input/event5/device/device/enable)
10-27 13:24:21.722 215-237/? W/ActivityManager Activity pause timeout for ActivityRecord{42252d10 com.example.test/.MainActivity}
10-27 13:24:21.730 907-927/? I/System.out resetSurface start
10-27 13:24:21.730 907-927/? I/System.out resetSurface end
10-27 13:24:21.738 907-927/? I/System.out resumeFxCore start
10-27 13:24:21.879 907-927/? I/System.out resumeFxCore end
10-27 13:24:21.879 907-907/? D/Launcher3d LauncherNxChannel.send() msgKey=EGL_CONTEXT_RECREATED msgArgs=null extra=null
10-27 13:24:21.879 907-907/? D/Launcher3d LauncherNxChannel.send() msgKey=FXCORE_ON_RESUME msgArgs=null extra=null
10-27 13:24:21.933 907-907/? I/fitatc preference set, no need change
10-27 13:24:21.933 907-907/? D/Launcher3d LauncherNxChannel.send() msgKey=ACTIVITY_RESUMED msgArgs=null extra=NxDataSet(100/NxObject({config:NxObject({longPressTime:500})}))
10-27 13:24:21.933 907-926/? D/FSCommand [fxcoreOnResumeHandler] _mode=1
10-27 13:24:21.933 907-926/? D/FSCommand [DesktopDock.enable]
10-27 13:24:21.941 907-926/? D/FSCommand [xxx enable len = 4]
10-27 13:24:21.996 907-926/? D/FSCommand [activityResumedHandler] longPressTime = 500,_nodeItemEventChecker = [object Object],desktop.dock = [object Object]
10-27 13:24:22.363 215-288/? E/SystemStatTool Switch consumed time = 1145 ms
Code:
package com.example.test;
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.KeyEvent;
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.widget.EditText;
public class MainActivity extends ActionBarActivity {
EditText display = (EditText) findViewById(R.id.displayField);
StringBuffer s = new StringBuffer("");
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) getSupportFragmentManager().beginTransaction()
//.add(R.id.container, new PlaceholderFragment())
.commit();
}
@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.
switch (item.getItemId()) {
case 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;
}
}
public void backspaceAction(View view) throws NullPointerException{
//display.setText(display.getText().delete(display.length() - 1, display.length()));
display.getText().toString().substring(0, display.getText().toString().length()-1);
}
public void oneAction(View view) {
display.setText(s.append(1));
}
public void twoAction(View view) {
display.setText(s.append(2));
}
public void onClick(View view) {
switch(view.getId()){
case R.id.btn3:
display.setText(s.append(3));
break;
case R.id.btn4:
display.setText(s.append(4));
break;
case R.id.btn5:
display.setText(s.append(5));
break;
case R.id.btn6:
display.setText(s.append(6));
break;
case R.id.btn7:
display.setText(s.append(7));
break;
case R.id.btn8:
display.setText(s.append(8));
break;
case R.id.btn9:
display.setText(s.append(9));
break;
case R.id.btn0:
display.setText(s.append(0));
break;
}
}
}
Code:
<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=".MainActivity" >
<EditText
android:drawableLeft="@drawable/ic_launcher"
android:id="@+id/displayField"
android:layout_width="fill_parent"
android:layout_height="80dp"
android:textSize="60sp"
android:inputType="number"
android:textColor="@android:color/white"
android:editable="false"
android:background="@android:color/black" />
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_below="@id/displayField">
<Button
android:id="@+id/emptyButton"
android:layout_weight="2"
android:enabled="false"
android:layout_height="60dp"
android:layout_width="wrap_content" />
<ImageButton
android:id="@+id/backspace"
android:layout_height="60dp"
android:layout_width="wrap_content"
android:layout_weight="0.37"
android:src="@drawable/backspace" />
</LinearLayout>
<TableLayout
android:stretchColumns="*"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_margin="0dp"
android:onClick="backspaceAction"
android:layout_below="@id/linearLayout1">
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="2"
>
<ImageButton
android:onClick="onClick"
android:id="@+id/btn7"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/seven"
/>
<ImageButton
android:onClick="onClick"
android:id="@+id/btn8"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="@string/btn2"
android:src="@drawable/eight"
/>
<ImageButton
android:onClick="onClick"
android:id="@+id/btn9"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/nine"
/>
<ImageButton
android:id="@+id/btnDivide"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/division"
/>
</TableRow>
<TableRow
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:layout_weight="2">
<ImageButton
android:onClick="onClick"
android:id="@+id/btn4"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/four"
/>
<ImageButton
android:onClick="onClick"
android:id="@+id/btn5"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/five"
/>
<ImageButton
android:onClick="onClick"
android:id="@+id/btn6"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/six"
/>
<ImageButton
android:id="@+id/btnMultiply"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/multiply"
/>
</TableRow>
<TableRow
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:layout_weight="2">
<ImageButton
android:id="@+id/btn1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:onClick="oneAction"
android:src="@drawable/one"
/>
<ImageButton
android:id="@+id/btn2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/two"
android:onClick="twoAction"
/>
<ImageButton
android:id="@+id/btn3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:onClick="onClick"
android:src="@drawable/three"
/>
<ImageButton
android:id="@+id/btnMinus"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/minus"
/>
</TableRow>
<TableRow
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:layout_weight="2">
<ImageButton
android:id="@+id/btnComma"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="@string/btn2"
android:src="@drawable/comma2"
/>
<ImageButton
android:onClick="onClick"
android:id="@+id/btn0"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/zero"
/>
<ImageButton
android:id="@+id/btnEqual"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/white"
android:src="@drawable/equals"
/>
<ImageButton
android:onClick="plusAction"
android:id="@+id/btnPlus"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/plus"
/>
</TableRow>
</TableLayout>
</RelativeLayout>
ist das vllt relevant:
10-27 13:38:32.394 215-574/? I/ActivityManager No longer want com.android.packageinstaller (pid 20219): hidden #16
10-27 13:38:32.418 20376-20376/com.example.test D/AndroidRuntime Shutting down VM
10-27 13:38:32.418 20376-20376/com.example.test W/dalvikvm threadid=1: thread exiting with uncaught exception (group=0x40a5c1f8)
10-27 13:38:32.425 19694-19696/? E/dalvikvm GC_CONCURRENT freed 1446K, 19% free 9377K/11491K, paused 6ms+2ms
10-27 13:38:32.425 20376-20376/com.example.test E/AndroidRuntime FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.test/com.example.test.MainActivity}: java.lang.NullPointerException
215-237/? W/ActivityManager Activity destroy timeout for ActivityRecord{41405800 com.example.test/.MainActivity}
Zuletzt bearbeitet: